diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/history/controller/HistoryController.java b/src/main/java/com/modernfarmer/farmusspring/domain/history/controller/HistoryController.java index e645ad5b..987c886e 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/history/controller/HistoryController.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/history/controller/HistoryController.java @@ -1,6 +1,7 @@ package com.modernfarmer.farmusspring.domain.history.controller; import com.modernfarmer.farmusspring.domain.auth.entity.CustomUser; +import com.modernfarmer.farmusspring.domain.history.dto.req.VeggieHistoryResultPostRequestDto; import com.modernfarmer.farmusspring.domain.history.dto.res.*; import com.modernfarmer.farmusspring.domain.history.service.HistoryService; import com.modernfarmer.farmusspring.global.response.BaseResponseDto; @@ -12,6 +13,7 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.security.core.annotation.AuthenticationPrincipal; import org.springframework.web.bind.annotation.*; +import org.springframework.web.multipart.MultipartFile; @Slf4j @RestController @@ -77,4 +79,13 @@ public BaseResponseDto getVeggieHistoryDetail( ) { return BaseResponseDto.of(SuccessCode.SUCCESS, historyService.getVeggieHistoryDetail(detailId)); } + + @PostMapping("/veggie/result") + public BaseResponseDto postFarmResult( + @RequestPart("image") final MultipartFile image, + @RequestPart("requestDto") final VeggieHistoryResultPostRequestDto requestDto + ) { + historyService.createVeggieHistoryResult(requestDto, image); + return BaseResponseDto.of(SuccessCode.CREATED, null); + } } diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/history/service/HistoryService.java b/src/main/java/com/modernfarmer/farmusspring/domain/history/service/HistoryService.java index 44e4b6fd..7a1be0f8 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/history/service/HistoryService.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/history/service/HistoryService.java @@ -3,14 +3,19 @@ import com.modernfarmer.farmusspring.domain.history.document.History; import com.modernfarmer.farmusspring.domain.history.document.HistoryFarmClubDetail; import com.modernfarmer.farmusspring.domain.history.document.HistoryVeggieDetail; +import com.modernfarmer.farmusspring.domain.history.dto.req.VeggieHistoryResultPostRequestDto; import com.modernfarmer.farmusspring.domain.history.dto.res.*; import com.modernfarmer.farmusspring.domain.history.helper.HistoryHelper; import com.modernfarmer.farmusspring.domain.history.repository.HistoryRepository; +import com.modernfarmer.farmusspring.domain.myveggiegarden.util.DateManager; +import com.modernfarmer.farmusspring.infra.s3.S3Service; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.bson.types.ObjectId; import org.springframework.stereotype.Service; +import org.springframework.web.multipart.MultipartFile; +import java.time.LocalDateTime; import java.util.ArrayList; @Service @@ -19,6 +24,7 @@ public class HistoryService { private final HistoryHelper historyHelper; + private final S3Service s3Service; public void createHistory(Long userId) { historyHelper.createUserHistory(userId); @@ -53,4 +59,14 @@ public FarmClubHistoryListResponseDto getFarmClubHistories(Long userId) { History history = historyHelper.getUserHistory(userId); return FarmClubHistoryListResponseDto.of(history.getFarmClubHistoryDetails()); } + + public void createVeggieHistoryResult(VeggieHistoryResultPostRequestDto requestDto, MultipartFile image) { + 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.createVeggieHistoryResult(farmResult, requestDto.historyDetailId()); + } }