diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md new file mode 100644 index 00000000..c74c7aa7 --- /dev/null +++ b/.github/pull_request_template.md @@ -0,0 +1,15 @@ +## #️⃣연관된 이슈 + +> ex) #이슈번호, #이슈번호 + +## 📝작업 내용 + +> 이번 PR에서 작업한 내용을 간략히 설명해주세요(이미지 첨부 가능) + +### 스크린샷 (선택) + +## 💬리뷰 요구사항(선택) + +> 리뷰어가 특별히 봐주었으면 하는 부분이 있다면 작성해주세요 +> +> ex) 메서드 XXX의 이름을 더 잘 짓고 싶은데 혹시 좋은 명칭이 있을까요? \ No newline at end of file diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/controller/MyVeggieDiaryController.java b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/controller/MyVeggieDiaryController.java index 73bcb02b..5941d617 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/controller/MyVeggieDiaryController.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/controller/MyVeggieDiaryController.java @@ -1,12 +1,11 @@ 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; @@ -14,6 +13,7 @@ import org.springframework.web.multipart.MultipartFile; import java.io.IOException; +import java.util.List; @Slf4j @RequiredArgsConstructor @@ -54,5 +54,23 @@ public BaseResponseDto selectDiaryOne( return myVeggieDiaryService.selectDiaryOne(MyVeggie.builder().id(myVeggieId).build()); } + @GetMapping(value = "/{myVeggieId}/count") + public BaseResponseDto 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 selectDiaryAll( + @PathVariable("myVeggieId") Long myVeggieId + ) { + MyVeggie myVeggie = MyVeggie.builder().id(myVeggieId).build(); + List result = myVeggieDiaryService.selectDiaryAll(myVeggie); + + return BaseResponseDto.of(SuccessCode.SUCCESS, result); + } } diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/controller/MyVeggieGardenController.java b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/controller/MyVeggieGardenController.java index e5660dd5..67e334da 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/controller/MyVeggieGardenController.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/controller/MyVeggieGardenController.java @@ -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 @@ -20,7 +28,7 @@ public class MyVeggieGardenController { private final MyVeggieGardenService myVeggieGardenService; - @PostMapping(value = "/") + @PostMapping(value = "") public BaseResponseDto settingMyVeggie( @AuthenticationPrincipal CustomUser user, @Validated @RequestBody SettingMyVeggieRequest settingMyVeggi @@ -31,13 +39,43 @@ public BaseResponseDto settingMyVeggie( ); } + @GetMapping(value = "/list") + public BaseResponseDto> selectDetailMyVeggieList( + @AuthenticationPrincipal CustomUser user + ){ + return myVeggieGardenService.selectDetailMyVeggieList(user.getUserId()); + } + + + @DeleteMapping(value = "") + public BaseResponseDto deleteMyVeggie( + @Validated @RequestBody DeleteMyVeggieRequest deleteMyVeggieRequest + ){ + return myVeggieGardenService.deleteMyVeggie(deleteMyVeggieRequest); + } + + @GetMapping(value = "/simple-list") - public BaseResponseDto selectMyVeggieList( + public BaseResponseDto> selectMyVeggieList( @AuthenticationPrincipal CustomUser user ){ return myVeggieGardenService.selectMyVeggieList(user.getUserId()); } + @GetMapping(value = "/{myVeggieId}/profile") + public BaseResponseDto 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); + } diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/controller/MyVeggieRoutineController.java b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/controller/MyVeggieRoutineController.java index 998b65bf..5822e24a 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/controller/MyVeggieRoutineController.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/controller/MyVeggieRoutineController.java @@ -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 @@ -25,4 +34,24 @@ public BaseResponseDto settingMyVeggieRoutine( return myVeggieRoutineService.settingMyVeggieRoutine(settingMyVeggieRoutineReqeuest); } + + @GetMapping(value = "/{myVeggieId}") + public BaseResponseDto selectMyVeggieRoutineById( + @PathVariable("myVeggieId") Long myVeggieId + ) { + MyVeggie myVeggie = MyVeggie.builder().id(myVeggieId).build(); + List result = myVeggieRoutineService.selectMyVeggieRoutineById(myVeggie); + + return BaseResponseDto.of(SuccessCode.SUCCESS, result); + } + + @GetMapping(value = "/list") + public BaseResponseDto selectMyVeggieRoutine( + @AuthenticationPrincipal CustomUser user + ) { + + List result = myVeggieRoutineService.selectMyVeggieRoutine(user.getUserId()); + + return BaseResponseDto.of(SuccessCode.SUCCESS, result); + } } diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/dto/TestDto.java b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/dto/TestDto.java deleted file mode 100644 index 94f24356..00000000 --- a/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/dto/TestDto.java +++ /dev/null @@ -1,4 +0,0 @@ -package com.modernfarmer.farmusspring.domain.myveggiegarden.dto; - -public class TestDto { -} diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/dto/request/DeleteMyVeggieRequest.java b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/dto/request/DeleteMyVeggieRequest.java new file mode 100644 index 00000000..e67745d6 --- /dev/null +++ b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/dto/request/DeleteMyVeggieRequest.java @@ -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; + +} diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/dto/request/MyVeggieUpdate.java b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/dto/request/MyVeggieUpdate.java new file mode 100644 index 00000000..5d37774d --- /dev/null +++ b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/dto/request/MyVeggieUpdate.java @@ -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; + +} diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/dto/request/SettingMyVeggieRequest.java b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/dto/request/SettingMyVeggieRequest.java index 0d5b042d..2b6f5fc5 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/dto/request/SettingMyVeggieRequest.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/dto/request/SettingMyVeggieRequest.java @@ -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; } diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/dto/response/AllDairy.java b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/dto/response/AllDairy.java new file mode 100644 index 00000000..9e20eaa3 --- /dev/null +++ b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/dto/response/AllDairy.java @@ -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 processData(List diaryList){ + return diaryList.stream() + .map(diary -> AllDairy.of(diary, formatDate(diary.getCreatedDate()))) + .toList(); + } + + +} diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/dto/response/MyDetailMyVeggie.java b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/dto/response/MyDetailMyVeggie.java new file mode 100644 index 00000000..6212c7a0 --- /dev/null +++ b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/dto/response/MyDetailMyVeggie.java @@ -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; + +} diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/dto/response/MyDetailMyVeggieDto.java b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/dto/response/MyDetailMyVeggieDto.java new file mode 100644 index 00000000..c11ed6bf --- /dev/null +++ b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/dto/response/MyDetailMyVeggieDto.java @@ -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 processData(List 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(); + } + +} diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/dto/response/MyRoutineList.java b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/dto/response/MyRoutineList.java new file mode 100644 index 00000000..174cebf3 --- /dev/null +++ b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/dto/response/MyRoutineList.java @@ -0,0 +1,53 @@ +package com.modernfarmer.farmusspring.domain.myveggiegarden.dto.response; + +import com.modernfarmer.farmusspring.domain.myveggiegarden.entity.MyVeggie; +import com.modernfarmer.farmusspring.domain.myveggiegarden.entity.Routine; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; + +import java.util.ArrayList; +import java.util.List; + +@AllArgsConstructor +@NoArgsConstructor +@Getter +public class MyRoutineList { + + private String nickname; + private String veggieName; + private List myVeggieRoutineList; + + + public static MyRoutineList of(MyVeggie myVeggie, List myVeggieRoutineList){ + return new MyRoutineList( + myVeggie.getNickname(), + myVeggie.getVeggieName(), + myVeggieRoutineList + ); + } + + + public static List processData(List myVeggieList){ + return myVeggieList.stream() + .map(myVeggie -> { + + return MyRoutineList.of(myVeggie,checkRoutine(myVeggie)); + }) + .toList(); + } + + private static List checkRoutine(MyVeggie myVeggie){ + + if(myVeggie.getRoutines().isEmpty()){ + return new ArrayList<>(); + } + return myVeggie.getRoutines().stream() + .map(routine -> { + + return new MyVeggieRoutine(true, routine.getContent(), routine.getPeriod() ); + }) + .toList(); + } + +} diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/dto/response/MyVeggieDiaryCount.java b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/dto/response/MyVeggieDiaryCount.java new file mode 100644 index 00000000..b3e43cae --- /dev/null +++ b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/dto/response/MyVeggieDiaryCount.java @@ -0,0 +1,40 @@ +package com.modernfarmer.farmusspring.domain.myveggiegarden.dto.response; + + +import com.modernfarmer.farmusspring.domain.myveggiegarden.entity.Diary; +import com.modernfarmer.farmusspring.domain.myveggiegarden.entity.Routine; +import io.swagger.models.auth.In; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; + +import java.util.List; +import java.util.stream.Stream; + +@AllArgsConstructor +@NoArgsConstructor +@Getter +public class MyVeggieDiaryCount { + + private int diaryCount; + private int publicDiaryCount; + + public static MyVeggieDiaryCount of(int diaryCount, int publicDiaryCount){ + return new MyVeggieDiaryCount( + diaryCount, + publicDiaryCount + ); + } + + public static MyVeggieDiaryCount processData(List diaryList){ + + return MyVeggieDiaryCount.of(diaryList.size(),selectPublicDiaryCount(diaryList)); + + } + + public static int selectPublicDiaryCount(List diaryList){ + return (int) diaryList.stream() + .filter(diary -> diary.getIsOpen()) + .count(); + } +} diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/dto/response/MyVeggieRoutine.java b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/dto/response/MyVeggieRoutine.java new file mode 100644 index 00000000..a568aedb --- /dev/null +++ b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/dto/response/MyVeggieRoutine.java @@ -0,0 +1,57 @@ +package com.modernfarmer.farmusspring.domain.myveggiegarden.dto.response; + + +import com.modernfarmer.farmusspring.domain.myveggiegarden.entity.Routine; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Component; + +import java.time.LocalDate; +import java.util.Date; +import java.util.List; + + +@AllArgsConstructor +@NoArgsConstructor +@Getter +public class MyVeggieRoutine { + + private Boolean check; + private String content; + private int period; + + + public static MyVeggieRoutine of(Routine routine, Boolean check){ + return new MyVeggieRoutine( + check, + routine.getContent(), + routine.getPeriod() + ); + } + + + + public static List processData(List routineList){ + return routineList.stream() + .map(routine -> { + boolean check; + + check = signRoutineCheck(routine.getDate()); + return MyVeggieRoutine.of(routine, check); + }) + .toList(); + } + + + private static Boolean signRoutineCheck(Date date){ + boolean check = true; + if (date.equals(LocalDate.now())) { + check = false; + } + return check; + } + +} diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/dto/response/SelectMyVeggieListDto.java b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/dto/response/SelectMyVeggieListDto.java index 0d7a40ac..ec95b0ac 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/dto/response/SelectMyVeggieListDto.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/dto/response/SelectMyVeggieListDto.java @@ -1,15 +1,22 @@ package com.modernfarmer.farmusspring.domain.myveggiegarden.dto.response; +import com.modernfarmer.farmusspring.domain.myveggiegarden.entity.MyVeggie; import lombok.AllArgsConstructor; import lombok.Getter; import lombok.NoArgsConstructor; +import org.springframework.stereotype.Component; + +import java.util.List; + -@NoArgsConstructor @AllArgsConstructor @Getter public class SelectMyVeggieListDto { - public Long myVeggieId; - public String nickname; + public static List processData(List myVeggieList){ + return myVeggieList.stream() + .map(myVeggie -> SelectMyVeggieListResponse.of(myVeggie.getVeggieInfoId(),myVeggie.getNickname())) + .toList(); + } } diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/dto/response/SelectMyVeggieListResponse.java b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/dto/response/SelectMyVeggieListResponse.java index 22912cb0..ed61d014 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/dto/response/SelectMyVeggieListResponse.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/dto/response/SelectMyVeggieListResponse.java @@ -10,9 +10,11 @@ @NoArgsConstructor @AllArgsConstructor(staticName = "of") @Getter - public class SelectMyVeggieListResponse { - List simpleMyVeggieList; + // List simpleMyVeggieList; + public Long myVeggieId; + public String nickname; + } diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/dto/response/SelectMyVeggieProfileResponse.java b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/dto/response/SelectMyVeggieProfileResponse.java new file mode 100644 index 00000000..3189facd --- /dev/null +++ b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/dto/response/SelectMyVeggieProfileResponse.java @@ -0,0 +1,18 @@ +package com.modernfarmer.farmusspring.domain.myveggiegarden.dto.response; + + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@NoArgsConstructor +@AllArgsConstructor(staticName = "of") +@Getter +public class SelectMyVeggieProfileResponse { + + private String veggieName; + private String veggieImage; + private String createdVeggie; + private int period; + private int step; +} diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/entity/MyVeggie.java b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/entity/MyVeggie.java index 309dba88..e0e8be6d 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/entity/MyVeggie.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/entity/MyVeggie.java @@ -35,6 +35,13 @@ public class MyVeggie extends BaseEntity { @Column(name = "veggie_info_id") private Long veggieInfoId; + @Column(name = "veggie_name") + private String veggieName; + + @Column(name = "veggie_image") + private String veggieImage; + + @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "user_id") private User user; @@ -51,11 +58,16 @@ public class MyVeggie extends BaseEntity { @JoinColumn(name = "user_farm_club_id") private UserFarmClub userFarmClub; - public static MyVeggie createMyVegetable(String nickname, Date birth, Long veggieInfoId, User user){ + public static MyVeggie createMyVegetable(String nickname, Date birth, Long veggieInfoId, + String veggieName, + String veggieImage, + User user){ MyVeggie newMyVeggie = MyVeggie.builder() .nickname(nickname) .birth(birth) .veggieInfoId(veggieInfoId) + .veggieName(veggieName) + .veggieImage(veggieImage) .user(user) .build(); diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/repository/MyVeggieRepository.java b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/repository/MyVeggieRepository.java index be56c478..9cd49c93 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/repository/MyVeggieRepository.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/repository/MyVeggieRepository.java @@ -3,11 +3,15 @@ import com.modernfarmer.farmusspring.domain.myveggiegarden.entity.Diary; import com.modernfarmer.farmusspring.domain.myveggiegarden.entity.MyVeggie; +import com.modernfarmer.farmusspring.domain.myveggiegarden.entity.Routine; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; +import java.time.LocalDate; +import java.util.Date; import java.util.List; import java.util.Optional; @@ -26,9 +30,18 @@ public interface MyVeggieRepository extends JpaRepository { List findMyVeggieUserId(@Param("userId") Long userId); + @Query("SELECT mv FROM my_veggie AS mv LEFT JOIN mv.userFarmClub WHERE mv.id= :myVeggieId") + MyVeggie findMyVeggieAndFarmClub(@Param("myVeggieId") Long myVeggieId); + @Query("SELECT r FROM routine AS r WHERE r.myVeggie = :myVeggie ") + List findMyVeggieRoutineById(@Param("myVeggie") MyVeggie myVeggie); + @Modifying + @Query("UPDATE my_veggie SET nickname = :nickname, birth = :birth WHERE id = :myVeggieId ") + void updateMyVeggie(@Param("myVeggieId") Long myVeggieId, + @Param("nickname") String nickanme, + @Param("birth") Date birth); - - + @Query("SELECT mv FROM my_veggie AS mv LEFT JOIN mv.routines WHERE mv.user.id= :userId") + List findMyVeggieAndRoutine(@Param("userId") Long userId); } diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/service/MyVeggieDiaryService.java b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/service/MyVeggieDiaryService.java index 6eddef61..f9419c80 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/service/MyVeggieDiaryService.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/service/MyVeggieDiaryService.java @@ -1,6 +1,8 @@ package com.modernfarmer.farmusspring.domain.myveggiegarden.service; +import com.modernfarmer.farmusspring.domain.myveggiegarden.dto.response.AllDairy; import com.modernfarmer.farmusspring.domain.myveggiegarden.dto.response.CheckTodayDiaryResponse; +import com.modernfarmer.farmusspring.domain.myveggiegarden.dto.response.MyVeggieDiaryCount; import com.modernfarmer.farmusspring.domain.myveggiegarden.dto.response.SelectDiaryOneResponse; import com.modernfarmer.farmusspring.domain.myveggiegarden.entity.Diary; import com.modernfarmer.farmusspring.domain.myveggiegarden.entity.MyVeggie; @@ -59,6 +61,21 @@ public BaseResponseDto checkTodayDiary( boolean state = verifyDiaryState(diary); return BaseResponseDto.of(SuccessCode.SUCCESS,CheckTodayDiaryResponse.of(state)); } + @Transactional + public MyVeggieDiaryCount selectDiaryCount(MyVeggie myVeggie) { + + List diaryList = myVeggieRepository.findDiariesByMyVeggie(myVeggie); + return MyVeggieDiaryCount.processData(diaryList); + } + + @Transactional + public List selectDiaryAll(MyVeggie myVeggie) { + + List diaryList = selectDiaryByMyVeggie(myVeggie); + return AllDairy.processData(diaryList); + } + + @Transactional public BaseResponseDto selectDiaryOne( @@ -95,6 +112,7 @@ public List selectDiaryByMyVeggie(MyVeggie myVeggie){ return myVeggieRepository.findDiariesByMyVeggie(myVeggie); } + private void addMyyVeggieDiary( String content, boolean isOpen, @@ -103,8 +121,6 @@ private void addMyyVeggieDiary( Long myVeggieId ){ MyVeggie myVeggie = myVeggieGardenService.getMyVeggie(myVeggieId); - - Diary newDiary = Diary.createDiary( content, isOpen, diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/service/MyVeggieGardenService.java b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/service/MyVeggieGardenService.java index 3c4d7e01..b723b90e 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/service/MyVeggieGardenService.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/service/MyVeggieGardenService.java @@ -1,9 +1,11 @@ package com.modernfarmer.farmusspring.domain.myveggiegarden.service; +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.SelectMyVeggieListDto; -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.util.DateManager; import com.modernfarmer.farmusspring.domain.user.entity.User; import com.modernfarmer.farmusspring.global.response.BaseResponseDto; import com.modernfarmer.farmusspring.global.response.SuccessCode; @@ -13,8 +15,9 @@ import org.springframework.transaction.annotation.Transactional; import com.modernfarmer.farmusspring.domain.myveggiegarden.repository.MyVeggieRepository; + +import java.util.Date; import java.util.List; -import java.util.stream.Collectors; @Slf4j @AllArgsConstructor @@ -22,6 +25,10 @@ public class MyVeggieGardenService { private final MyVeggieRepository myVeggieRepository; + private final DateManager dateManager; + private final MyDetailMyVeggieDto myDetailMyVeggieDto; + + @Transactional public BaseResponseDto settingMyVeggie(Long userId, SettingMyVeggieRequest settingMyVeggieRequest) { @@ -31,21 +38,69 @@ public BaseResponseDto settingMyVeggie(Long userId, SettingMyVeggieRequest } @Transactional - public BaseResponseDto selectMyVeggieList(Long userId) { + public BaseResponseDto> selectMyVeggieList(Long userId) { + List myVeggieList = bringMyVeggieData(userId); + List selectMyVeggieLists = SelectMyVeggieListDto.processData(myVeggieList); + return BaseResponseDto.of(SuccessCode.SUCCESS,selectMyVeggieLists); + } + + @Transactional + public BaseResponseDto deleteMyVeggie(DeleteMyVeggieRequest deleteMyVeggieRequest) { + deleteMyVeggieById((deleteMyVeggieRequest.getMyVeggieId())); + return BaseResponseDto.of(SuccessCode.SUCCESS, null); + } + + @Transactional + public BaseResponseDto selectMyVeggieProfile(Long myVeggieId) { + MyVeggie myVeggie = selectMyVeggieAndFarmClub(myVeggieId); + return BaseResponseDto.of(SuccessCode.SUCCESS, + SelectMyVeggieProfileResponse.of( + myVeggie.getVeggieName(), + myVeggie.getVeggieImage(), + dateManager.parsingDotDate(myVeggie.getBirth()), + dateManager.calculateDay(myVeggie.getBirth(), new Date()), + checkFarmClubAffiliation(myVeggie) + )); + } + + + @Transactional + public BaseResponseDto> selectDetailMyVeggieList(Long userId) { + List myVeggieList = bringMyVeggieData(userId); - List selectMyVeggieLists = processingSimpleMyVeggieData(myVeggieList); - return BaseResponseDto.of(SuccessCode.SUCCESS,SelectMyVeggieListResponse.of(selectMyVeggieLists)); + List selectMyVeggieList = myDetailMyVeggieDto.processData(myVeggieList); + return BaseResponseDto.of(SuccessCode.SUCCESS,selectMyVeggieList); + } + + @Transactional + public void myVeggieUpdate(MyVeggieUpdate myVeggieUpdate) { + myVeggieRepository.updateMyVeggie(myVeggieUpdate.getMyVeggieId(), myVeggieUpdate.getNickname(), myVeggieUpdate.getBirth()); + } + + + + public int checkFarmClubAffiliation(MyVeggie myVeggie){ + if(myVeggie.getUserFarmClub() == null) + return -1; + return myVeggie.getUserFarmClub().getCurrentStep(); + } + + + public MyVeggie selectMyVeggieAndFarmClub(Long myVeggieId){ + return myVeggieRepository.findMyVeggieAndFarmClub(myVeggieId); + + } + + + public void deleteMyVeggieById(Long myVeggieId) { + myVeggieRepository.deleteById(myVeggieId); } private List bringMyVeggieData(Long userId){ return myVeggieRepository.findMyVeggieUserId(userId); } - private List processingSimpleMyVeggieData(List myVeggieList){ - return myVeggieList.stream() - .map(myVeggie -> new SelectMyVeggieListDto(myVeggie.getVeggieInfoId(),myVeggie.getNickname())) - .collect(Collectors.toList()); - } + @@ -60,6 +115,8 @@ private void addMyyVeggie(Long userId, SettingMyVeggieRequest settingMyVeggiRequ settingMyVeggiRequest.getNickname(), settingMyVeggiRequest.getBirh(), settingMyVeggiRequest.getVeggiInfoId(), + settingMyVeggiRequest.getVeggieName(), + settingMyVeggiRequest.getVeggieImage(), User.builder().id(userId).build() ); myVeggieRepository.save(newMyVeggie); diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/service/MyVeggieRoutineService.java b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/service/MyVeggieRoutineService.java index 48d124fc..69fb6a79 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/service/MyVeggieRoutineService.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/service/MyVeggieRoutineService.java @@ -1,16 +1,21 @@ package com.modernfarmer.farmusspring.domain.myveggiegarden.service; 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.repository.MyVeggieRepository; import com.modernfarmer.farmusspring.global.response.BaseResponseDto; import com.modernfarmer.farmusspring.global.response.SuccessCode; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.util.Date; +import java.util.List; @Slf4j @AllArgsConstructor @@ -18,6 +23,8 @@ public class MyVeggieRoutineService { private final MyVeggieGardenService myVeggieGardenService; + private final MyVeggieRepository myVeggieRepository; + @Transactional @@ -29,6 +36,22 @@ public BaseResponseDto settingMyVeggieRoutine( } + @Transactional + public List selectMyVeggieRoutineById(MyVeggie myVeggie) { + + List routineList = myVeggieRepository.findMyVeggieRoutineById(myVeggie); + return MyVeggieRoutine.processData(routineList); + } + + @Transactional + public List selectMyVeggieRoutine(Long userId) { + + List myVeggieList = myVeggieRepository.findMyVeggieAndRoutine(userId); + return MyRoutineList.processData(myVeggieList); + } + + + private void addMyyVeggieRoutine(SettingMyVeggieRoutineReqeuest settingMyVeggieRoutineReqeuest){ MyVeggie myVeggie = myVeggieGardenService.getMyVeggie(settingMyVeggieRoutineReqeuest.getMyVeggieId()); diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/util/DateManager.java b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/util/DateManager.java new file mode 100644 index 00000000..605d18fa --- /dev/null +++ b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/util/DateManager.java @@ -0,0 +1,31 @@ +package com.modernfarmer.farmusspring.domain.myveggiegarden.util; + +import org.springframework.stereotype.Component; + +import java.text.SimpleDateFormat; +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; +import java.util.Date; + + +@Component +public class DateManager { + + public String parsingDotDate(Date date){ + SimpleDateFormat format = new SimpleDateFormat("yy.MM.dd"); + return format.format(date); + } + public int calculateDay(Date startDate, Date endDate) { + long differenceMillis = endDate.getTime() - startDate.getTime(); + long differenceDays = differenceMillis / (1000 * 60 * 60 * 24); + return (int) differenceDays; + } + + public static String formatDate(LocalDateTime date) { + + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy년 MM월 dd일"); + String formattedDate = date.format(formatter); + return formattedDate; + } + +} diff --git a/src/main/java/com/modernfarmer/farmusspring/global/common/security/SecurityConfig.java b/src/main/java/com/modernfarmer/farmusspring/global/common/security/SecurityConfig.java index 5e2fd934..30ffad20 100644 --- a/src/main/java/com/modernfarmer/farmusspring/global/common/security/SecurityConfig.java +++ b/src/main/java/com/modernfarmer/farmusspring/global/common/security/SecurityConfig.java @@ -59,7 +59,8 @@ public SecurityFilterChain filterChain(HttpSecurity http, HandlerMappingIntrospe "/api/veggie-info/**", "api/my-veggie", "api/my-veggie/diary", - "/api/my-veggie/simple-list" + "/api/my-veggie/simple-list", + "/api/my-veggie/list" ).permitAll() ) .authorizeHttpRequests(request -> request.anyRequest().authenticated()); @@ -77,6 +78,7 @@ public WebSecurityCustomizer configure() { .requestMatchers("/api/my-veggie/routine") .requestMatchers("/api/my-veggie/diary/{myVeggieId}/one") .requestMatchers("/api/my-veggie/diary/check") + .requestMatchers("/api/my-veggie/{myVeggieId}/profile") ); }