Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature 11/240408회의 api 개발 및 엔티티 수정 #13

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
## #️⃣연관된 이슈

> ex) #이슈번호, #이슈번호

## 📝작업 내용

> 이번 PR에서 작업한 내용을 간략히 설명해주세요(이미지 첨부 가능)

### 스크린샷 (선택)

## 💬리뷰 요구사항(선택)

> 리뷰어가 특별히 봐주었으면 하는 부분이 있다면 작성해주세요
>
> ex) 메서드 XXX의 이름을 더 잘 짓고 싶은데 혹시 좋은 명칭이 있을까요?
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
package com.modernfarmer.farmusspring.domain.myveggiegarden.controller;

import com.modernfarmer.farmusspring.domain.myveggiegarden.dto.response.CheckTodayDiaryResponse;
import com.modernfarmer.farmusspring.domain.myveggiegarden.dto.response.SelectDiaryOneResponse;
import com.modernfarmer.farmusspring.domain.myveggiegarden.dto.response.SelectMyVeggieListResponse;
import com.modernfarmer.farmusspring.domain.myveggiegarden.dto.response.*;
import com.modernfarmer.farmusspring.domain.myveggiegarden.entity.MyVeggie;
import com.modernfarmer.farmusspring.domain.myveggiegarden.service.MyVeggieDiaryService;
import com.modernfarmer.farmusspring.domain.myveggiegarden.service.MyVeggieGardenService;
import com.modernfarmer.farmusspring.global.response.BaseResponseDto;
import com.modernfarmer.farmusspring.global.response.SuccessCode;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.List;

@Slf4j
@RequiredArgsConstructor
Expand Down Expand Up @@ -54,5 +54,23 @@ public BaseResponseDto<SelectDiaryOneResponse> selectDiaryOne(
return myVeggieDiaryService.selectDiaryOne(MyVeggie.builder().id(myVeggieId).build());
}

@GetMapping(value = "/{myVeggieId}/count")
public BaseResponseDto<MyVeggieDiaryCount> selectDiaryCount(
@PathVariable("myVeggieId") Long myVeggieId
) {
MyVeggie myVeggie = MyVeggie.builder().id(myVeggieId).build();
MyVeggieDiaryCount result = myVeggieDiaryService.selectDiaryCount(myVeggie);

return BaseResponseDto.of(SuccessCode.SUCCESS, result);
}

@GetMapping(value = "/{myVeggieId}/all")
public BaseResponseDto<MyVeggieDiaryCount> selectDiaryAll(
@PathVariable("myVeggieId") Long myVeggieId
) {
MyVeggie myVeggie = MyVeggie.builder().id(myVeggieId).build();
List<AllDairy> result = myVeggieDiaryService.selectDiaryAll(myVeggie);

return BaseResponseDto.of(SuccessCode.SUCCESS, result);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,23 @@

import com.modernfarmer.farmusspring.domain.auth.entity.CustomUser;

import com.modernfarmer.farmusspring.domain.myveggiegarden.dto.request.DeleteMyVeggieRequest;
import com.modernfarmer.farmusspring.domain.myveggiegarden.dto.request.MyVeggieUpdate;
import com.modernfarmer.farmusspring.domain.myveggiegarden.dto.request.SettingMyVeggieRequest;
import com.modernfarmer.farmusspring.domain.myveggiegarden.dto.response.MyDetailMyVeggie;
import com.modernfarmer.farmusspring.domain.myveggiegarden.dto.response.SelectMyVeggieListResponse;
import com.modernfarmer.farmusspring.domain.myveggiegarden.dto.response.SelectMyVeggieProfileResponse;
import com.modernfarmer.farmusspring.domain.myveggiegarden.service.MyVeggieGardenService;
import com.modernfarmer.farmusspring.global.response.BaseResponseDto;
import com.modernfarmer.farmusspring.global.response.SuccessCode;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@Slf4j
@RequiredArgsConstructor
Expand All @@ -20,7 +28,7 @@ public class MyVeggieGardenController {

private final MyVeggieGardenService myVeggieGardenService;

@PostMapping(value = "/")
@PostMapping(value = "")
public BaseResponseDto<Void> settingMyVeggie(
@AuthenticationPrincipal CustomUser user,
@Validated @RequestBody SettingMyVeggieRequest settingMyVeggi
Expand All @@ -31,13 +39,43 @@ public BaseResponseDto<Void> settingMyVeggie(
);
}

@GetMapping(value = "/list")
public BaseResponseDto<List<MyDetailMyVeggie>> selectDetailMyVeggieList(
@AuthenticationPrincipal CustomUser user
){
return myVeggieGardenService.selectDetailMyVeggieList(user.getUserId());
}


@DeleteMapping(value = "")
public BaseResponseDto<Void> deleteMyVeggie(
@Validated @RequestBody DeleteMyVeggieRequest deleteMyVeggieRequest
){
return myVeggieGardenService.deleteMyVeggie(deleteMyVeggieRequest);
}


@GetMapping(value = "/simple-list")
public BaseResponseDto<Void> selectMyVeggieList(
public BaseResponseDto<List<SelectMyVeggieListResponse>> selectMyVeggieList(
@AuthenticationPrincipal CustomUser user
){
return myVeggieGardenService.selectMyVeggieList(user.getUserId());
}

@GetMapping(value = "/{myVeggieId}/profile")
public BaseResponseDto<SelectMyVeggieProfileResponse> selectMyVeggieProfile(
@PathVariable("myVeggieId") Long myVeggieId
){
return myVeggieGardenService.selectMyVeggieProfile(myVeggieId);
}

@PutMapping(value = "")
public BaseResponseDto<?> updateMyVeggie(
@Validated @RequestBody MyVeggieUpdate myVeggieUpdate){

myVeggieGardenService.myVeggieUpdate(myVeggieUpdate);
return BaseResponseDto.of(SuccessCode.SUCCESS, null);
}



Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
package com.modernfarmer.farmusspring.domain.myveggiegarden.controller;

import com.modernfarmer.farmusspring.domain.auth.entity.CustomUser;
import com.modernfarmer.farmusspring.domain.myveggiegarden.dto.request.SettingMyVeggieRoutineReqeuest;
import com.modernfarmer.farmusspring.domain.myveggiegarden.dto.response.MyRoutineList;
import com.modernfarmer.farmusspring.domain.myveggiegarden.dto.response.MyVeggieRoutine;
import com.modernfarmer.farmusspring.domain.myveggiegarden.entity.MyVeggie;
import com.modernfarmer.farmusspring.domain.myveggiegarden.entity.Routine;
import com.modernfarmer.farmusspring.domain.myveggiegarden.service.MyVeggieRoutineService;
import com.modernfarmer.farmusspring.global.response.BaseResponseDto;
import com.modernfarmer.farmusspring.global.response.SuccessCode;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@Slf4j
@RequiredArgsConstructor
Expand All @@ -25,4 +34,24 @@ public BaseResponseDto<Void> settingMyVeggieRoutine(
return myVeggieRoutineService.settingMyVeggieRoutine(settingMyVeggieRoutineReqeuest);

}

@GetMapping(value = "/{myVeggieId}")
public BaseResponseDto<?> selectMyVeggieRoutineById(
@PathVariable("myVeggieId") Long myVeggieId
) {
MyVeggie myVeggie = MyVeggie.builder().id(myVeggieId).build();
List<MyVeggieRoutine> result = myVeggieRoutineService.selectMyVeggieRoutineById(myVeggie);

return BaseResponseDto.of(SuccessCode.SUCCESS, result);
}

@GetMapping(value = "/list")
public BaseResponseDto<?> selectMyVeggieRoutine(
@AuthenticationPrincipal CustomUser user
) {

List<MyRoutineList> result = myVeggieRoutineService.selectMyVeggieRoutine(user.getUserId());

return BaseResponseDto.of(SuccessCode.SUCCESS, result);
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.modernfarmer.farmusspring.domain.myveggiegarden.dto.request;

import jakarta.validation.constraints.NotNull;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@AllArgsConstructor
@NoArgsConstructor
public class DeleteMyVeggieRequest {

@NotNull(message = "null 값을 가지면 안됩니다.")
private Long myVeggieId;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.modernfarmer.farmusspring.domain.myveggiegarden.dto.request;

import jakarta.validation.constraints.NotNull;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.springframework.format.annotation.DateTimeFormat;

import java.time.LocalDate;
import java.util.Date;


@Getter
@AllArgsConstructor
@NoArgsConstructor
public class MyVeggieUpdate {

@NotNull(message = "null 값을 가지면 안됩니다.")
private Long myVeggieId;


@NotNull(message = "null 값을 가지면 안됩니다.")
private String nickname;

@NotNull(message = "null 값을 가지면 안됩니다.")
private Date birth;

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,10 @@ public class SettingMyVeggieRequest {

@NotNull(message = "null 값을 가지면 안됩니다.")
private Long veggiInfoId;

@NotNull(message = "null 값을 가지면 안됩니다.")
private String veggieName;

@NotNull(message = "null 값을 가지면 안됩니다.")
private String veggieImage;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.modernfarmer.farmusspring.domain.myveggiegarden.dto.response;

import com.modernfarmer.farmusspring.domain.myveggiegarden.entity.Diary;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import java.util.List;

import static com.modernfarmer.farmusspring.domain.myveggiegarden.util.DateManager.formatDate;

@AllArgsConstructor
@NoArgsConstructor
@Getter
public class AllDairy {

private String date;
private String image;
private String content;
private Boolean isOpen;

public static AllDairy of(Diary diary, String date){
return new AllDairy(
date,
diary.getImage(),
diary.getContent(),
diary.getIsOpen()
);
}

public static List<AllDairy> processData(List<Diary> diaryList){
return diaryList.stream()
.map(diary -> AllDairy.of(diary, formatDate(diary.getCreatedDate())))
.toList();
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.modernfarmer.farmusspring.domain.myveggiegarden.dto.response;


import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;


@NoArgsConstructor
@AllArgsConstructor(staticName = "of")
@Getter
public class MyDetailMyVeggie {

String nickname;
String image;
String veggieName;
String birthDay;
int period;
Long myVeggieId;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.modernfarmer.farmusspring.domain.myveggiegarden.dto.response;

import com.modernfarmer.farmusspring.domain.myveggiegarden.entity.MyVeggie;
import com.modernfarmer.farmusspring.domain.myveggiegarden.util.DateManager;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

import java.util.Date;
import java.util.List;


@AllArgsConstructor
@Getter
@Component
public class MyDetailMyVeggieDto {


private final DateManager dateManager;

public List<MyDetailMyVeggie> processData(List<MyVeggie> myVeggieList){

return myVeggieList.stream()
.map(myVeggie -> MyDetailMyVeggie.of(
myVeggie.getNickname(),
myVeggie.getVeggieImage(),
myVeggie.getVeggieName(),
dateManager.parsingDotDate(myVeggie.getBirth()),
dateManager.calculateDay(myVeggie.getBirth(), new Date()),
myVeggie.getId()

)).toList();
}

}
Loading
Loading