Skip to content

Commit

Permalink
[fix] 재배결과 생성 api 개발
Browse files Browse the repository at this point in the history
  • Loading branch information
MinchoGreenT committed Aug 14, 2024
1 parent c7410d1 commit e4f02b3
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -19,6 +24,7 @@
public class HistoryService {

private final HistoryHelper historyHelper;
private final S3Service s3Service;

public void createHistory(Long userId) {
historyHelper.createUserHistory(userId);
Expand Down Expand Up @@ -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());
}
}

0 comments on commit e4f02b3

Please sign in to comment.