From a41cab3bc7f2c8871ba87c68e95ce13757aa5c8b Mon Sep 17 00:00:00 2001 From: seungryeol Date: Fri, 5 Apr 2024 15:19:26 +0900 Subject: [PATCH 01/12] =?UTF-8?q?[feat]=201.=20=EB=82=B4=20=EC=B1=84?= =?UTF-8?q?=EC=86=8C=20=EB=93=B1=EB=A1=9D=20API=20=EC=99=84=EB=A3=8C=20=20?= =?UTF-8?q?=20=20=20=20=202.=20=EB=82=B4=20=EC=B1=84=EC=86=8C=20=EC=9D=BC?= =?UTF-8?q?=EA=B8=B0=20=EB=93=B1=EB=A1=9D=20API=20=EB=AF=B8=EC=99=84?= =?UTF-8?q?=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/MyVeggieGardenController.java | 57 ++++++++++++ .../request/SettingMyVeggiDiaryRequest.java | 30 +++++++ .../dto/request/SettingMyVeggiRequest.java | 24 +++++ .../myveggiegarden/entity/MyVeggie.java | 4 +- .../repository/MyVeggieRepository.java | 11 +++ .../service/MyVeggieGardenService.java | 87 +++++++++++++++++++ .../common/security/SecurityConfig.java | 4 +- 7 files changed, 214 insertions(+), 3 deletions(-) create mode 100644 src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/controller/MyVeggieGardenController.java create mode 100644 src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/dto/request/SettingMyVeggiDiaryRequest.java create mode 100644 src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/dto/request/SettingMyVeggiRequest.java create mode 100644 src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/repository/MyVeggieRepository.java create mode 100644 src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/service/MyVeggieGardenService.java 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 new file mode 100644 index 00000000..36c56902 --- /dev/null +++ b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/controller/MyVeggieGardenController.java @@ -0,0 +1,57 @@ +package com.modernfarmer.farmusspring.domain.myveggiegarden.controller; + +import com.modernfarmer.farmusspring.domain.auth.entity.CustomUser; +import com.modernfarmer.farmusspring.domain.myveggiegarden.dto.request.SettingMyVeggiDiaryRequest; +import com.modernfarmer.farmusspring.domain.myveggiegarden.dto.request.SettingMyVeggiRequest; +import com.modernfarmer.farmusspring.domain.myveggiegarden.service.MyVeggieGardenService; +import com.modernfarmer.farmusspring.global.response.BaseResponseDto; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.http.MediaType; +import org.springframework.security.core.annotation.AuthenticationPrincipal; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; +import org.springframework.web.multipart.MultipartFile; + +import java.io.IOException; + +@Slf4j +@RequiredArgsConstructor +@RestController +@RequestMapping("/api/my-veggie") +public class MyVeggieGardenController { + + private final MyVeggieGardenService myVeggieGardenService; + + @PostMapping(value = "/") + public BaseResponseDto settingMyVeggi( + @AuthenticationPrincipal CustomUser user, + @Validated @RequestBody SettingMyVeggiRequest settingMyVeggi + ){ + + return myVeggieGardenService.settingMyVeggi( + user.getUserId(), + settingMyVeggi + ); + + } + + @PostMapping(value = "/diary", produces = MediaType.APPLICATION_JSON_VALUE) + public BaseResponseDto settingMyVeggiDiary( + @RequestPart(value = "file", required = false) MultipartFile multipartFile, + @RequestParam("content") String content, + @RequestParam("isOpen") boolean isOpen, + @RequestParam("state") String state, + @RequestParam("myVeggieId") Long myVeggieId + ) throws IOException { + return myVeggieGardenService.settingMyVeggiDiary( + multipartFile, + content, + isOpen, + state, + myVeggieId + ); + } + + +} diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/dto/request/SettingMyVeggiDiaryRequest.java b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/dto/request/SettingMyVeggiDiaryRequest.java new file mode 100644 index 00000000..152c3902 --- /dev/null +++ b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/dto/request/SettingMyVeggiDiaryRequest.java @@ -0,0 +1,30 @@ +package com.modernfarmer.farmusspring.domain.myveggiegarden.dto.request; + +import jakarta.validation.constraints.NotNull; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; + +import java.util.Date; + +@Getter +@AllArgsConstructor +@NoArgsConstructor +public class SettingMyVeggiDiaryRequest { + + @NotNull(message = "null 값을 가지면 안됩니다.") + private String conetent; + + @NotNull(message = "null 값을 가지면 안됩니다.") + private boolean isOpen; + + @NotNull(message = "null 값을 가지면 안됩니다.") + private String iamge; + + @NotNull(message = "null 값을 가지면 안됩니다.") + private String state; + + @NotNull(message = "null 값을 가지면 안됩니다.") + private Long myVeggieId; + +} diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/dto/request/SettingMyVeggiRequest.java b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/dto/request/SettingMyVeggiRequest.java new file mode 100644 index 00000000..da3bc572 --- /dev/null +++ b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/dto/request/SettingMyVeggiRequest.java @@ -0,0 +1,24 @@ +package com.modernfarmer.farmusspring.domain.myveggiegarden.dto.request; + + +import jakarta.validation.constraints.NotNull; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; + +import java.util.Date; + +@Getter +@AllArgsConstructor +@NoArgsConstructor +public class SettingMyVeggiRequest { + + @NotNull(message = "null 값을 가지면 안됩니다.") + private String nickname; + + @NotNull(message = "null 값을 가지면 안됩니다.") + private Date birh; + + @NotNull(message = "null 값을 가지면 안됩니다.") + private Long veggiInfoId; +} 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 fe3a33bc..ab0302cd 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 @@ -33,7 +33,7 @@ public class MyVeggie extends BaseEntity { private Date birth; @Column(name = "veggie_info_id") - private String veggieInfoId; + private Long veggieInfoId; @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "user_id") @@ -51,7 +51,7 @@ public class MyVeggie extends BaseEntity { @JoinColumn(name = "user_farm_club_id") private UserFarmClub userFarmClub; - public static MyVeggie createMyVegetable(String nickname, Date birth, String veggieInfoId, User user){ + public static MyVeggie createMyVegetable(String nickname, Date birth, Long veggieInfoId, User user){ MyVeggie newMyVeggie = MyVeggie.builder() .nickname(nickname) .birth(birth) 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 new file mode 100644 index 00000000..580b1192 --- /dev/null +++ b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/repository/MyVeggieRepository.java @@ -0,0 +1,11 @@ +package com.modernfarmer.farmusspring.domain.myveggiegarden.repository; + + +import com.modernfarmer.farmusspring.domain.myveggiegarden.entity.MyVeggie; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +@Repository +public interface MyVeggieRepository extends JpaRepository { + +} 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 new file mode 100644 index 00000000..844cf192 --- /dev/null +++ b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/service/MyVeggieGardenService.java @@ -0,0 +1,87 @@ +package com.modernfarmer.farmusspring.domain.myveggiegarden.service; + +import com.modernfarmer.farmusspring.domain.myveggiegarden.dto.request.SettingMyVeggiRequest; +import com.modernfarmer.farmusspring.domain.myveggiegarden.entity.Diary; +import com.modernfarmer.farmusspring.domain.myveggiegarden.entity.MyVeggie; +import com.modernfarmer.farmusspring.domain.user.entity.User; +import com.modernfarmer.farmusspring.global.response.BaseResponseDto; +import com.modernfarmer.farmusspring.global.response.SuccessCode; +import com.modernfarmer.farmusspring.infra.s3.S3Service; +import lombok.AllArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import com.modernfarmer.farmusspring.domain.myveggiegarden.repository.MyVeggieRepository; +import org.springframework.web.multipart.MultipartFile; + +import java.io.IOException; + +@Slf4j +@AllArgsConstructor +@Service +public class MyVeggieGardenService { + + private final MyVeggieRepository myVeggieRepository; + private final S3Service s3Service; + + + @Transactional + public BaseResponseDto settingMyVeggi(Long userId, SettingMyVeggiRequest settingMyVeggiRequest) { + + addMyyVeggi(userId, settingMyVeggiRequest); + return BaseResponseDto.of(SuccessCode.SUCCESS,null); + } + + @Transactional + public BaseResponseDto settingMyVeggiDiary( + MultipartFile multipartFile, + String content, + boolean isOpen, + String state, + Long myVeggieId + ) throws IOException { + + String imageUrl = getImageUrl(multipartFile); + addMyyVeggiDiary( + content, + isOpen, + imageUrl, + state, + MyVeggie.builder().veggieInfoId(myVeggieId).build() + ); + return BaseResponseDto.of(SuccessCode.SUCCESS,null); + } + + private void addMyyVeggiDiary( + String content, + boolean isOpen, + String image, + String state, + MyVeggie myVeggie + ){ + Diary newDiary = Diary.createDiary( + content, + isOpen, + image, + state, + myVeggie + ); + myVeggie.addDiary(newDiary); + } + + private void addMyyVeggi(Long userId, SettingMyVeggiRequest settingMyVeggiRequest){ + + MyVeggie newMyVeggie = MyVeggie.createMyVegetable( + settingMyVeggiRequest.getNickname(), + settingMyVeggiRequest.getBirh(), + settingMyVeggiRequest.getVeggiInfoId(), + User.builder().id(userId).build() + ); + myVeggieRepository.save(newMyVeggie); + } + + private String getImageUrl(MultipartFile multipartFile) throws IOException { + return s3Service.uploadImage(multipartFile, "dairyimage"); + } + +} 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 0a8854f8..ce96f426 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 @@ -56,7 +56,9 @@ public SecurityFilterChain filterChain(HttpSecurity http, HandlerMappingIntrospe "/api/user/profile-image", "/api/user/profile", "/api/veggie-info", - "/api/veggie-info/**" + "/api/veggie-info/**", + "api/my-veggie", + "api/my-veggie/diary" ).permitAll() ) .authorizeHttpRequests(request -> request.anyRequest().authenticated()); From 7c5b92df1be1fa05ad3b7fad57ee4ebefacebe1f Mon Sep 17 00:00:00 2001 From: seungryeol Date: Fri, 5 Apr 2024 15:41:19 +0900 Subject: [PATCH 02/12] =?UTF-8?q?[fix]=20=EB=82=B4=20=EC=B1=84=EC=86=8C=20?= =?UTF-8?q?=EC=9D=BC=EA=B8=B0=20=EB=93=B1=EB=A1=9D=20API=20->=20MyVeggieDi?= =?UTF-8?q?ary=20Controlle=EB=A1=9C=20=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/MyVeggieDiaryController.java | 38 +++++++++++ .../controller/MyVeggieGardenController.java | 17 +---- .../service/MyVeggieDiaryService.java | 65 +++++++++++++++++++ .../service/MyVeggieGardenService.java | 45 +------------ 4 files changed, 105 insertions(+), 60 deletions(-) create mode 100644 src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/controller/MyVeggieDiaryController.java create mode 100644 src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/service/MyVeggieDiaryService.java 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 new file mode 100644 index 00000000..0ab8681a --- /dev/null +++ b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/controller/MyVeggieDiaryController.java @@ -0,0 +1,38 @@ +package com.modernfarmer.farmusspring.domain.myveggiegarden.controller; + +import com.modernfarmer.farmusspring.domain.myveggiegarden.service.MyVeggieDiaryService; +import com.modernfarmer.farmusspring.domain.myveggiegarden.service.MyVeggieGardenService; +import com.modernfarmer.farmusspring.global.response.BaseResponseDto; +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; + +@Slf4j +@RequiredArgsConstructor +@RestController +@RequestMapping("/api/my-veggie/diary") +public class MyVeggieDiaryController { + + private final MyVeggieDiaryService myVeggieDiaryService; + + @PostMapping(value = "/", produces = MediaType.APPLICATION_JSON_VALUE) + public BaseResponseDto settingMyVeggiDiary( + @RequestPart(value = "file", required = false) MultipartFile multipartFile, + @RequestParam("content") String content, + @RequestParam("isOpen") boolean isOpen, + @RequestParam("state") String state, + @RequestParam("myVeggieId") Long myVeggieId + ) throws IOException { + return myVeggieDiaryService.settingMyVeggiDiary( + multipartFile, + content, + isOpen, + state, + myVeggieId + ); + } +} 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 36c56902..e9005c8e 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 @@ -36,22 +36,7 @@ public BaseResponseDto settingMyVeggi( } - @PostMapping(value = "/diary", produces = MediaType.APPLICATION_JSON_VALUE) - public BaseResponseDto settingMyVeggiDiary( - @RequestPart(value = "file", required = false) MultipartFile multipartFile, - @RequestParam("content") String content, - @RequestParam("isOpen") boolean isOpen, - @RequestParam("state") String state, - @RequestParam("myVeggieId") Long myVeggieId - ) throws IOException { - return myVeggieGardenService.settingMyVeggiDiary( - multipartFile, - content, - isOpen, - state, - myVeggieId - ); - } + } 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 new file mode 100644 index 00000000..2188301c --- /dev/null +++ b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/service/MyVeggieDiaryService.java @@ -0,0 +1,65 @@ +package com.modernfarmer.farmusspring.domain.myveggiegarden.service; + +import com.modernfarmer.farmusspring.domain.myveggiegarden.entity.Diary; +import com.modernfarmer.farmusspring.domain.myveggiegarden.entity.MyVeggie; +import com.modernfarmer.farmusspring.domain.myveggiegarden.repository.MyVeggieRepository; +import com.modernfarmer.farmusspring.global.response.BaseResponseDto; +import com.modernfarmer.farmusspring.global.response.SuccessCode; +import com.modernfarmer.farmusspring.infra.s3.S3Service; +import lombok.AllArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.web.multipart.MultipartFile; + +import java.io.IOException; + +@Slf4j +@AllArgsConstructor +@Service +public class MyVeggieDiaryService { + + private final S3Service s3Service; + + @Transactional + public BaseResponseDto settingMyVeggiDiary( + MultipartFile multipartFile, + String content, + boolean isOpen, + String state, + Long myVeggieId + ) throws IOException { + + String imageUrl = getImageUrl(multipartFile); + log.info(String.valueOf(MyVeggie.builder().id(myVeggieId).build().getId())); + addMyyVeggiDiary( + content, + isOpen, + imageUrl, + state, + MyVeggie.builder().id(myVeggieId).build() + ); + return BaseResponseDto.of(SuccessCode.SUCCESS,null); + } + + private void addMyyVeggiDiary( + String content, + boolean isOpen, + String image, + String state, + MyVeggie myVeggie + ){ + Diary newDiary = Diary.createDiary( + content, + isOpen, + image, + state, + myVeggie + ); + myVeggie.addDiary(newDiary); + } + + private String getImageUrl(MultipartFile multipartFile) throws IOException { + return s3Service.uploadImage(multipartFile, "dairyimage"); + } +} 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 844cf192..e6654493 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 @@ -6,15 +6,11 @@ import com.modernfarmer.farmusspring.domain.user.entity.User; import com.modernfarmer.farmusspring.global.response.BaseResponseDto; import com.modernfarmer.farmusspring.global.response.SuccessCode; -import com.modernfarmer.farmusspring.infra.s3.S3Service; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import com.modernfarmer.farmusspring.domain.myveggiegarden.repository.MyVeggieRepository; -import org.springframework.web.multipart.MultipartFile; - -import java.io.IOException; @Slf4j @AllArgsConstructor @@ -22,8 +18,6 @@ public class MyVeggieGardenService { private final MyVeggieRepository myVeggieRepository; - private final S3Service s3Service; - @Transactional public BaseResponseDto settingMyVeggi(Long userId, SettingMyVeggiRequest settingMyVeggiRequest) { @@ -32,42 +26,7 @@ public BaseResponseDto settingMyVeggi(Long userId, SettingMyVeggiRequest s return BaseResponseDto.of(SuccessCode.SUCCESS,null); } - @Transactional - public BaseResponseDto settingMyVeggiDiary( - MultipartFile multipartFile, - String content, - boolean isOpen, - String state, - Long myVeggieId - ) throws IOException { - String imageUrl = getImageUrl(multipartFile); - addMyyVeggiDiary( - content, - isOpen, - imageUrl, - state, - MyVeggie.builder().veggieInfoId(myVeggieId).build() - ); - return BaseResponseDto.of(SuccessCode.SUCCESS,null); - } - - private void addMyyVeggiDiary( - String content, - boolean isOpen, - String image, - String state, - MyVeggie myVeggie - ){ - Diary newDiary = Diary.createDiary( - content, - isOpen, - image, - state, - myVeggie - ); - myVeggie.addDiary(newDiary); - } private void addMyyVeggi(Long userId, SettingMyVeggiRequest settingMyVeggiRequest){ @@ -80,8 +39,6 @@ private void addMyyVeggi(Long userId, SettingMyVeggiRequest settingMyVeggiReques myVeggieRepository.save(newMyVeggie); } - private String getImageUrl(MultipartFile multipartFile) throws IOException { - return s3Service.uploadImage(multipartFile, "dairyimage"); - } + } From d9091d313f2ddf8678aa9bf832ff38725b53397d Mon Sep 17 00:00:00 2001 From: seungryeol Date: Fri, 5 Apr 2024 16:39:42 +0900 Subject: [PATCH 03/12] =?UTF-8?q?[fix]=20=EB=82=B4=20=EC=B1=84=EC=86=8C=20?= =?UTF-8?q?=EC=9D=BC=EA=B8=B0=20=EB=93=B1=EB=A1=9D=20API=20->=20findById?= =?UTF-8?q?=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repository/MyVeggieRepository.java | 2 ++ .../service/MyVeggieDiaryService.java | 15 ++++++++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) 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 580b1192..743d3a65 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 @@ -8,4 +8,6 @@ @Repository public interface MyVeggieRepository extends JpaRepository { + MyVeggie findMyVeggieById(Long id); + } 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 2188301c..b2081f1c 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 @@ -13,11 +13,13 @@ import org.springframework.web.multipart.MultipartFile; import java.io.IOException; +import java.util.Optional; @Slf4j @AllArgsConstructor @Service public class MyVeggieDiaryService { + private final MyVeggieRepository myVeggieRepository; private final S3Service s3Service; @@ -32,17 +34,22 @@ public BaseResponseDto settingMyVeggiDiary( String imageUrl = getImageUrl(multipartFile); log.info(String.valueOf(MyVeggie.builder().id(myVeggieId).build().getId())); + + MyVeggie myVeggie = myVeggieRepository.findMyVeggieById(myVeggieId); + + // log.info(myVeggie.getNickname()); addMyyVeggiDiary( content, isOpen, imageUrl, state, - MyVeggie.builder().id(myVeggieId).build() + // MyVeggie.builder().id(myVeggieId).build() + myVeggie ); return BaseResponseDto.of(SuccessCode.SUCCESS,null); } - - private void addMyyVeggiDiary( + @Transactional + public void addMyyVeggiDiary( String content, boolean isOpen, String image, @@ -56,7 +63,9 @@ private void addMyyVeggiDiary( state, myVeggie ); + log.info("start"); myVeggie.addDiary(newDiary); + log.info("finish"); } private String getImageUrl(MultipartFile multipartFile) throws IOException { From dc5d749e4f212fe84d211b42f1159e186c66d9bb Mon Sep 17 00:00:00 2001 From: MinchoGreenT Date: Fri, 5 Apr 2024 17:01:47 +0900 Subject: [PATCH 04/12] =?UTF-8?q?[fix]=20MyVeggie.java=20->=20diary=20casc?= =?UTF-8?q?ade=20ALL=20=EC=84=A4=EC=A0=95=20MyVeggieGardenService=20?= =?UTF-8?q?=EC=97=90=20=EC=B1=84=EC=86=8C=20=EC=B0=BE=EB=8A=94=20=EB=A9=94?= =?UTF-8?q?=EC=84=9C=EB=93=9C=20=EC=B6=94=EA=B0=80=20MyVeggieDiaryService?= =?UTF-8?q?=20=EB=A1=9C=EC=A7=81=20findById()=20=EC=9D=B4=ED=9B=84=20addDi?= =?UTF-8?q?ary()=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/myveggiegarden/entity/MyVeggie.java | 2 +- .../myveggiegarden/service/MyVeggieDiaryService.java | 9 ++++++--- .../myveggiegarden/service/MyVeggieGardenService.java | 7 ++++--- 3 files changed, 11 insertions(+), 7 deletions(-) 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 ab0302cd..fbb57a43 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 @@ -43,7 +43,7 @@ public class MyVeggie extends BaseEntity { @Builder.Default private List routines = new ArrayList<>(); - @OneToMany(mappedBy = "myVeggie", fetch = FetchType.LAZY, cascade = CascadeType.REMOVE) + @OneToMany(mappedBy = "myVeggie", fetch = FetchType.LAZY, cascade = CascadeType.ALL) @Builder.Default private List diaries = new ArrayList<>(); 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 2188301c..b67e084c 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 @@ -20,6 +20,8 @@ public class MyVeggieDiaryService { private final S3Service s3Service; + private final MyVeggieRepository myVeggieRepository; + private final MyVeggieGardenService myVeggieGardenService; @Transactional public BaseResponseDto settingMyVeggiDiary( @@ -31,13 +33,12 @@ public BaseResponseDto settingMyVeggiDiary( ) throws IOException { String imageUrl = getImageUrl(multipartFile); - log.info(String.valueOf(MyVeggie.builder().id(myVeggieId).build().getId())); addMyyVeggiDiary( content, isOpen, imageUrl, state, - MyVeggie.builder().id(myVeggieId).build() + myVeggieId ); return BaseResponseDto.of(SuccessCode.SUCCESS,null); } @@ -47,8 +48,10 @@ private void addMyyVeggiDiary( boolean isOpen, String image, String state, - MyVeggie myVeggie + 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 e6654493..8484cd35 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 @@ -26,7 +26,10 @@ public BaseResponseDto settingMyVeggi(Long userId, SettingMyVeggiRequest s return BaseResponseDto.of(SuccessCode.SUCCESS,null); } - + public MyVeggie getMyVeggie(Long userId){ + return myVeggieRepository.findById(userId) + .orElseThrow(() -> new IllegalArgumentException("채소가 존재하지 않습니다.")); + } private void addMyyVeggi(Long userId, SettingMyVeggiRequest settingMyVeggiRequest){ @@ -39,6 +42,4 @@ private void addMyyVeggi(Long userId, SettingMyVeggiRequest settingMyVeggiReques myVeggieRepository.save(newMyVeggie); } - - } From 7f6e88809636999c0a23f313395988b0bf4e6ac0 Mon Sep 17 00:00:00 2001 From: seungryeol Date: Fri, 5 Apr 2024 18:07:51 +0900 Subject: [PATCH 05/12] =?UTF-8?q?[fix]=20Veggi=20->=20Veggie=20=EC=98=A4?= =?UTF-8?q?=ED=83=80=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../myveggiegarden/controller/MyVeggieDiaryController.java | 4 ++-- .../myveggiegarden/service/MyVeggieDiaryService.java | 7 ++++--- 2 files changed, 6 insertions(+), 5 deletions(-) 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 0ab8681a..519f2115 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 @@ -20,14 +20,14 @@ public class MyVeggieDiaryController { private final MyVeggieDiaryService myVeggieDiaryService; @PostMapping(value = "/", produces = MediaType.APPLICATION_JSON_VALUE) - public BaseResponseDto settingMyVeggiDiary( + public BaseResponseDto settingMyVeggieDiary( @RequestPart(value = "file", required = false) MultipartFile multipartFile, @RequestParam("content") String content, @RequestParam("isOpen") boolean isOpen, @RequestParam("state") String state, @RequestParam("myVeggieId") Long myVeggieId ) throws IOException { - return myVeggieDiaryService.settingMyVeggiDiary( + return myVeggieDiaryService.settingMyVeggieDiary( multipartFile, content, isOpen, 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 b67e084c..b8297e13 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 @@ -24,7 +24,7 @@ public class MyVeggieDiaryService { private final MyVeggieGardenService myVeggieGardenService; @Transactional - public BaseResponseDto settingMyVeggiDiary( + public BaseResponseDto settingMyVeggieDiary( MultipartFile multipartFile, String content, boolean isOpen, @@ -33,7 +33,7 @@ public BaseResponseDto settingMyVeggiDiary( ) throws IOException { String imageUrl = getImageUrl(multipartFile); - addMyyVeggiDiary( + addMyyVeggieDiary( content, isOpen, imageUrl, @@ -43,7 +43,7 @@ public BaseResponseDto settingMyVeggiDiary( return BaseResponseDto.of(SuccessCode.SUCCESS,null); } - private void addMyyVeggiDiary( + private void addMyyVeggieDiary( String content, boolean isOpen, String image, @@ -52,6 +52,7 @@ private void addMyyVeggiDiary( ){ MyVeggie myVeggie = myVeggieGardenService.getMyVeggie(myVeggieId); + Diary newDiary = Diary.createDiary( content, isOpen, From edc04ae49f1dac68c49ff3fffb06ea7a66b29732 Mon Sep 17 00:00:00 2001 From: seungryeol Date: Sat, 6 Apr 2024 15:03:50 +0900 Subject: [PATCH 06/12] =?UTF-8?q?[fix]=20Routine=20Table=20notify=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../farmusspring/domain/myveggiegarden/entity/Routine.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/entity/Routine.java b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/entity/Routine.java index 9fafe378..ad80c230 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/entity/Routine.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/entity/Routine.java @@ -35,17 +35,22 @@ public class Routine extends BaseEntity { @Column(name = "period") private int period; + @Column(name = "notify") + private boolean notify; + + @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "my_veggie_id") private MyVeggie myVeggie; - public static Routine createRoutine(Date date, String content, int period, MyVeggie myVeggie){ + public static Routine createRoutine(Date date, String content, int period, MyVeggie myVeggie, boolean notify){ Routine newRoutine = Routine.builder() .date(date) .content(content) .period(period) .myVeggie(myVeggie) + .notify(notify) .build(); myVeggie.addRoutine(newRoutine); From 952b7f2cde37a1ac398bccb93c45a6d9da66534a Mon Sep 17 00:00:00 2001 From: seungryeol Date: Sat, 6 Apr 2024 15:04:17 +0900 Subject: [PATCH 07/12] =?UTF-8?q?[feat]=20=EB=82=B4=20=EC=B1=84=EC=86=8C?= =?UTF-8?q?=20=EB=A3=A8=ED=8B=B4=20=EC=B6=94=EA=B0=80=20api=20=EC=99=84?= =?UTF-8?q?=EB=A3=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/MyVeggieGardenController.java | 7 +-- .../controller/MyVeggieRoutineController.java | 28 ++++++++++ ...va => SettingMyVeggieRoutineReqeuest.java} | 16 ++---- .../myveggiegarden/entity/MyVeggie.java | 2 +- .../service/MyVeggieDiaryService.java | 1 - .../service/MyVeggieGardenService.java | 6 +-- .../service/MyVeggieRoutineService.java | 51 +++++++++++++++++++ 7 files changed, 90 insertions(+), 21 deletions(-) create mode 100644 src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/controller/MyVeggieRoutineController.java rename src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/dto/request/{SettingMyVeggiDiaryRequest.java => SettingMyVeggieRoutineReqeuest.java} (53%) create mode 100644 src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/service/MyVeggieRoutineService.java 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 e9005c8e..f5f6af97 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 @@ -1,19 +1,16 @@ package com.modernfarmer.farmusspring.domain.myveggiegarden.controller; import com.modernfarmer.farmusspring.domain.auth.entity.CustomUser; -import com.modernfarmer.farmusspring.domain.myveggiegarden.dto.request.SettingMyVeggiDiaryRequest; + import com.modernfarmer.farmusspring.domain.myveggiegarden.dto.request.SettingMyVeggiRequest; import com.modernfarmer.farmusspring.domain.myveggiegarden.service.MyVeggieGardenService; import com.modernfarmer.farmusspring.global.response.BaseResponseDto; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.springframework.http.MediaType; import org.springframework.security.core.annotation.AuthenticationPrincipal; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; -import org.springframework.web.multipart.MultipartFile; -import java.io.IOException; @Slf4j @RequiredArgsConstructor @@ -29,7 +26,7 @@ public BaseResponseDto settingMyVeggi( @Validated @RequestBody SettingMyVeggiRequest settingMyVeggi ){ - return myVeggieGardenService.settingMyVeggi( + return myVeggieGardenService.settingMyVeggie( user.getUserId(), settingMyVeggi ); 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 new file mode 100644 index 00000000..998b65bf --- /dev/null +++ b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/controller/MyVeggieRoutineController.java @@ -0,0 +1,28 @@ +package com.modernfarmer.farmusspring.domain.myveggiegarden.controller; + +import com.modernfarmer.farmusspring.domain.myveggiegarden.dto.request.SettingMyVeggieRoutineReqeuest; +import com.modernfarmer.farmusspring.domain.myveggiegarden.service.MyVeggieRoutineService; +import com.modernfarmer.farmusspring.global.response.BaseResponseDto; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; + + +@Slf4j +@RequiredArgsConstructor +@RestController +@RequestMapping("/api/my-veggie/routine") +public class MyVeggieRoutineController { + + private final MyVeggieRoutineService myVeggieRoutineService; + + @PostMapping(value = "") + public BaseResponseDto settingMyVeggieRoutine( + @Validated @RequestBody SettingMyVeggieRoutineReqeuest settingMyVeggieRoutineReqeuest + ) { + + return myVeggieRoutineService.settingMyVeggieRoutine(settingMyVeggieRoutineReqeuest); + + } +} diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/dto/request/SettingMyVeggiDiaryRequest.java b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/dto/request/SettingMyVeggieRoutineReqeuest.java similarity index 53% rename from src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/dto/request/SettingMyVeggiDiaryRequest.java rename to src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/dto/request/SettingMyVeggieRoutineReqeuest.java index 152c3902..8eea5845 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/dto/request/SettingMyVeggiDiaryRequest.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/dto/request/SettingMyVeggieRoutineReqeuest.java @@ -1,28 +1,22 @@ package com.modernfarmer.farmusspring.domain.myveggiegarden.dto.request; + import jakarta.validation.constraints.NotNull; import lombok.AllArgsConstructor; import lombok.Getter; import lombok.NoArgsConstructor; -import java.util.Date; - @Getter @AllArgsConstructor @NoArgsConstructor -public class SettingMyVeggiDiaryRequest { - - @NotNull(message = "null 값을 가지면 안됩니다.") - private String conetent; +public class SettingMyVeggieRoutineReqeuest { @NotNull(message = "null 값을 가지면 안됩니다.") - private boolean isOpen; + private String content; - @NotNull(message = "null 값을 가지면 안됩니다.") - private String iamge; + private boolean notify; - @NotNull(message = "null 값을 가지면 안됩니다.") - private String state; + private int period; @NotNull(message = "null 값을 가지면 안됩니다.") private Long myVeggieId; 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 fbb57a43..309dba88 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 @@ -39,7 +39,7 @@ public class MyVeggie extends BaseEntity { @JoinColumn(name = "user_id") private User user; - @OneToMany(mappedBy = "myVeggie", fetch = FetchType.LAZY, cascade = CascadeType.REMOVE) + @OneToMany(mappedBy = "myVeggie", fetch = FetchType.LAZY, cascade = CascadeType.ALL) @Builder.Default private List routines = new ArrayList<>(); 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 b8297e13..c5d2802c 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 @@ -20,7 +20,6 @@ public class MyVeggieDiaryService { private final S3Service s3Service; - private final MyVeggieRepository myVeggieRepository; private final MyVeggieGardenService myVeggieGardenService; @Transactional 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 8484cd35..602236cf 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 @@ -20,9 +20,9 @@ public class MyVeggieGardenService { private final MyVeggieRepository myVeggieRepository; @Transactional - public BaseResponseDto settingMyVeggi(Long userId, SettingMyVeggiRequest settingMyVeggiRequest) { + public BaseResponseDto settingMyVeggie(Long userId, SettingMyVeggiRequest settingMyVeggiRequest) { - addMyyVeggi(userId, settingMyVeggiRequest); + addMyyVeggie(userId, settingMyVeggiRequest); return BaseResponseDto.of(SuccessCode.SUCCESS,null); } @@ -31,7 +31,7 @@ public MyVeggie getMyVeggie(Long userId){ .orElseThrow(() -> new IllegalArgumentException("채소가 존재하지 않습니다.")); } - private void addMyyVeggi(Long userId, SettingMyVeggiRequest settingMyVeggiRequest){ + private void addMyyVeggie(Long userId, SettingMyVeggiRequest settingMyVeggiRequest){ MyVeggie newMyVeggie = MyVeggie.createMyVegetable( settingMyVeggiRequest.getNickname(), 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 new file mode 100644 index 00000000..d888b50a --- /dev/null +++ b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/service/MyVeggieRoutineService.java @@ -0,0 +1,51 @@ +package com.modernfarmer.farmusspring.domain.myveggiegarden.service; + +import com.modernfarmer.farmusspring.domain.myveggiegarden.dto.request.SettingMyVeggiRequest; +import com.modernfarmer.farmusspring.domain.myveggiegarden.dto.request.SettingMyVeggieRoutineReqeuest; +import com.modernfarmer.farmusspring.domain.myveggiegarden.entity.MyVeggie; +import com.modernfarmer.farmusspring.domain.myveggiegarden.entity.Routine; +import com.modernfarmer.farmusspring.domain.user.entity.User; +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.mongodb.core.aggregation.ArithmeticOperators; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.web.multipart.MultipartFile; + +import java.io.IOException; +import java.util.Date; + +@Slf4j +@AllArgsConstructor +@Service +public class MyVeggieRoutineService { + + private final MyVeggieGardenService myVeggieGardenService; + + + @Transactional + public BaseResponseDto settingMyVeggieRoutine( + SettingMyVeggieRoutineReqeuest settingMyVeggieRoutineReqeuest + ) { + addMyyVeggieRoutine(settingMyVeggieRoutineReqeuest); + return BaseResponseDto.of(SuccessCode.SUCCESS,null); + } + + + + private void addMyyVeggieRoutine(SettingMyVeggieRoutineReqeuest settingMyVeggieRoutineReqeuest){ + MyVeggie myVeggie = myVeggieGardenService.getMyVeggie(settingMyVeggieRoutineReqeuest.getMyVeggieId()); + Routine newRoutine = Routine.createRoutine( + new Date(), + settingMyVeggieRoutineReqeuest.getContent(), + settingMyVeggieRoutineReqeuest.getPeriod(), + myVeggie, + settingMyVeggieRoutineReqeuest.isNotify() + ); + myVeggie.addRoutine(newRoutine); + } + + +} From 0c86a1ec953d24301cf33f50cff6748ed2a40667 Mon Sep 17 00:00:00 2001 From: seungryeol Date: Sat, 6 Apr 2024 17:02:51 +0900 Subject: [PATCH 08/12] =?UTF-8?q?[feat]=20=EB=82=B4=20=EC=B1=84=EC=86=8C?= =?UTF-8?q?=20=EC=8B=AC=ED=94=8C=20=EB=8D=B0=EC=9D=B4=ED=84=B0=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C=20API=20=EC=99=84=EB=A3=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/MyVeggieGardenController.java | 7 +++++- .../dto/response/SelectMyVeggieListDto.java | 15 +++++++++++ .../response/SelectMyVeggieListResponse.java | 18 +++++++++++++ .../repository/MyVeggieRepository.java | 17 ++++++++++++- .../service/MyVeggieGardenService.java | 25 ++++++++++++++++++- .../common/security/SecurityConfig.java | 4 ++- 6 files changed, 82 insertions(+), 4 deletions(-) create mode 100644 src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/dto/response/SelectMyVeggieListDto.java create mode 100644 src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/dto/response/SelectMyVeggieListResponse.java 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 f5f6af97..9d886d1a 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 @@ -25,12 +25,17 @@ public BaseResponseDto settingMyVeggi( @AuthenticationPrincipal CustomUser user, @Validated @RequestBody SettingMyVeggiRequest settingMyVeggi ){ - return myVeggieGardenService.settingMyVeggie( user.getUserId(), settingMyVeggi ); + } + @GetMapping(value = "/simple-list") + public BaseResponseDto selectMyVeggieList( + @AuthenticationPrincipal CustomUser user + ){ + return myVeggieGardenService.selectMyVeggieList(user.getUserId()); } 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 new file mode 100644 index 00000000..0d7a40ac --- /dev/null +++ b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/dto/response/SelectMyVeggieListDto.java @@ -0,0 +1,15 @@ +package com.modernfarmer.farmusspring.domain.myveggiegarden.dto.response; + + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@NoArgsConstructor +@AllArgsConstructor +@Getter +public class SelectMyVeggieListDto { + + public Long myVeggieId; + public String nickname; +} 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 new file mode 100644 index 00000000..22912cb0 --- /dev/null +++ b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/dto/response/SelectMyVeggieListResponse.java @@ -0,0 +1,18 @@ +package com.modernfarmer.farmusspring.domain.myveggiegarden.dto.response; + + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; + +import java.util.List; + +@NoArgsConstructor +@AllArgsConstructor(staticName = "of") +@Getter + +public class SelectMyVeggieListResponse { + + List simpleMyVeggieList; + +} 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 743d3a65..55e5445a 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,26 @@ import com.modernfarmer.farmusspring.domain.myveggiegarden.entity.MyVeggie; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; +import java.util.List; +import java.util.Optional; + @Repository public interface MyVeggieRepository extends JpaRepository { - MyVeggie findMyVeggieById(Long id); + Optional findById(Long id); + + + @Query("SELECT mv FROM my_veggie AS mv JOIN FETCH mv.user WHERE mv.user.id = :userId") + List findMyVeggieUserId(@Param("userId") Long userId); + + + + + + } 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 602236cf..2c0839fe 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,7 +1,8 @@ package com.modernfarmer.farmusspring.domain.myveggiegarden.service; import com.modernfarmer.farmusspring.domain.myveggiegarden.dto.request.SettingMyVeggiRequest; -import com.modernfarmer.farmusspring.domain.myveggiegarden.entity.Diary; +import com.modernfarmer.farmusspring.domain.myveggiegarden.dto.response.SelectMyVeggieListDto; +import com.modernfarmer.farmusspring.domain.myveggiegarden.dto.response.SelectMyVeggieListResponse; import com.modernfarmer.farmusspring.domain.myveggiegarden.entity.MyVeggie; import com.modernfarmer.farmusspring.domain.user.entity.User; import com.modernfarmer.farmusspring.global.response.BaseResponseDto; @@ -12,6 +13,9 @@ import org.springframework.transaction.annotation.Transactional; import com.modernfarmer.farmusspring.domain.myveggiegarden.repository.MyVeggieRepository; +import java.util.List; +import java.util.stream.Collectors; + @Slf4j @AllArgsConstructor @Service @@ -26,6 +30,25 @@ public BaseResponseDto settingMyVeggie(Long userId, SettingMyVeggiRequest return BaseResponseDto.of(SuccessCode.SUCCESS,null); } + @Transactional + public BaseResponseDto selectMyVeggieList(Long userId) { + List myVeggieList = bringMyVeggieData(userId); + List selectMyVeggieLists = processingSimpleMyVeggieData(myVeggieList); + return BaseResponseDto.of(SuccessCode.SUCCESS,SelectMyVeggieListResponse.of(selectMyVeggieLists)); + } + + 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()); + } + + + public MyVeggie getMyVeggie(Long userId){ return myVeggieRepository.findById(userId) .orElseThrow(() -> new IllegalArgumentException("채소가 존재하지 않습니다.")); 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 ce96f426..f0a403b9 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 @@ -58,7 +58,8 @@ public SecurityFilterChain filterChain(HttpSecurity http, HandlerMappingIntrospe "/api/veggie-info", "/api/veggie-info/**", "api/my-veggie", - "api/my-veggie/diary" + "api/my-veggie/diary", + "/api/my-veggie/simple-list" ).permitAll() ) .authorizeHttpRequests(request -> request.anyRequest().authenticated()); @@ -73,6 +74,7 @@ public WebSecurityCustomizer configure() { .requestMatchers("/api/auth/kakao-login") .requestMatchers("/api/auth/google-login") + .requestMatchers("/api/my-veggie/routine") ); } From 94fec055f995564dbf89d8099b6f2ef95533faa2 Mon Sep 17 00:00:00 2001 From: seungryeol Date: Sun, 7 Apr 2024 15:26:54 +0900 Subject: [PATCH 09/12] =?UTF-8?q?[feat]=201.=20=EB=A9=94=EC=9D=B8=ED=8C=A8?= =?UTF-8?q?=EC=9D=B4=EC=A7=80=20=EC=84=B1=EC=9E=A5=EC=9D=BC=EA=B8=B0=20?= =?UTF-8?q?=EC=A1=B0=ED=9A=8C=20API=20=EC=99=84=EB=A3=8C=20=20=20=20=20=20?= =?UTF-8?q?=20=202.=20=EB=82=B4=20=EC=B1=84=EC=86=8C=20=EC=9D=BC=EA=B8=B0?= =?UTF-8?q?=20=EC=B6=94=EA=B0=80=20=EC=97=AC=EB=B6=80=20=ED=99=95=EC=9D=B8?= =?UTF-8?q?=20API=20=EC=99=84=EB=A3=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/MyVeggieDiaryController.java | 20 ++++++ .../dto/response/CheckTodayDiaryResponse.java | 14 +++++ .../dto/response/SelectDiaryOneResponse.java | 17 +++++ .../exception/MyVeggieGardenErrorCode.java | 15 +++++ .../MyVeggieGardenExceptionHandler.java | 15 +++++ .../repository/MyVeggieRepository.java | 6 ++ .../service/MyVeggieDiaryService.java | 62 ++++++++++++++++++- .../common/security/SecurityConfig.java | 2 + 8 files changed, 150 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/dto/response/CheckTodayDiaryResponse.java create mode 100644 src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/dto/response/SelectDiaryOneResponse.java create mode 100644 src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/exception/MyVeggieGardenErrorCode.java create mode 100644 src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/exception/MyVeggieGardenExceptionHandler.java 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 519f2115..73bcb02b 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,5 +1,9 @@ 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.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; @@ -35,4 +39,20 @@ public BaseResponseDto settingMyVeggieDiary( myVeggieId ); } + + @GetMapping(value = "/{myVeggieId}/check") + public BaseResponseDto checkTodayDiary( + @PathVariable("myVeggieId") Long myVeggieId + ) { + return myVeggieDiaryService.checkTodayDiary(MyVeggie.builder().id(myVeggieId).build()); + } + + @GetMapping(value = "/{myVeggieId}/one") + public BaseResponseDto selectDiaryOne( + @PathVariable("myVeggieId") Long myVeggieId + ) { + return myVeggieDiaryService.selectDiaryOne(MyVeggie.builder().id(myVeggieId).build()); + } + + } diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/dto/response/CheckTodayDiaryResponse.java b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/dto/response/CheckTodayDiaryResponse.java new file mode 100644 index 00000000..824a0f91 --- /dev/null +++ b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/dto/response/CheckTodayDiaryResponse.java @@ -0,0 +1,14 @@ +package com.modernfarmer.farmusspring.domain.myveggiegarden.dto.response; + + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@NoArgsConstructor +@AllArgsConstructor(staticName = "of") +@Getter +public class CheckTodayDiaryResponse { + + private boolean state; +} diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/dto/response/SelectDiaryOneResponse.java b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/dto/response/SelectDiaryOneResponse.java new file mode 100644 index 00000000..76e09a28 --- /dev/null +++ b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/dto/response/SelectDiaryOneResponse.java @@ -0,0 +1,17 @@ +package com.modernfarmer.farmusspring.domain.myveggiegarden.dto.response; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; + +import java.util.Date; + +@NoArgsConstructor +@AllArgsConstructor(staticName = "of") +@Getter +public class SelectDiaryOneResponse { + + private String image; + private String content; + private String date; +} diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/exception/MyVeggieGardenErrorCode.java b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/exception/MyVeggieGardenErrorCode.java new file mode 100644 index 00000000..a248caa9 --- /dev/null +++ b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/exception/MyVeggieGardenErrorCode.java @@ -0,0 +1,15 @@ +package com.modernfarmer.farmusspring.domain.myveggiegarden.exception; + +import com.modernfarmer.farmusspring.global.response.ResponseCode; +import lombok.Getter; +import lombok.RequiredArgsConstructor; + +@Getter +@RequiredArgsConstructor +public enum MyVeggieGardenErrorCode implements ResponseCode { + + NOT_FOUND_DIARY(3000, "해당 일기가 존재하지 않습니다."); + + private final int code; + private final String message; +} diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/exception/MyVeggieGardenExceptionHandler.java b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/exception/MyVeggieGardenExceptionHandler.java new file mode 100644 index 00000000..4c9ea37f --- /dev/null +++ b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/exception/MyVeggieGardenExceptionHandler.java @@ -0,0 +1,15 @@ +package com.modernfarmer.farmusspring.domain.myveggiegarden.exception; + +import com.modernfarmer.farmusspring.domain.test.exception.TestException; +import com.modernfarmer.farmusspring.global.response.BaseResponseDto; +import jakarta.servlet.http.HttpServletRequest; +import lombok.extern.slf4j.Slf4j; +import org.springframework.web.bind.annotation.ExceptionHandler; +import org.springframework.web.bind.annotation.RestControllerAdvice; + +@Slf4j +@RestControllerAdvice(basePackages = "com.modernfarmer.farmusspring.domain.test") +public class MyVeggieGardenExceptionHandler { + + +} 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 55e5445a..be56c478 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 @@ -1,6 +1,7 @@ package com.modernfarmer.farmusspring.domain.myveggiegarden.repository; +import com.modernfarmer.farmusspring.domain.myveggiegarden.entity.Diary; import com.modernfarmer.farmusspring.domain.myveggiegarden.entity.MyVeggie; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; @@ -15,6 +16,11 @@ public interface MyVeggieRepository extends JpaRepository { Optional findById(Long id); + @Query("SELECT d FROM diary AS d WHERE d.myVeggie = :myVeggie ORDER BY d.createdDate DESC") + List findDiariesByMyVeggie(MyVeggie myVeggie); + + @Query("SELECT d FROM diary AS d WHERE d.myVeggie = :myVeggie AND FUNCTION('DATE', d.createdDate) = CURRENT_DATE ") + Diary findDiariesByMyVeggieAndToday(MyVeggie myVeggie); @Query("SELECT mv FROM my_veggie AS mv JOIN FETCH mv.user WHERE mv.user.id = :userId") List findMyVeggieUserId(@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 c5d2802c..dd1d2bf5 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,9 +1,12 @@ package com.modernfarmer.farmusspring.domain.myveggiegarden.service; +import com.modernfarmer.farmusspring.domain.myveggiegarden.dto.response.CheckTodayDiaryResponse; +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; import com.modernfarmer.farmusspring.domain.myveggiegarden.repository.MyVeggieRepository; import com.modernfarmer.farmusspring.global.response.BaseResponseDto; +import com.modernfarmer.farmusspring.domain.myveggiegarden.exception.MyVeggieGardenErrorCode; import com.modernfarmer.farmusspring.global.response.SuccessCode; import com.modernfarmer.farmusspring.infra.s3.S3Service; import lombok.AllArgsConstructor; @@ -11,8 +14,10 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.web.multipart.MultipartFile; - import java.io.IOException; +import java.time.format.DateTimeFormatter; +import java.util.List; + @Slf4j @AllArgsConstructor @@ -21,6 +26,7 @@ public class MyVeggieDiaryService { private final S3Service s3Service; private final MyVeggieGardenService myVeggieGardenService; + private final MyVeggieRepository myVeggieRepository; @Transactional public BaseResponseDto settingMyVeggieDiary( @@ -42,6 +48,60 @@ public BaseResponseDto settingMyVeggieDiary( return BaseResponseDto.of(SuccessCode.SUCCESS,null); } + + @Transactional + public BaseResponseDto checkTodayDiary( + MyVeggie myVeggie + ) { + + Diary diary = selectTodayDiary(myVeggie); + boolean state = verifyDiaryState(diary); + return BaseResponseDto.of(SuccessCode.SUCCESS,CheckTodayDiaryResponse.of(state)); + } + + @Transactional + public BaseResponseDto selectDiaryOne( + MyVeggie myVeggie + ) { + List diaryList = selectDiaryByMyVeggie(myVeggie); + if(checkNullDiaryList(diaryList)) { + return BaseResponseDto.of(MyVeggieGardenErrorCode.NOT_FOUND_DIARY, null); + } + return BaseResponseDto.of(SuccessCode.SUCCESS, + SelectDiaryOneResponse.of( + diaryList.get(0).getImage(), + diaryList.get(0).getContent(), + diaryList.get(0).getCreatedDate().format(DateTimeFormatter.ofPattern("yyyy-MM-dd")) + )); + } + + + + + public boolean verifyDiaryState(Diary diary){ + + if(diary == null){ + return true; + } + return false; + } + + public boolean checkNullDiaryList(List diaries){ + + if(diaries.isEmpty()){ + return true; + } + return false; + } + + public Diary selectTodayDiary(MyVeggie myVeggie){ + return myVeggieRepository.findDiariesByMyVeggieAndToday(myVeggie); + } + + public List selectDiaryByMyVeggie(MyVeggie myVeggie){ + return myVeggieRepository.findDiariesByMyVeggie(myVeggie); + } + private void addMyyVeggieDiary( String content, boolean isOpen, 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 f0a403b9..5e2fd934 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 @@ -75,6 +75,8 @@ public WebSecurityCustomizer configure() { .requestMatchers("/api/auth/kakao-login") .requestMatchers("/api/auth/google-login") .requestMatchers("/api/my-veggie/routine") + .requestMatchers("/api/my-veggie/diary/{myVeggieId}/one") + .requestMatchers("/api/my-veggie/diary/check") ); } From 7d94a30fc905f6dc5436c35bfab4ec6283d04efb Mon Sep 17 00:00:00 2001 From: seungryeol Date: Tue, 9 Apr 2024 01:11:21 +0900 Subject: [PATCH 10/12] =?UTF-8?q?[fix]=20=EC=98=A4=ED=83=80=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/MyVeggieGardenController.java | 6 +++--- ...ingMyVeggiRequest.java => SettingMyVeggieRequest.java} | 2 +- .../myveggiegarden/service/MyVeggieGardenService.java | 8 ++++---- .../myveggiegarden/service/MyVeggieRoutineService.java | 5 ----- 4 files changed, 8 insertions(+), 13 deletions(-) rename src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/dto/request/{SettingMyVeggiRequest.java => SettingMyVeggieRequest.java} (93%) 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 9d886d1a..e5660dd5 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,7 +2,7 @@ import com.modernfarmer.farmusspring.domain.auth.entity.CustomUser; -import com.modernfarmer.farmusspring.domain.myveggiegarden.dto.request.SettingMyVeggiRequest; +import com.modernfarmer.farmusspring.domain.myveggiegarden.dto.request.SettingMyVeggieRequest; import com.modernfarmer.farmusspring.domain.myveggiegarden.service.MyVeggieGardenService; import com.modernfarmer.farmusspring.global.response.BaseResponseDto; import lombok.RequiredArgsConstructor; @@ -21,9 +21,9 @@ public class MyVeggieGardenController { private final MyVeggieGardenService myVeggieGardenService; @PostMapping(value = "/") - public BaseResponseDto settingMyVeggi( + public BaseResponseDto settingMyVeggie( @AuthenticationPrincipal CustomUser user, - @Validated @RequestBody SettingMyVeggiRequest settingMyVeggi + @Validated @RequestBody SettingMyVeggieRequest settingMyVeggi ){ return myVeggieGardenService.settingMyVeggie( user.getUserId(), diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/dto/request/SettingMyVeggiRequest.java b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/dto/request/SettingMyVeggieRequest.java similarity index 93% rename from src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/dto/request/SettingMyVeggiRequest.java rename to src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/dto/request/SettingMyVeggieRequest.java index da3bc572..0d5b042d 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/dto/request/SettingMyVeggiRequest.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/dto/request/SettingMyVeggieRequest.java @@ -11,7 +11,7 @@ @Getter @AllArgsConstructor @NoArgsConstructor -public class SettingMyVeggiRequest { +public class SettingMyVeggieRequest { @NotNull(message = "null 값을 가지면 안됩니다.") private String nickname; 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 2c0839fe..3c4d7e01 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,6 +1,6 @@ package com.modernfarmer.farmusspring.domain.myveggiegarden.service; -import com.modernfarmer.farmusspring.domain.myveggiegarden.dto.request.SettingMyVeggiRequest; +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.entity.MyVeggie; @@ -24,9 +24,9 @@ public class MyVeggieGardenService { private final MyVeggieRepository myVeggieRepository; @Transactional - public BaseResponseDto settingMyVeggie(Long userId, SettingMyVeggiRequest settingMyVeggiRequest) { + public BaseResponseDto settingMyVeggie(Long userId, SettingMyVeggieRequest settingMyVeggieRequest) { - addMyyVeggie(userId, settingMyVeggiRequest); + addMyyVeggie(userId, settingMyVeggieRequest); return BaseResponseDto.of(SuccessCode.SUCCESS,null); } @@ -54,7 +54,7 @@ public MyVeggie getMyVeggie(Long userId){ .orElseThrow(() -> new IllegalArgumentException("채소가 존재하지 않습니다.")); } - private void addMyyVeggie(Long userId, SettingMyVeggiRequest settingMyVeggiRequest){ + private void addMyyVeggie(Long userId, SettingMyVeggieRequest settingMyVeggiRequest){ MyVeggie newMyVeggie = MyVeggie.createMyVegetable( settingMyVeggiRequest.getNickname(), 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 d888b50a..48d124fc 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,20 +1,15 @@ package com.modernfarmer.farmusspring.domain.myveggiegarden.service; -import com.modernfarmer.farmusspring.domain.myveggiegarden.dto.request.SettingMyVeggiRequest; import com.modernfarmer.farmusspring.domain.myveggiegarden.dto.request.SettingMyVeggieRoutineReqeuest; import com.modernfarmer.farmusspring.domain.myveggiegarden.entity.MyVeggie; import com.modernfarmer.farmusspring.domain.myveggiegarden.entity.Routine; -import com.modernfarmer.farmusspring.domain.user.entity.User; 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.mongodb.core.aggregation.ArithmeticOperators; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import org.springframework.web.multipart.MultipartFile; -import java.io.IOException; import java.util.Date; @Slf4j From 1d3b68ae1ef545adba6ba0eddb5300e08b51f102 Mon Sep 17 00:00:00 2001 From: seungryeol Date: Tue, 9 Apr 2024 01:21:46 +0900 Subject: [PATCH 11/12] =?UTF-8?q?[fix]=20successCode=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../exception/MyVeggieGardenErrorCode.java | 2 +- .../exception/MyVeggieGardenSuccessCode.java | 15 +++++++++++++++ .../service/MyVeggieDiaryService.java | 3 ++- 3 files changed, 18 insertions(+), 2 deletions(-) create mode 100644 src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/exception/MyVeggieGardenSuccessCode.java diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/exception/MyVeggieGardenErrorCode.java b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/exception/MyVeggieGardenErrorCode.java index a248caa9..15cc9ec0 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/exception/MyVeggieGardenErrorCode.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/exception/MyVeggieGardenErrorCode.java @@ -8,7 +8,7 @@ @RequiredArgsConstructor public enum MyVeggieGardenErrorCode implements ResponseCode { - NOT_FOUND_DIARY(3000, "해당 일기가 존재하지 않습니다."); + ; private final int code; private final String message; diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/exception/MyVeggieGardenSuccessCode.java b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/exception/MyVeggieGardenSuccessCode.java new file mode 100644 index 00000000..8222d2ab --- /dev/null +++ b/src/main/java/com/modernfarmer/farmusspring/domain/myveggiegarden/exception/MyVeggieGardenSuccessCode.java @@ -0,0 +1,15 @@ +package com.modernfarmer.farmusspring.domain.myveggiegarden.exception; + +import com.modernfarmer.farmusspring.global.response.ResponseCode; +import lombok.Getter; +import lombok.RequiredArgsConstructor; + +@Getter +@RequiredArgsConstructor +public enum MyVeggieGardenSuccessCode implements ResponseCode { + + + NOT_FOUND_DIARY(3000, "해당 일기가 존재하지 않습니다."); + private final int code; + private final String message; +} \ No newline at end of file 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 dd1d2bf5..29b0a6cd 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 @@ -4,6 +4,7 @@ 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; +import com.modernfarmer.farmusspring.domain.myveggiegarden.exception.MyVeggieGardenSuccessCode; import com.modernfarmer.farmusspring.domain.myveggiegarden.repository.MyVeggieRepository; import com.modernfarmer.farmusspring.global.response.BaseResponseDto; import com.modernfarmer.farmusspring.domain.myveggiegarden.exception.MyVeggieGardenErrorCode; @@ -65,7 +66,7 @@ public BaseResponseDto selectDiaryOne( ) { List diaryList = selectDiaryByMyVeggie(myVeggie); if(checkNullDiaryList(diaryList)) { - return BaseResponseDto.of(MyVeggieGardenErrorCode.NOT_FOUND_DIARY, null); + return BaseResponseDto.of(MyVeggieGardenSuccessCode.NOT_FOUND_DIARY, null); } return BaseResponseDto.of(SuccessCode.SUCCESS, SelectDiaryOneResponse.of( From 914b0b6c8dc82945bd2bd4b511a3446b5cacf279 Mon Sep 17 00:00:00 2001 From: seungryeol Date: Sat, 13 Apr 2024 11:51:27 +0900 Subject: [PATCH 12/12] =?UTF-8?q?[fix]=20successCode=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../myveggiegarden/service/MyVeggieDiaryService.java | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) 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 29b0a6cd..6eddef61 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 @@ -65,7 +65,7 @@ public BaseResponseDto selectDiaryOne( MyVeggie myVeggie ) { List diaryList = selectDiaryByMyVeggie(myVeggie); - if(checkNullDiaryList(diaryList)) { + if(diaryList.isEmpty()) { return BaseResponseDto.of(MyVeggieGardenSuccessCode.NOT_FOUND_DIARY, null); } return BaseResponseDto.of(SuccessCode.SUCCESS, @@ -78,7 +78,6 @@ public BaseResponseDto selectDiaryOne( - public boolean verifyDiaryState(Diary diary){ if(diary == null){ @@ -87,13 +86,6 @@ public boolean verifyDiaryState(Diary diary){ return false; } - public boolean checkNullDiaryList(List diaries){ - - if(diaries.isEmpty()){ - return true; - } - return false; - } public Diary selectTodayDiary(MyVeggie myVeggie){ return myVeggieRepository.findDiariesByMyVeggieAndToday(myVeggie);