diff --git a/src/main/java/org/gachon/checkmate/domain/post/dto/response/PostDetailResponseDto.java b/src/main/java/org/gachon/checkmate/domain/post/dto/response/PostDetailResponseDto.java index e61f37c..0569b69 100644 --- a/src/main/java/org/gachon/checkmate/domain/post/dto/response/PostDetailResponseDto.java +++ b/src/main/java/org/gachon/checkmate/domain/post/dto/response/PostDetailResponseDto.java @@ -7,6 +7,8 @@ @Builder public record PostDetailResponseDto( Long memberId, + String title, + String content, String name, String major, String profile, @@ -14,12 +16,16 @@ public record PostDetailResponseDto( String mbti, String roomType, String dormitoryType, + String importantKeyType, + String similarityKeyType, boolean isScrap, CheckListResponseDto checkList ) { public static PostDetailResponseDto of(PostDetailDto postDetailDto, CheckListResponseDto checkList, boolean isScrap) { return PostDetailResponseDto.builder() .memberId(postDetailDto.memberId()) + .title(postDetailDto.title()) + .content(postDetailDto.content()) .name(postDetailDto.name()) .major(postDetailDto.major()) .profile(postDetailDto.profile()) @@ -27,6 +33,8 @@ public static PostDetailResponseDto of(PostDetailDto postDetailDto, CheckListRes .roomType(postDetailDto.roomType().getDesc()) .dormitoryType(postDetailDto.dormitoryType().getDesc()) .mbti(postDetailDto.mbti().getDesc()) + .importantKeyType(postDetailDto.importantKeyType().getDesc()) + .similarityKeyType(postDetailDto.similarityKeyType().getDesc()) .isScrap(isScrap) .checkList(checkList) .build(); diff --git a/src/main/java/org/gachon/checkmate/domain/post/dto/support/PostDetailDto.java b/src/main/java/org/gachon/checkmate/domain/post/dto/support/PostDetailDto.java index 1603a20..2acec4b 100644 --- a/src/main/java/org/gachon/checkmate/domain/post/dto/support/PostDetailDto.java +++ b/src/main/java/org/gachon/checkmate/domain/post/dto/support/PostDetailDto.java @@ -6,10 +6,14 @@ import org.gachon.checkmate.domain.member.entity.MbtiType; import org.gachon.checkmate.domain.member.entity.ProfileImageType; import org.gachon.checkmate.domain.post.entity.DormitoryType; +import org.gachon.checkmate.domain.post.entity.ImportantKeyType; import org.gachon.checkmate.domain.post.entity.RoomType; +import org.gachon.checkmate.domain.post.entity.SimilarityKeyType; public record PostDetailDto( Long memberId, + String title, + String content, String major, MbtiType mbti, GenderType gender, @@ -17,11 +21,17 @@ public record PostDetailDto( DormitoryType dormitoryType, String name, String profile, + ImportantKeyType importantKeyType, + SimilarityKeyType similarityKeyType, PostCheckList postCheckList ) { @QueryProjection - public PostDetailDto(Long memberId, String major, MbtiType mbti, GenderType gender, RoomType roomType, DormitoryType dormitoryType, String name, String profile, PostCheckList postCheckList) { + public PostDetailDto(Long memberId, String title, String content, String major, MbtiType mbti, + GenderType gender, RoomType roomType, DormitoryType dormitoryType, String name, + String profile, ImportantKeyType importantKeyType, SimilarityKeyType similarityKeyType, PostCheckList postCheckList) { this.memberId = memberId; + this.title = title; + this.content = content; this.major = major; this.mbti = mbti; this.gender = gender; @@ -29,6 +39,8 @@ public PostDetailDto(Long memberId, String major, MbtiType mbti, GenderType gend this.dormitoryType = dormitoryType; this.name = name; this.profile = profile; + this.importantKeyType = importantKeyType; + this.similarityKeyType = similarityKeyType; this.postCheckList = postCheckList; } } diff --git a/src/main/java/org/gachon/checkmate/domain/post/repository/PostCustomRepositoryImpl.java b/src/main/java/org/gachon/checkmate/domain/post/repository/PostCustomRepositoryImpl.java index 14bfdf7..7d6f88f 100644 --- a/src/main/java/org/gachon/checkmate/domain/post/repository/PostCustomRepositoryImpl.java +++ b/src/main/java/org/gachon/checkmate/domain/post/repository/PostCustomRepositoryImpl.java @@ -30,6 +30,8 @@ public Optional findPostDetail(Long postId) { return Optional.ofNullable(queryFactory .select(new QPostDetailDto( user.id, + post.title, + post.content, user.major, user.mbtiType, user.gender, @@ -37,6 +39,8 @@ public Optional findPostDetail(Long postId) { post.dormitoryType, user.name, user.profile, + post.importantKeyType, + post.similarityKeyType, post.postCheckList )) .from(post) diff --git a/src/main/java/org/gachon/checkmate/domain/scrap/controller/ScrapController.java b/src/main/java/org/gachon/checkmate/domain/scrap/controller/ScrapController.java index b317418..b83d970 100644 --- a/src/main/java/org/gachon/checkmate/domain/scrap/controller/ScrapController.java +++ b/src/main/java/org/gachon/checkmate/domain/scrap/controller/ScrapController.java @@ -32,8 +32,8 @@ public ResponseEntity> createScrapPost(@UserId final Long use @DeleteMapping("/{id}") public ResponseEntity> deleteScrapPost(@UserId final Long userId, - @PathVariable("id") final Long scrapId) { - scrapService.deleteScrapPost(userId, scrapId); + @PathVariable("id") final Long postId) { + scrapService.deleteScrapPost(userId, postId); return SuccessResponse.ok(null); } } diff --git a/src/main/java/org/gachon/checkmate/domain/scrap/repository/ScrapRepository.java b/src/main/java/org/gachon/checkmate/domain/scrap/repository/ScrapRepository.java index f413ab9..e50670b 100644 --- a/src/main/java/org/gachon/checkmate/domain/scrap/repository/ScrapRepository.java +++ b/src/main/java/org/gachon/checkmate/domain/scrap/repository/ScrapRepository.java @@ -4,6 +4,6 @@ import org.springframework.data.jpa.repository.JpaRepository; public interface ScrapRepository extends JpaRepository, ScrapCustomRepository { - void deleteByIdAndUserId(Long scrapId, Long userId); + void deleteByPostIdAndUserId(Long postId, Long userId); boolean existsByPostIdAndUserId(Long postId, Long userId); } diff --git a/src/main/java/org/gachon/checkmate/domain/scrap/service/ScrapService.java b/src/main/java/org/gachon/checkmate/domain/scrap/service/ScrapService.java index b520a9c..fbaa8e8 100644 --- a/src/main/java/org/gachon/checkmate/domain/scrap/service/ScrapService.java +++ b/src/main/java/org/gachon/checkmate/domain/scrap/service/ScrapService.java @@ -14,7 +14,9 @@ import org.gachon.checkmate.domain.scrap.dto.support.ScrapSearchCondition; import org.gachon.checkmate.domain.scrap.entity.Scrap; import org.gachon.checkmate.domain.scrap.repository.ScrapRepository; +import org.gachon.checkmate.global.error.exception.ConflictException; import org.gachon.checkmate.global.error.exception.EntityNotFoundException; +import org.gachon.checkmate.global.error.exception.InvalidValueException; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Service; @@ -48,11 +50,13 @@ public PostSearchResponseDto getScrapPosts(Long userId, Pageable pageable) { public void creatScrapPost(Long userId, ScrapRequestDto scrapRequestDto) { User user = findUserOrThrow(userId); Post post = findPostOrThrow(scrapRequestDto.postId()); + validateDuplicateScrap(post.getId(), user.getId()); createScrapAndSave(user, post); } - public void deleteScrapPost(Long userId, Long scrapId) { - scrapRepository.deleteByIdAndUserId(scrapId, userId); + public void deleteScrapPost(Long userId, Long postId) { + validateExistScrap(postId, userId); + scrapRepository.deleteByPostIdAndUserId(postId, userId); } private List createPostSearchResponseDto(Page postSearchDtoList, CheckList checkList) { @@ -74,6 +78,20 @@ private void createScrapAndSave(User user, Post post) { scrapRepository.save(scrap); } + private void validateDuplicateScrap(Long postId, Long userId) { + if(existPostInScrap(postId, userId)) + throw new ConflictException(DUPLICATE_SCRAP); + } + + private void validateExistScrap(Long postId, Long userId) { + if(!existPostInScrap(postId, userId)) + throw new InvalidValueException(INVALID_DELETE_SCRAP); + } + + private boolean existPostInScrap(Long postId, Long userId) { + return scrapRepository.existsByPostIdAndUserId(postId, userId); + } + private CheckList getCheckList(Long userId) { return checkListRepository.findByUserId(userId) .orElseThrow(() -> new EntityNotFoundException(CHECK_LIST_NOT_FOUND)); diff --git a/src/main/java/org/gachon/checkmate/global/error/ErrorCode.java b/src/main/java/org/gachon/checkmate/global/error/ErrorCode.java index e41b40b..035e5d9 100644 --- a/src/main/java/org/gachon/checkmate/global/error/ErrorCode.java +++ b/src/main/java/org/gachon/checkmate/global/error/ErrorCode.java @@ -17,6 +17,7 @@ public enum ErrorCode { INVALID_PASSWORD(HttpStatus.BAD_REQUEST, "비밀번호는 8~20자 대소문자 영문, 숫자, 특수문자의 조합이어야 합니다."), INVALID_POST_TITLE(HttpStatus.BAD_REQUEST, "이미 존재하는 게시물입니다."), INVALID_POST_DATE(HttpStatus.BAD_REQUEST, "마감시간이 지난 게시물입니다."), + INVALID_DELETE_SCRAP(HttpStatus.BAD_REQUEST, "등록되지 않은 스크랩입니다."), /** * 401 Unauthorized @@ -59,6 +60,7 @@ public enum ErrorCode { */ CONFLICT(HttpStatus.CONFLICT, "이미 존재하는 리소스입니다."), DUPLICATE_EMAIL(HttpStatus.CONFLICT, "이미 가입된 이메일입니다."), + DUPLICATE_SCRAP(HttpStatus.CONFLICT, "이미 등록된 스크랩입니다."), DUPLICATE_CHECK_LIST(HttpStatus.CONFLICT, "체크리스트가 이미 존재합니다."), DUPLICATE_POST_REPORT(HttpStatus.CONFLICT, "이전에 신고했던 게시물입니다."), DUPLICATE_CHATROOM_REPORT(HttpStatus.CONFLICT, "이전에 신고했던 채팅방입니다."),