From 8175e5f30ee70e2b7570d75c22021ec8b2269e86 Mon Sep 17 00:00:00 2001 From: MinchoGreenT Date: Thu, 15 Aug 2024 00:11:57 +0900 Subject: [PATCH] =?UTF-8?q?[feat]=20=ED=99=88=ED=8C=8C=EB=B0=8D=20?= =?UTF-8?q?=EC=84=B1=EA=B3=B5=20api=20=EA=B0=9C=EB=B0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../VeggieHistoryResultPostRequestDto.java | 7 ++++++ .../controller/MyVeggieGardenController.java | 12 +++++++++- .../service/MyVeggieGardenService.java | 22 ++++++++++++++++++- 3 files changed, 39 insertions(+), 2 deletions(-) create mode 100644 src/main/java/com/modernfarmer/farmusspring/domain/history/dto/req/VeggieHistoryResultPostRequestDto.java diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/history/dto/req/VeggieHistoryResultPostRequestDto.java b/src/main/java/com/modernfarmer/farmusspring/domain/history/dto/req/VeggieHistoryResultPostRequestDto.java new file mode 100644 index 00000000..017103b7 --- /dev/null +++ b/src/main/java/com/modernfarmer/farmusspring/domain/history/dto/req/VeggieHistoryResultPostRequestDto.java @@ -0,0 +1,7 @@ +package com.modernfarmer.farmusspring.domain.history.dto.req; + +public record VeggieHistoryResultPostRequestDto( + String historyDetailId, + String content +) { +} 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 ccf09c58..dbeb7e6b 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 @@ -5,6 +5,7 @@ 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.request.SuccessFarmingRequestDto; 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; @@ -16,6 +17,7 @@ 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.util.List; @@ -77,6 +79,14 @@ public BaseResponseDto updateMyVeggie( return BaseResponseDto.of(SuccessCode.SUCCESS, null); } - + @PostMapping("/success") + public BaseResponseDto successFarming( + @RequestPart("requestDto") SuccessFarmingRequestDto requestDto, + @RequestPart("image") final MultipartFile image, + @AuthenticationPrincipal CustomUser user + ){ + myVeggieGardenService.successFarming(requestDto, image, user.getUserId()); + return BaseResponseDto.of(SuccessCode.SUCCESS, null); + } } 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 3d715c21..68a6ca06 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,10 +1,14 @@ package com.modernfarmer.farmusspring.domain.myveggiegarden.service; +import com.modernfarmer.farmusspring.domain.history.document.HistoryVeggieDetail; +import com.modernfarmer.farmusspring.domain.history.helper.HistoryHelper; 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.request.SuccessFarmingRequestDto; import com.modernfarmer.farmusspring.domain.myveggiegarden.dto.response.*; import com.modernfarmer.farmusspring.domain.myveggiegarden.entity.MyVeggie; +import com.modernfarmer.farmusspring.domain.myveggiegarden.helper.MyVeggieHelper; import com.modernfarmer.farmusspring.domain.myveggiegarden.util.DateManager; import com.modernfarmer.farmusspring.domain.user.entity.User; import com.modernfarmer.farmusspring.domain.veggieinfo.entity.VeggieInfo; @@ -12,13 +16,16 @@ import com.modernfarmer.farmusspring.domain.veggieinfo.vo.VeggieInfoVo; 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.time.LocalDateTime; import java.util.Date; import java.util.List; @@ -30,6 +37,9 @@ public class MyVeggieGardenService { private final MyVeggieRepository myVeggieRepository; private final MyDetailMyVeggieDto myDetailMyVeggieDto; private final VeggieInfoHelper veggieInfoHelper; + private final MyVeggieHelper myVeggieHelper; + private final HistoryHelper historyHelper; + private final S3Service s3Service; @@ -84,7 +94,17 @@ public void myVeggieUpdate(MyVeggieUpdate myVeggieUpdate) { myVeggieRepository.updateMyVeggie(myVeggieUpdate.getMyVeggieId(), myVeggieUpdate.getNickname(), myVeggieUpdate.getBirth()); } - + @Transactional + public void successFarming(SuccessFarmingRequestDto requestDto, MultipartFile image, Long userId) { + String imageUrl = s3Service.uploadImage(image, "farm-result"); + HistoryVeggieDetail.HistoryPost farmResult = HistoryVeggieDetail.HistoryPost.builder() + .postImage(imageUrl) + .content(requestDto.content()) + .dateTime(DateManager.parsingDotDateTime(LocalDateTime.now())) + .build(); + historyHelper.createVeggieHistoryDetail(userId, requestDto.myVeggieId(), farmResult); + myVeggieHelper.deleteMyVeggie(requestDto.myVeggieId()); + } public int checkFarmClubAffiliation(MyVeggie myVeggie){ if(myVeggie.getUserFarmClub() == null)