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 d584a4c7..042453e9 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 @@ -2,6 +2,8 @@ import com.modernfarmer.farmusspring.domain.auth.entity.CustomUser; import com.modernfarmer.farmusspring.domain.farmclub.dto.req.CreateFarmClubRequestDto; +import com.modernfarmer.farmusspring.domain.farmclub.dto.req.CreateMissionPostCommentRequestDto; +import com.modernfarmer.farmusspring.domain.farmclub.dto.req.CreateMissionPostLikeRequestDto; import com.modernfarmer.farmusspring.domain.farmclub.dto.req.CreateMissionPostRequestDto; import com.modernfarmer.farmusspring.domain.farmclub.helper.FarmClubHelper; import com.modernfarmer.farmusspring.domain.farmclub.service.FarmClubService; @@ -76,4 +78,39 @@ public BaseResponseDto createMissionPost( ) { return BaseResponseDto.of(SuccessCode.CREATED, missionPostService.createMissionPost(requestDto, image)); } + + @PostMapping("/mission/comment") + public BaseResponseDto createMissionPostComment( + @AuthenticationPrincipal CustomUser user, + @RequestBody CreateMissionPostCommentRequestDto requestDto + ) { + return BaseResponseDto.of(SuccessCode.CREATED, missionPostService.createMissionPostComment(user.getUserId(), requestDto)); + } + + @PostMapping("/mission/like") + public BaseResponseDto createMissionPostLike( + @AuthenticationPrincipal CustomUser user, + @RequestBody CreateMissionPostLikeRequestDto requestDto + ) { + return BaseResponseDto.of(SuccessCode.CREATED, missionPostService.createMissionPostLike(user.getUserId(), requestDto.missionPostId())); + } + + @GetMapping("/{id}/mission") + public BaseResponseDto getMissionPostList( + @PathVariable Long id + ) { + return BaseResponseDto.of(SuccessCode.SUCCESS, missionPostService.getMissionPostList(id)); + } + + @GetMapping("/mission/{id}") + public BaseResponseDto getMissionPostComments( + @PathVariable Long id + ) { + return BaseResponseDto.of(SuccessCode.SUCCESS, missionPostService.getMissionPostComment(id)); + } + + @GetMapping("/help") + public BaseResponseDto getFarmClubHelp() { + return null; + } } diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/dto/req/CreateMissionPostCommentRequestDto.java b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/dto/req/CreateMissionPostCommentRequestDto.java new file mode 100644 index 00000000..28ac1681 --- /dev/null +++ b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/dto/req/CreateMissionPostCommentRequestDto.java @@ -0,0 +1,7 @@ +package com.modernfarmer.farmusspring.domain.farmclub.dto.req; + +public record CreateMissionPostCommentRequestDto( + Long missionPostId, + String content +) { +} diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/dto/req/CreateMissionPostLikeRequestDto.java b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/dto/req/CreateMissionPostLikeRequestDto.java new file mode 100644 index 00000000..09f7b93c --- /dev/null +++ b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/dto/req/CreateMissionPostLikeRequestDto.java @@ -0,0 +1,7 @@ +package com.modernfarmer.farmusspring.domain.farmclub.dto.req; + +public record CreateMissionPostLikeRequestDto( + Long missionPostId, + Long userId +) { +} diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/dto/res/CreateMissionPostCommentResponseDto.java b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/dto/res/CreateMissionPostCommentResponseDto.java new file mode 100644 index 00000000..07d7163a --- /dev/null +++ b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/dto/res/CreateMissionPostCommentResponseDto.java @@ -0,0 +1,16 @@ +package com.modernfarmer.farmusspring.domain.farmclub.dto.res; + + +import lombok.Builder; + +@Builder +public record CreateMissionPostCommentResponseDto( + Long missionPostCommentId +) { + + public static CreateMissionPostCommentResponseDto of(Long missionPostCommentId) { + return CreateMissionPostCommentResponseDto.builder() + .missionPostCommentId(missionPostCommentId) + .build(); + } +} diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/dto/res/CreateMissionPostLikeResponseDto.java b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/dto/res/CreateMissionPostLikeResponseDto.java new file mode 100644 index 00000000..67742eb7 --- /dev/null +++ b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/dto/res/CreateMissionPostLikeResponseDto.java @@ -0,0 +1,15 @@ +package com.modernfarmer.farmusspring.domain.farmclub.dto.res; + +import lombok.Builder; + +@Builder +public record CreateMissionPostLikeResponseDto( + Long missionPostLikeId +) { + + public static CreateMissionPostLikeResponseDto of(Long missionPostLikeId) { + return CreateMissionPostLikeResponseDto.builder() + .missionPostLikeId(missionPostLikeId) + .build(); + } +} diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/dto/res/GetMissionPostCommentResponseDto.java b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/dto/res/GetMissionPostCommentResponseDto.java new file mode 100644 index 00000000..d09e4d15 --- /dev/null +++ b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/dto/res/GetMissionPostCommentResponseDto.java @@ -0,0 +1,17 @@ +package com.modernfarmer.farmusspring.domain.farmclub.dto.res; + +import com.modernfarmer.farmusspring.domain.farmclub.vo.MissionPostCommentVo; +import lombok.Builder; + +import java.util.List; + +@Builder +public record GetMissionPostCommentResponseDto( + List comments +) { + public static GetMissionPostCommentResponseDto of(List comments) { + return GetMissionPostCommentResponseDto.builder() + .comments(comments) + .build(); + } +} diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/dto/res/GetMissionPostListResponseDto.java b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/dto/res/GetMissionPostListResponseDto.java new file mode 100644 index 00000000..9221fa27 --- /dev/null +++ b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/dto/res/GetMissionPostListResponseDto.java @@ -0,0 +1,17 @@ +package com.modernfarmer.farmusspring.domain.farmclub.dto.res; + +import com.modernfarmer.farmusspring.domain.farmclub.vo.MissionPostVo; +import lombok.Builder; + +import java.util.List; + +@Builder +public record GetMissionPostListResponseDto( + List missionPosts +) { + public static GetMissionPostListResponseDto of(List missionPosts) { + return GetMissionPostListResponseDto.builder() + .missionPosts(missionPosts) + .build(); + } +} diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/exception/FarmClubErrorCode.java b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/exception/FarmClubErrorCode.java index c0189345..6780307b 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/exception/FarmClubErrorCode.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/exception/FarmClubErrorCode.java @@ -9,7 +9,8 @@ public enum FarmClubErrorCode implements ResponseCode { FARM_CLUB_NOT_FOUND(3001, "해당 팜클럽을 찾을 수 없습니다."), - USER_FARM_CLUB_NOT_FOUND(3002, "해당 등록 정보를 찾을 수 없습니다."); + USER_FARM_CLUB_NOT_FOUND(3002, "해당 등록 정보를 찾을 수 없습니다."), + MISSION_POST_NOT_FOUND(3003, "해당 미션 포스트를 찾을 수 없습니다."); private final int code; private final String message; diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/exception/FarmClubExceptionHandler.java b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/exception/FarmClubExceptionHandler.java index 21e4376a..967d04fd 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/exception/FarmClubExceptionHandler.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/exception/FarmClubExceptionHandler.java @@ -1,7 +1,7 @@ package com.modernfarmer.farmusspring.domain.farmclub.exception; import com.modernfarmer.farmusspring.domain.farmclub.exception.custom.FarmClubBaseException; -import com.modernfarmer.farmusspring.domain.farmclub.exception.custom.EntityNotFoundException; +import com.modernfarmer.farmusspring.domain.farmclub.exception.custom.FarmClubEntityNotFoundException; import com.modernfarmer.farmusspring.global.response.BaseResponseDto; import jakarta.servlet.http.HttpServletRequest; import lombok.extern.slf4j.Slf4j; @@ -13,7 +13,7 @@ public class FarmClubExceptionHandler { @ExceptionHandler(FarmClubBaseException.class) - public BaseResponseDto handleFarmClubNotFoundException(EntityNotFoundException e, HttpServletRequest request) { + public BaseResponseDto handleFarmClubNotFoundException(FarmClubEntityNotFoundException e, HttpServletRequest request) { log.error("FarmClubNotFoundException : {} {} errMessage={}\n", request.getMethod(), request.getRequestURI(), diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/exception/custom/EntityNotFoundException.java b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/exception/custom/FarmClubEntityNotFoundException.java similarity index 54% rename from src/main/java/com/modernfarmer/farmusspring/domain/farmclub/exception/custom/EntityNotFoundException.java rename to src/main/java/com/modernfarmer/farmusspring/domain/farmclub/exception/custom/FarmClubEntityNotFoundException.java index 9f21bdb8..8e88ebcd 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/exception/custom/EntityNotFoundException.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/exception/custom/FarmClubEntityNotFoundException.java @@ -2,9 +2,9 @@ import com.modernfarmer.farmusspring.domain.farmclub.exception.FarmClubErrorCode; -public class EntityNotFoundException extends FarmClubBaseException { +public class FarmClubEntityNotFoundException extends FarmClubBaseException { - public EntityNotFoundException(String message, FarmClubErrorCode errorCode) { + public FarmClubEntityNotFoundException(String message, FarmClubErrorCode errorCode) { super(message, errorCode); } } diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/helper/MissionPostHelper.java b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/helper/MissionPostHelper.java index 4e570e75..2e792e63 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/helper/MissionPostHelper.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/helper/MissionPostHelper.java @@ -1,9 +1,20 @@ package com.modernfarmer.farmusspring.domain.farmclub.helper; +import com.modernfarmer.farmusspring.domain.farmclub.entity.MissionPost; +import com.modernfarmer.farmusspring.domain.farmclub.exception.FarmClubErrorCode; +import com.modernfarmer.farmusspring.domain.farmclub.exception.custom.FarmClubEntityNotFoundException; +import com.modernfarmer.farmusspring.domain.farmclub.repository.MissionPostRepository; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Component; @Component @RequiredArgsConstructor public class MissionPostHelper { + + private final MissionPostRepository missionPostRepository; + + public MissionPost getMissionPost(Long missionPostId) { + return missionPostRepository.findById(missionPostId) + .orElseThrow(() -> new FarmClubEntityNotFoundException("존재하지 않는 미션 게시글입니다.", FarmClubErrorCode.MISSION_POST_NOT_FOUND)); + } } diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/helper/UserFarmClubHelper.java b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/helper/UserFarmClubHelper.java index b195297f..6d81badb 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/helper/UserFarmClubHelper.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/helper/UserFarmClubHelper.java @@ -2,7 +2,7 @@ import com.modernfarmer.farmusspring.domain.farmclub.entity.UserFarmClub; import com.modernfarmer.farmusspring.domain.farmclub.exception.FarmClubErrorCode; -import com.modernfarmer.farmusspring.domain.farmclub.exception.custom.EntityNotFoundException; +import com.modernfarmer.farmusspring.domain.farmclub.exception.custom.FarmClubEntityNotFoundException; import com.modernfarmer.farmusspring.domain.farmclub.repository.UserFarmClubRepository; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -17,6 +17,6 @@ public class UserFarmClubHelper { public UserFarmClub getUserFarmClubEntity(Long id) { return userFarmClubRepository.findById(id) - .orElseThrow(() -> new EntityNotFoundException("존재하지 않는 등록 정보입니다.", FarmClubErrorCode.USER_FARM_CLUB_NOT_FOUND)); + .orElseThrow(() -> new FarmClubEntityNotFoundException("존재하지 않는 등록 정보입니다.", FarmClubErrorCode.USER_FARM_CLUB_NOT_FOUND)); } } diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/repository/FarmClubRepositoryImpl.java b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/repository/FarmClubRepositoryImpl.java index 35c7e86d..1d75622a 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/repository/FarmClubRepositoryImpl.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/repository/FarmClubRepositoryImpl.java @@ -3,7 +3,7 @@ import com.modernfarmer.farmusspring.domain.farmclub.dto.res.*; import com.modernfarmer.farmusspring.domain.farmclub.entity.QFarmClub; import com.modernfarmer.farmusspring.domain.farmclub.exception.FarmClubErrorCode; -import com.modernfarmer.farmusspring.domain.farmclub.exception.custom.EntityNotFoundException; +import com.modernfarmer.farmusspring.domain.farmclub.exception.custom.FarmClubEntityNotFoundException; import com.modernfarmer.farmusspring.domain.farmclub.vo.GetMyFarmClubVo; import com.modernfarmer.farmusspring.domain.farmclub.vo.QGetMyFarmClubVo_BaseInfo; import com.querydsl.jpa.impl.JPAQueryFactory; @@ -75,7 +75,7 @@ public GetMyFarmClubVo findMyFarmClub(Long farmClubId, Long userId) { return GetMyFarmClubVo.of(baseInfo, userFarmClubCount, daySinceStart); } else { - throw new EntityNotFoundException("내 팜클럽을 불러오는 도중 에러가 발생했습니다.", FarmClubErrorCode.FARM_CLUB_NOT_FOUND); + throw new FarmClubEntityNotFoundException("내 팜클럽을 불러오는 도중 에러가 발생했습니다.", FarmClubErrorCode.FARM_CLUB_NOT_FOUND); } } diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/repository/MissionPostRepositoryCustom.java b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/repository/MissionPostRepositoryCustom.java index 864ecdf8..7d8dd526 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/repository/MissionPostRepositoryCustom.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/repository/MissionPostRepositoryCustom.java @@ -2,10 +2,14 @@ import com.modernfarmer.farmusspring.domain.farmclub.vo.GetMissionPostListWithStepCountsAndImagesVo; +import com.modernfarmer.farmusspring.domain.farmclub.vo.MissionPostCommentVo; +import com.modernfarmer.farmusspring.domain.farmclub.vo.MissionPostVo; import java.util.List; public interface MissionPostRepositoryCustom { List getMissionPostStepNumAndImage(Long farmClubId); + List getMissionPostComment(Long missionPostId); + List getMissionPostList(Long missionPostId); } diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/repository/MissionPostRepositoryImpl.java b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/repository/MissionPostRepositoryImpl.java index b126d63a..48e0bef0 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/repository/MissionPostRepositoryImpl.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/repository/MissionPostRepositoryImpl.java @@ -1,9 +1,9 @@ package com.modernfarmer.farmusspring.domain.farmclub.repository; -import com.modernfarmer.farmusspring.domain.farmclub.vo.GetMissionPostListWithStepCountsAndImagesVo; -import com.modernfarmer.farmusspring.domain.farmclub.vo.QGetMissionPostListWithStepCountsAndImagesVo; +import com.modernfarmer.farmusspring.domain.farmclub.vo.*; import com.querydsl.core.group.GroupBy; +import com.querydsl.jpa.JPAExpressions; import com.querydsl.jpa.impl.JPAQueryFactory; import jakarta.persistence.EntityManager; import jakarta.persistence.PersistenceContext; @@ -12,7 +12,11 @@ import static com.modernfarmer.farmusspring.domain.farmclub.entity.QFarmClub.farmClub; import static com.modernfarmer.farmusspring.domain.farmclub.entity.QMissionPost.missionPost; +import static com.modernfarmer.farmusspring.domain.farmclub.entity.QMissionPostComment.missionPostComment; +import static com.modernfarmer.farmusspring.domain.farmclub.entity.QMissionPostLike.missionPostLike; import static com.modernfarmer.farmusspring.domain.farmclub.entity.QUserFarmClub.userFarmClub; +import static com.modernfarmer.farmusspring.domain.myveggiegarden.entity.QMyVeggie.myVeggie; +import static com.modernfarmer.farmusspring.domain.user.entity.QUser.user; public class MissionPostRepositoryImpl implements MissionPostRepositoryCustom { @@ -36,4 +40,41 @@ public List getMissionPostStepNumAn )) ); } + + @Override + public List getMissionPostComment(Long missionPostId) { + JPAQueryFactory queryFactory = new JPAQueryFactory(em); + + return queryFactory + .select(new QMissionPostCommentVo(missionPost, user)) + .from(missionPost) + .join(missionPost.userFarmClub, userFarmClub) + .join(userFarmClub.myVeggie, myVeggie) + .join(myVeggie.user, user) + .where(missionPost.id.eq(missionPostId)) + .fetch(); + } + + @Override + public List getMissionPostList(Long farmClubId) { + JPAQueryFactory queryFactory = new JPAQueryFactory(em); + + return queryFactory + .select(new QMissionPostVo( + missionPost, + user, + JPAExpressions.select(missionPostLike.count()) + .from(missionPostLike) + .where(missionPostLike.missionPost.eq(missionPost)), + JPAExpressions.select(missionPostComment.count()) + .from(missionPostComment) + .where(missionPostComment.missionPost.eq(missionPost)))) + .from(missionPost) + .join(missionPost.userFarmClub, userFarmClub) + .join(userFarmClub.myVeggie, myVeggie) + .join(myVeggie.user, user) + .where(farmClub.id.eq(farmClubId)) + .orderBy(missionPost.createdDate.desc()) + .fetch(); + } } 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 029070fc..3fab60f4 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 @@ -1,17 +1,27 @@ package com.modernfarmer.farmusspring.domain.farmclub.service; +import com.modernfarmer.farmusspring.domain.farmclub.dto.req.CreateMissionPostCommentRequestDto; import com.modernfarmer.farmusspring.domain.farmclub.dto.req.CreateMissionPostRequestDto; -import com.modernfarmer.farmusspring.domain.farmclub.dto.res.CreateMissionPostResponseDto; +import com.modernfarmer.farmusspring.domain.farmclub.dto.res.*; import com.modernfarmer.farmusspring.domain.farmclub.entity.MissionPost; +import com.modernfarmer.farmusspring.domain.farmclub.entity.MissionPostComment; +import com.modernfarmer.farmusspring.domain.farmclub.entity.MissionPostLike; import com.modernfarmer.farmusspring.domain.farmclub.entity.UserFarmClub; +import com.modernfarmer.farmusspring.domain.farmclub.helper.MissionPostHelper; import com.modernfarmer.farmusspring.domain.farmclub.helper.UserFarmClubHelper; import com.modernfarmer.farmusspring.domain.farmclub.repository.MissionPostRepository; +import com.modernfarmer.farmusspring.domain.farmclub.vo.MissionPostCommentVo; +import com.modernfarmer.farmusspring.domain.farmclub.vo.MissionPostVo; +import com.modernfarmer.farmusspring.domain.user.entity.User; +import com.modernfarmer.farmusspring.domain.user.helper.UserHelper; import com.modernfarmer.farmusspring.infra.s3.S3Service; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; import org.springframework.web.multipart.MultipartFile; +import java.util.List; + @Service @Slf4j @RequiredArgsConstructor @@ -20,6 +30,8 @@ public class MissionPostService { private final MissionPostRepository missionPostRepository; private final UserFarmClubHelper userFarmClubHelper; + private final MissionPostHelper missionPostHelper; + private final UserHelper userHelper; private final S3Service s3Service; @@ -30,6 +42,30 @@ public CreateMissionPostResponseDto createMissionPost(CreateMissionPostRequestDt return CreateMissionPostResponseDto.of(missionPostId); } + public CreateMissionPostCommentResponseDto createMissionPostComment(Long userId, CreateMissionPostCommentRequestDto requestDto) { + MissionPost missionPost = missionPostHelper.getMissionPost(requestDto.missionPostId()); + User user = userHelper.getUserEntity(userId); + MissionPostComment.createMissionPostComment(requestDto.content(), missionPost, user); + return CreateMissionPostCommentResponseDto.of(missionPost.getId()); + } + + public CreateMissionPostLikeResponseDto createMissionPostLike(Long userId, Long missionPostId) { + MissionPost missionPost = missionPostHelper.getMissionPost(missionPostId); + User user = userHelper.getUserEntity(userId); + MissionPostLike.createMissionPostLike(missionPost, user); + return CreateMissionPostLikeResponseDto.of(missionPost.getId()); + } + + public GetMissionPostListResponseDto getMissionPostList(Long farmClubId) { + List missionPosts = missionPostRepository.getMissionPostList(farmClubId); + return GetMissionPostListResponseDto.of(missionPosts); + } + + public GetMissionPostCommentResponseDto getMissionPostComment(Long missionPostId) { + List comments = missionPostRepository.getMissionPostComment(missionPostId); + return GetMissionPostCommentResponseDto.of(comments); + } + private MissionPost saveMissionPost(MissionPost missionPost) { return missionPostRepository.save(missionPost); } diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/vo/MissionPostCommentVo.java b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/vo/MissionPostCommentVo.java new file mode 100644 index 00000000..111ff2ac --- /dev/null +++ b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/vo/MissionPostCommentVo.java @@ -0,0 +1,25 @@ +package com.modernfarmer.farmusspring.domain.farmclub.vo; + +import com.modernfarmer.farmusspring.domain.farmclub.entity.MissionPost; +import com.modernfarmer.farmusspring.domain.user.entity.User; +import com.querydsl.core.annotations.QueryProjection; + +public record MissionPostCommentVo( + Long missionPostCommentId, + String nickname, + String profileImage, + String date, + String content +) { + @QueryProjection + public MissionPostCommentVo(MissionPost missionPost, User user) + { + this( + missionPost.getId(), + user.getNickname(), + user.getProfileImage(), + missionPost.getCreatedDate().toString(), + missionPost.getContent() + ); + } +} diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/vo/MissionPostVo.java b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/vo/MissionPostVo.java new file mode 100644 index 00000000..d73d54e0 --- /dev/null +++ b/src/main/java/com/modernfarmer/farmusspring/domain/farmclub/vo/MissionPostVo.java @@ -0,0 +1,31 @@ +package com.modernfarmer.farmusspring.domain.farmclub.vo; + +import com.modernfarmer.farmusspring.domain.farmclub.entity.MissionPost; +import com.modernfarmer.farmusspring.domain.user.entity.User; +import com.querydsl.core.annotations.QueryProjection; + +public record MissionPostVo( + Long missionPostId, + String nickname, + String profileImage, + String date, + String image, + String content, + Long likeCount, + Long commentCount +) { + @QueryProjection + public MissionPostVo(MissionPost missionPost, User user, Long likeCount, Long commentCount) + { + this( + missionPost.getId(), + user.getNickname(), + user.getProfileImage(), + missionPost.getCreatedDate().toString(), + missionPost.getImage(), + missionPost.getContent(), + likeCount, + commentCount + ); + } +} diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/user/helper/UserHelper.java b/src/main/java/com/modernfarmer/farmusspring/domain/user/helper/UserHelper.java new file mode 100644 index 00000000..878fc28d --- /dev/null +++ b/src/main/java/com/modernfarmer/farmusspring/domain/user/helper/UserHelper.java @@ -0,0 +1,21 @@ +package com.modernfarmer.farmusspring.domain.user.helper; + +import com.modernfarmer.farmusspring.domain.user.entity.User; +import com.modernfarmer.farmusspring.domain.user.exception.UserNotFoundException; +import com.modernfarmer.farmusspring.domain.user.repository.UserRepository; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Component; + +@Slf4j +@Component +@RequiredArgsConstructor +public class UserHelper { + + private final UserRepository userRepository; + + public User getUserEntity(Long userId) { + return userRepository.findById(userId) + .orElseThrow(() -> new UserNotFoundException("해당 유저가 존재하지 않습니다.")); + } +}