diff --git a/src/main/java/com/pickple/server/api/notice/controller/NoticeController.java b/src/main/java/com/pickple/server/api/notice/controller/NoticeController.java index 28c8daa0..7d9faabf 100644 --- a/src/main/java/com/pickple/server/api/notice/controller/NoticeController.java +++ b/src/main/java/com/pickple/server/api/notice/controller/NoticeController.java @@ -4,11 +4,13 @@ import com.pickple.server.api.notice.dto.response.NoticeListGetByMoimResponse; import com.pickple.server.api.notice.service.NoticeCommandService; import com.pickple.server.api.notice.service.NoticeQueryService; +import com.pickple.server.global.common.annotation.HostId; import com.pickple.server.global.response.ApiResponseDto; import com.pickple.server.global.response.enums.SuccessCode; 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; @@ -36,4 +38,11 @@ public ApiResponseDto> getNoticeListByMoimId(@ return ApiResponseDto.success(SuccessCode.NOTICE_LIST_GET_SUCCESS, noticeQueryService.getNoticeListByMoimId(moimId)); } + + @DeleteMapping("/v2/notice/{noticeId}") + public ApiResponseDto deleteNotice(@HostId Long hostId, + @PathVariable Long noticeId) { + noticeCommandService.deleteNotice(hostId, noticeId); + return ApiResponseDto.success(SuccessCode.NOTICE_DELETE_SUCCESS); + } } diff --git a/src/main/java/com/pickple/server/api/notice/repository/NoticeRepository.java b/src/main/java/com/pickple/server/api/notice/repository/NoticeRepository.java index f9022f90..0e174fcd 100644 --- a/src/main/java/com/pickple/server/api/notice/repository/NoticeRepository.java +++ b/src/main/java/com/pickple/server/api/notice/repository/NoticeRepository.java @@ -1,10 +1,20 @@ package com.pickple.server.api.notice.repository; import com.pickple.server.api.notice.domain.Notice; +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 NoticeRepository extends JpaRepository { List findNoticeByMoimIdOrderByCreatedAtDesc(Long moimId); + + Optional findNoticeById(Long id); + + default Notice findNoticeByIdOrThrow(Long id) { + return findNoticeById(id) + .orElseThrow(() -> new CustomException(ErrorCode.NOTICE_NOT_FOUND)); + } } diff --git a/src/main/java/com/pickple/server/api/notice/service/NoticeCommandService.java b/src/main/java/com/pickple/server/api/notice/service/NoticeCommandService.java index 60708015..9ecc0270 100644 --- a/src/main/java/com/pickple/server/api/notice/service/NoticeCommandService.java +++ b/src/main/java/com/pickple/server/api/notice/service/NoticeCommandService.java @@ -5,6 +5,8 @@ import com.pickple.server.api.notice.domain.Notice; import com.pickple.server.api.notice.dto.request.NoticeCreateRequest; import com.pickple.server.api.notice.repository.NoticeRepository; +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; @@ -29,4 +31,12 @@ public void createNotice(Long moimId, NoticeCreateRequest request) { noticeRepository.save(notice); } + + public void deleteNotice(Long hostId, Long noticeId) { + Notice notice = noticeRepository.findNoticeByIdOrThrow(noticeId); + if (!hostId.equals(notice.getMoim().getHost().getId())) { + throw new CustomException(ErrorCode.NOT_HOST); + } + noticeRepository.delete(notice); + } } 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 2ac6129d..9917a1fa 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 @@ -27,6 +27,7 @@ public enum ErrorCode { //403 Forbidden NOT_ADMIN(40301, HttpStatus.UNAUTHORIZED, "관리자 계정이 아닙니다."), + NOT_HOST(40302, HttpStatus.FORBIDDEN, "해당 모임의 호스트가 아닙니다."), // 404 Not Found NOT_FOUND_END_POINT(40400, HttpStatus.NOT_FOUND, "존재하지 않는 API입니다."), @@ -37,6 +38,7 @@ public enum ErrorCode { HOST_NOT_FOUND(40405, HttpStatus.NOT_FOUND, "존재하지 않는 호스트입니다"), MOIM_SUBMISSION_NOT_FOUND(40406, HttpStatus.NOT_FOUND, "해당 모임에 신청한 내역이 없습니다."), SUBMITTER_NOT_FOUND(40408, HttpStatus.NOT_FOUND, "존재하지 않는 호스트 승인 신청입니다."), + NOTICE_NOT_FOUND(40409, 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 e0fdd94a..759a6a0d 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 @@ -35,6 +35,7 @@ public enum SuccessCode { MOIM_LIST_BY_HOST(20023, HttpStatus.OK, "호스트에 해당하는 모임 조회 성공"), SUBMITTER_LIST_GET_SUCCESS(20024, HttpStatus.OK, "호스트 승인 신청 내역 조회 성공"), HOST_SUBMITTER_APPROVE_SUCCESS(20025, HttpStatus.OK, "호스트 신청자 승인 성공"), + NOTICE_DELETE_SUCCESS(20026, HttpStatus.OK, "공지사항 삭제 성공"), // 201 Created MOIM_CREATE_SUCCESS(20100, HttpStatus.CREATED, "모임 개설 성공");