diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/controller/FarmClubController.java b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/controller/FarmClubController.java index e673b2cc..958bedf9 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/controller/FarmClubController.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/controller/FarmClubController.java @@ -80,10 +80,11 @@ public BaseResponseDto getMyFarmClub( @PostMapping("/mission") public BaseResponseDto createMissionPost( + @AuthenticationPrincipal CustomUser user, @RequestPart CreateMissionPostRequestDto requestDto, @RequestPart(value = "image") MultipartFile image ) { - return BaseResponseDto.of(SuccessCode.CREATED, missionPostService.createMissionPost(requestDto, image)); + return BaseResponseDto.of(SuccessCode.CREATED, missionPostService.createMissionPost(user.getUserId(), requestDto, image)); } @PostMapping("/mission/comment") diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/dto/req/CreateMissionPostRequestDto.java b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/dto/req/CreateMissionPostRequestDto.java index 3447f961..8ab9bdc6 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/dto/req/CreateMissionPostRequestDto.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/dto/req/CreateMissionPostRequestDto.java @@ -5,12 +5,11 @@ public record CreateMissionPostRequestDto( // 사진, 내용, 스텝번호 - Long userFarmClubId, - String content, - Long stepNum + Long farmClubId, + String content ) { - public MissionPost toEntity(UserFarmClub userFarmClub, String imageUrl) { - return MissionPost.createMissionPost(this.content, this.stepNum, imageUrl, userFarmClub); + public MissionPost toEntity(UserFarmClub userFarmClub, String imageUrl, int stepNum) { + return MissionPost.createMissionPost(this.content, stepNum, imageUrl, userFarmClub); } } diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/entity/MissionPost.java b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/entity/MissionPost.java index fa0da170..07061178 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/entity/MissionPost.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/entity/MissionPost.java @@ -24,7 +24,7 @@ public class MissionPost extends BaseEntity { private String content; @Column(nullable = false) - private Long stepNum; + private int stepNum; @Column(nullable = false) private String image; @@ -41,7 +41,7 @@ public class MissionPost extends BaseEntity { @JoinColumn(name = "user_farm_club_id") private UserFarmClub userFarmClub; - public static MissionPost createMissionPost(String content, Long stepNum, String image, UserFarmClub userFarmClub){ + public static MissionPost createMissionPost(String content, int stepNum, String image, UserFarmClub userFarmClub){ MissionPost newMissionPost = MissionPost.builder() .content(content) .stepNum(stepNum) diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/service/MissionPostService.java b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/service/MissionPostService.java index e3ab53fe..effdb8ae 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/service/MissionPostService.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/service/MissionPostService.java @@ -36,10 +36,10 @@ public class MissionPostService { private final S3Service s3Service; @Transactional - public CreateMissionPostResponseDto createMissionPost(CreateMissionPostRequestDto request, MultipartFile image) { - UserFarmClub userFarmClub = userFarmClubHelper.getUserFarmClubEntity(request.userFarmClubId()); + public CreateMissionPostResponseDto createMissionPost(Long userId, CreateMissionPostRequestDto request, MultipartFile image) { + UserFarmClub userFarmClub = userFarmClubHelper.findByUserIdAndFarmClubId(userId, request.farmClubId()); String imageUrl = s3Service.uploadImage(image, "mission-post"); - MissionPost missionPost = saveMissionPost(request.toEntity(userFarmClub, imageUrl)); + MissionPost missionPost = saveMissionPost(request.toEntity(userFarmClub, imageUrl, userFarmClub.getCurrentStep())); userFarmClub.addMissionPost(missionPost); userFarmClub.updateStep(veggieInfoHelper.getStepName(userFarmClub.getFarmClub().getVeggieInfoId(), userFarmClub.getCurrentStep() + 1)); return CreateMissionPostResponseDto.of(missionPost.getId()); diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/history/vo/MissionPostHistoryVo.java b/src/main/java/com/modernfarmer/farmusspring/domain/history/vo/MissionPostHistoryVo.java index d1eb0a3f..27544325 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/history/vo/MissionPostHistoryVo.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/history/vo/MissionPostHistoryVo.java @@ -7,7 +7,7 @@ @Builder(access = AccessLevel.PRIVATE) public record MissionPostHistoryVo( - Long stepNum, + int stepNum, String image, String content, String date @@ -17,7 +17,7 @@ public record MissionPostHistoryVo( public MissionPostHistoryVo { } - public static MissionPostHistoryVo of(Long stepNum, String image, String content, String date) { + public static MissionPostHistoryVo of(int stepNum, String image, String content, String date) { return MissionPostHistoryVo.builder() .stepNum(stepNum) .image(image)