diff --git a/README.md b/README.md index ebc588b..6cd20d2 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,5 @@ # ❕ PICK!PLE -![픽플이미지](https://github.com/user-attachments/assets/7083d8e6-5ac2-4465-8706-b342feddb073) - +![image](https://github.com/user-attachments/assets/f21646ab-53bc-4fc3-8d3a-80df8f1ff2fb) 내가 PICK!한 바로 '그 사람'과 함께하는 클래스 모임 diff --git a/src/main/java/com/pickple/server/api/comment/controller/CommentController.java b/src/main/java/com/pickple/server/api/comment/controller/CommentController.java index 7813596..ff62f8c 100644 --- a/src/main/java/com/pickple/server/api/comment/controller/CommentController.java +++ b/src/main/java/com/pickple/server/api/comment/controller/CommentController.java @@ -10,6 +10,7 @@ import jakarta.validation.Valid; import java.util.List; import lombok.RequiredArgsConstructor; +import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; @@ -38,4 +39,12 @@ public ApiResponseDto> getCommentListByNotice(@PathVari return ApiResponseDto.success(SuccessCode.COMMENT_LIST_BY_NOTICE_GET_SUCCESS, commentQueryService.getCommentListByNotice(noticeId)); } + + @DeleteMapping("/v2/notice/{noticeId}/comment/{commentId}") + public ApiResponseDto deleteComment(@UserId Long userId, + @PathVariable final Long noticeId, + @PathVariable final Long commentId) { + commentCommandService.deleteComment(userId, noticeId, commentId); + return ApiResponseDto.success(SuccessCode.COMMENT_DELETE_SUCCESS); + } } diff --git a/src/main/java/com/pickple/server/api/comment/controller/CommentControllerDocs.java b/src/main/java/com/pickple/server/api/comment/controller/CommentControllerDocs.java index aa02749..4b2dfd5 100644 --- a/src/main/java/com/pickple/server/api/comment/controller/CommentControllerDocs.java +++ b/src/main/java/com/pickple/server/api/comment/controller/CommentControllerDocs.java @@ -44,4 +44,19 @@ ApiResponseDto createComment( ApiResponseDto> getCommentListByNotice( @PathVariable Long noticeId ); + + @Operation(summary = "공지사항 댓글 삭제") + @ApiResponses( + value = { + @ApiResponse(responseCode = "20036", description = "공지사항 댓글 삭제 성공"), + @ApiResponse(responseCode = "40409", description = "존재하지 않는 공지사항입니다."), + @ApiResponse(responseCode = "40410", description = "존재하지 않는 댓글입니다.") + } + ) + ApiResponseDto deleteComment( + @Parameter(schema = @Schema(implementation = String.class), in = ParameterIn.PATH) + @UserId Long userId, + @PathVariable final Long noticeId, + @PathVariable final Long commentId + ); } diff --git a/src/main/java/com/pickple/server/api/comment/repository/CommentRepository.java b/src/main/java/com/pickple/server/api/comment/repository/CommentRepository.java index 5f8b396..0190fc8 100644 --- a/src/main/java/com/pickple/server/api/comment/repository/CommentRepository.java +++ b/src/main/java/com/pickple/server/api/comment/repository/CommentRepository.java @@ -1,7 +1,10 @@ package com.pickple.server.api.comment.repository; import com.pickple.server.api.comment.domain.Comment; +import com.pickple.server.global.exception.CustomException; +import com.pickple.server.global.response.enums.ErrorCode; import java.util.List; +import java.util.Optional; import org.springframework.data.jpa.repository.JpaRepository; public interface CommentRepository extends JpaRepository { @@ -9,4 +12,11 @@ public interface CommentRepository extends JpaRepository { List findCommentsByNoticeId(Long noticeId); int countCommentByNoticeId(Long noticeId); + + Optional findCommentById(Long id); + + default Comment findCommentByIdOrThrow(Long id) { + return findCommentById(id) + .orElseThrow(() -> new CustomException(ErrorCode.COMMENT_NOT_FOUND)); + } } diff --git a/src/main/java/com/pickple/server/api/comment/service/CommentCommandService.java b/src/main/java/com/pickple/server/api/comment/service/CommentCommandService.java index 679652c..ef20653 100644 --- a/src/main/java/com/pickple/server/api/comment/service/CommentCommandService.java +++ b/src/main/java/com/pickple/server/api/comment/service/CommentCommandService.java @@ -7,6 +7,8 @@ import com.pickple.server.api.notice.repository.NoticeRepository; import com.pickple.server.api.user.domain.User; import com.pickple.server.api.user.repository.UserRepository; +import com.pickple.server.global.exception.CustomException; +import com.pickple.server.global.response.enums.ErrorCode; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -34,4 +36,15 @@ public void createComment(Long userId, commentRepository.save(comment); } + + public void deleteComment(Long userId, Long noticeId, Long commentId) { + Notice notice = noticeRepository.findNoticeByIdOrThrow(noticeId); + Comment comment = commentRepository.findCommentByIdOrThrow(commentId); + + if (comment.getCommenter().getId().equals(userId)) { + commentRepository.delete(comment); + } else { + throw new CustomException(ErrorCode.NOT_AUTHOR); + } + } } diff --git a/src/main/java/com/pickple/server/api/moim/service/MoimCommandService.java b/src/main/java/com/pickple/server/api/moim/service/MoimCommandService.java index b18281e..7b2cd13 100644 --- a/src/main/java/com/pickple/server/api/moim/service/MoimCommandService.java +++ b/src/main/java/com/pickple/server/api/moim/service/MoimCommandService.java @@ -7,9 +7,9 @@ import com.pickple.server.api.moim.dto.request.MoimCreateRequest; import com.pickple.server.api.moim.dto.response.MoimCreateResponse; import com.pickple.server.api.moim.repository.MoimRepository; +import com.pickple.server.global.util.DateUtil; import java.time.LocalDate; import java.time.LocalTime; -import java.time.format.DateTimeFormatter; import java.util.List; import lombok.RequiredArgsConstructor; import org.springframework.scheduling.annotation.Scheduled; @@ -47,11 +47,11 @@ public MoimCreateResponse createMoim(Long hostId, MoimCreateRequest request) { .build(); } - //1분마다 실행 - @Scheduled(cron = "0 0/1 * * * *", zone = "Asia/Seoul") + //정각마다 실행 + @Scheduled(cron = "0 0 0/1 * * *", zone = "Asia/Seoul") public void changeMoimStateOfDday() { LocalDate date = LocalDate.now(); - String formattedDate = date.format(DateTimeFormatter.ofPattern("yyyy.MM.dd")); + String formattedDate = DateUtil.refineDate(date); List moimList = moimRepository.findByDate(formattedDate); for (Moim moim : moimList) { diff --git a/src/main/java/com/pickple/server/api/review/Service/ReviewQueryService.java b/src/main/java/com/pickple/server/api/review/Service/ReviewQueryService.java index 3791255..df26ed9 100644 --- a/src/main/java/com/pickple/server/api/review/Service/ReviewQueryService.java +++ b/src/main/java/com/pickple/server/api/review/Service/ReviewQueryService.java @@ -1,11 +1,12 @@ package com.pickple.server.api.review.Service; -import com.pickple.server.api.review.domain.Review; import com.pickple.server.api.moim.domain.Moim; import com.pickple.server.api.moim.repository.MoimRepository; +import com.pickple.server.api.review.domain.Review; import com.pickple.server.api.review.domain.enums.HostTag; import com.pickple.server.api.review.domain.enums.MoimTag; import com.pickple.server.api.review.dto.response.ReviewListGetByHostResponse; +import com.pickple.server.api.review.dto.response.ReviewListGetByMoimResponse; import com.pickple.server.api.review.dto.response.TagListGetResponse; import com.pickple.server.api.review.repository.ReviewRepository; import com.pickple.server.global.util.DateTimeUtil; @@ -48,7 +49,7 @@ public List getReviewListByMoim(Long moimId) { .date(DateTimeUtil.refineDateAndTime(review.getCreatedAt())) .build()) .collect(Collectors.toList()); - } + } public List getReviewListByHost(Long hostId) { List moimList = moimRepository.findMoimByHostId(hostId); diff --git a/src/main/java/com/pickple/server/api/review/controller/ReviewController.java b/src/main/java/com/pickple/server/api/review/controller/ReviewController.java index cee9fcb..24ebe8a 100644 --- a/src/main/java/com/pickple/server/api/review/controller/ReviewController.java +++ b/src/main/java/com/pickple/server/api/review/controller/ReviewController.java @@ -3,6 +3,7 @@ import com.pickple.server.api.review.Service.ReviewCommandService; import com.pickple.server.api.review.Service.ReviewQueryService; import com.pickple.server.api.review.dto.request.ReviewCreateReqeust; +import com.pickple.server.api.review.dto.response.ReviewListGetByHostResponse; import com.pickple.server.api.review.dto.response.ReviewListGetByMoimResponse; import com.pickple.server.api.review.dto.response.TagListGetResponse; import com.pickple.server.global.common.annotation.GuestId; diff --git a/src/main/java/com/pickple/server/api/review/controller/ReviewControllerDocs.java b/src/main/java/com/pickple/server/api/review/controller/ReviewControllerDocs.java index 113b601..00aee5b 100644 --- a/src/main/java/com/pickple/server/api/review/controller/ReviewControllerDocs.java +++ b/src/main/java/com/pickple/server/api/review/controller/ReviewControllerDocs.java @@ -1,6 +1,7 @@ package com.pickple.server.api.review.controller; import com.pickple.server.api.review.dto.request.ReviewCreateReqeust; +import com.pickple.server.api.review.dto.response.ReviewListGetByHostResponse; import com.pickple.server.api.review.dto.response.ReviewListGetByMoimResponse; import com.pickple.server.api.review.dto.response.TagListGetResponse; import com.pickple.server.global.common.annotation.GuestId; @@ -48,7 +49,7 @@ ApiResponseDto createReview( @Operation(summary = "모임에 해당하는 리뷰 조회") @ApiResponses( value = { - @ApiResponse(responseCode = "20038", description = "모임에 해당하는 리뷰 조회 성공"), + @ApiResponse(responseCode = "20037", description = "모임에 해당하는 리뷰 조회 성공"), @ApiResponse(responseCode = "40404", description = "존재하지 않는 모임입니다.") } ) diff --git a/src/main/java/com/pickple/server/global/response/enums/ErrorCode.java b/src/main/java/com/pickple/server/global/response/enums/ErrorCode.java index e08ac98..ab468af 100644 --- a/src/main/java/com/pickple/server/global/response/enums/ErrorCode.java +++ b/src/main/java/com/pickple/server/global/response/enums/ErrorCode.java @@ -21,6 +21,7 @@ public enum ErrorCode { MISSING_IMAGE_URL(40009, HttpStatus.BAD_REQUEST, "필수 이미지가 없습니다."), DUPLICATION_REVIEW(40010, HttpStatus.BAD_REQUEST, "해당 사용자가 이미 작성한 리뷰가 존재합니다"), NO_SUBMISSION_FOUND_FOR_REVIEW(40011, HttpStatus.BAD_REQUEST, "리뷰를 작성할 수 있는 신청이 없습니다"), + NOT_AUTHOR(40012, HttpStatus.BAD_REQUEST, "해당 댓글의 작성자가 아닙니다."), // 401 Unauthorized ACCESS_TOKEN_EXPIRED(40100, HttpStatus.UNAUTHORIZED, "액세스 토큰이 만료되었습니다."), @@ -41,6 +42,7 @@ public enum ErrorCode { MOIM_SUBMISSION_NOT_FOUND(40406, HttpStatus.NOT_FOUND, "해당 모임에 신청한 내역이 없습니다."), SUBMITTER_NOT_FOUND(40408, HttpStatus.NOT_FOUND, "존재하지 않는 호스트 승인 신청입니다."), NOTICE_NOT_FOUND(40409, HttpStatus.NOT_FOUND, "존재하지 않는 공지사항입니다."), + COMMENT_NOT_FOUND(40410, HttpStatus.NOT_FOUND, "존재하지 않는 댓글입니다."), // 405 Method Not Allowed Error METHOD_NOT_ALLOWED(40500, HttpStatus.METHOD_NOT_ALLOWED, "지원하지 않는 메소드입니다."), diff --git a/src/main/java/com/pickple/server/global/response/enums/SuccessCode.java b/src/main/java/com/pickple/server/global/response/enums/SuccessCode.java index 9547443..dc77a60 100644 --- a/src/main/java/com/pickple/server/global/response/enums/SuccessCode.java +++ b/src/main/java/com/pickple/server/global/response/enums/SuccessCode.java @@ -45,6 +45,7 @@ public enum SuccessCode { MOIM_SUBMISSION_ALL_GET_SUCCESS(20033, HttpStatus.OK, "모임 참여 신청 전체 조회 성공"), GUEST_PROFILE_UPDATE_SUCCESS(20034, HttpStatus.OK, "게스트 프로필 수정 성공"), HOST_PROFILE_UPDATE_SUCCESS(20035, HttpStatus.OK, "호스트 프로필 수정 성공"), + COMMENT_DELETE_SUCCESS(20036, HttpStatus.OK, "공지사항 댓글 삭제 성공"), REVIEW_LIST_BY_MOIM_GET_SUCCESS(20037, HttpStatus.OK, "모임에 해당하는 리뷰 조회 성공"), REVIEW_LIST_BY_HOST_GET_SUCCESS(20038, HttpStatus.OK, "호스트에 해당하는 리뷰 전체 조회 성공"), diff --git a/src/main/java/com/pickple/server/global/util/DateUtil.java b/src/main/java/com/pickple/server/global/util/DateUtil.java index aba0cad..ee4e483 100644 --- a/src/main/java/com/pickple/server/global/util/DateUtil.java +++ b/src/main/java/com/pickple/server/global/util/DateUtil.java @@ -1,6 +1,7 @@ package com.pickple.server.global.util; import java.time.LocalDate; +import java.time.format.DateTimeFormatter; import java.time.temporal.ChronoUnit; public class DateUtil { @@ -16,4 +17,9 @@ public static int calculateCompletedDay(LocalDate date) { int day = (int) ChronoUnit.DAYS.between(today, date); return day; } + + public static String refineDate(LocalDate localDate) { + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy.MM.dd"); + return localDate.format(formatter); + } }