Skip to content

Commit

Permalink
[feat] 홈파밍 성공 api 개발
Browse files Browse the repository at this point in the history
  • Loading branch information
MinchoGreenT committed Aug 14, 2024
1 parent e4f02b3 commit 8175e5f
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.modernfarmer.farmusspring.domain.history.dto.req;

public record VeggieHistoryResultPostRequestDto(
String historyDetailId,
String content
) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -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);
}

}
Original file line number Diff line number Diff line change
@@ -1,24 +1,31 @@
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;
import com.modernfarmer.farmusspring.domain.veggieinfo.helper.VeggieInfoHelper;
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;

Expand All @@ -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;



Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 8175e5f

Please sign in to comment.