diff --git a/src/main/java/app/xquare/dms/domain/notice/adaptor/inbound/web/NoticeController.java b/src/main/java/app/xquare/dms/domain/notice/adaptor/inbound/web/NoticeController.java index 607de50..9267b89 100644 --- a/src/main/java/app/xquare/dms/domain/notice/adaptor/inbound/web/NoticeController.java +++ b/src/main/java/app/xquare/dms/domain/notice/adaptor/inbound/web/NoticeController.java @@ -1,6 +1,7 @@ package app.xquare.dms.domain.notice.adaptor.inbound.web; import app.xquare.dms.domain.notice.application.port.inbound.CreateNoticeUseCase; +import app.xquare.dms.domain.notice.application.port.inbound.DeleteNoticeUseCase; import app.xquare.dms.domain.notice.application.port.inbound.GetNoticeListUseCase; import app.xquare.dms.domain.notice.application.port.inbound.UpdateNoticeUseCase; import app.xquare.dms.domain.notice.application.port.inbound.dto.request.CreateNoticeRequest; @@ -20,6 +21,7 @@ public class NoticeController { private final GetNoticeListUseCase getNoticeListUseCase; private final CreateNoticeUseCase createNoticeUseCase; private final UpdateNoticeUseCase updateNoticeUseCase; + private final DeleteNoticeUseCase deleteNoticeUseCase; @GetMapping public NoticeListResponse noticeList() { @@ -36,4 +38,10 @@ public void notice(@Valid @RequestBody CreateNoticeRequest request) { public void notice(@Valid @RequestBody UpdateNoticeRequest request, @PathVariable("notice-id") String noticeId) { updateNoticeUseCase.updateNotice(request, noticeId); } + + @DeleteMapping("/{notice-id}") + @ResponseStatus(value = HttpStatus.NO_CONTENT) + public void notice(@PathVariable("notice-id") String noticeId) { + deleteNoticeUseCase.deleteNotice(noticeId); + } } diff --git a/src/main/java/app/xquare/dms/domain/notice/adaptor/outbound/persistence/dms/NoticePersistenceAdaptor.java b/src/main/java/app/xquare/dms/domain/notice/adaptor/outbound/persistence/dms/NoticePersistenceAdaptor.java index b5dc2a1..ffb0268 100644 --- a/src/main/java/app/xquare/dms/domain/notice/adaptor/outbound/persistence/dms/NoticePersistenceAdaptor.java +++ b/src/main/java/app/xquare/dms/domain/notice/adaptor/outbound/persistence/dms/NoticePersistenceAdaptor.java @@ -3,9 +3,7 @@ import app.xquare.dms.domain.notice.adaptor.outbound.persistence.dms.entity.NoticeJpaEntity; import app.xquare.dms.domain.notice.adaptor.outbound.persistence.dms.mapper.NoticeMapper; import app.xquare.dms.domain.notice.adaptor.outbound.persistence.dms.repository.NoticeRepository; -import app.xquare.dms.domain.notice.application.port.outbound.FindNoticeByIdPort; -import app.xquare.dms.domain.notice.application.port.outbound.FindNoticePort; -import app.xquare.dms.domain.notice.application.port.outbound.SaveNoticePort; +import app.xquare.dms.domain.notice.application.port.outbound.*; import app.xquare.dms.domain.notice.domain.Notice; import app.xquare.dms.domain.notice.exception.NoticeNotFoundException; import lombok.RequiredArgsConstructor; @@ -16,7 +14,7 @@ @RequiredArgsConstructor @Component -public class NoticePersistenceAdaptor implements FindNoticePort, SaveNoticePort, FindNoticeByIdPort { +public class NoticePersistenceAdaptor implements FindNoticePort, SaveNoticePort, FindNoticeByIdPort, DeleteNoticeByIdPort, ExistsByIdPort { private final NoticeRepository noticeRepository; @@ -43,4 +41,14 @@ public Notice findNoticeById(String id) { return noticeMapper.mapToNotice(notice); } + + @Override + public void deleteNoticeById(String id) { + noticeRepository.deleteById(id); + } + + @Override + public boolean existsById(String id) { + return noticeRepository.existsById(id); + } } diff --git a/src/main/java/app/xquare/dms/domain/notice/application/port/inbound/DeleteNoticeUseCase.java b/src/main/java/app/xquare/dms/domain/notice/application/port/inbound/DeleteNoticeUseCase.java new file mode 100644 index 0000000..bd8fae6 --- /dev/null +++ b/src/main/java/app/xquare/dms/domain/notice/application/port/inbound/DeleteNoticeUseCase.java @@ -0,0 +1,6 @@ +package app.xquare.dms.domain.notice.application.port.inbound; + +public interface DeleteNoticeUseCase { + + void deleteNotice(String id); +} diff --git a/src/main/java/app/xquare/dms/domain/notice/application/port/outbound/DeleteNoticeByIdPort.java b/src/main/java/app/xquare/dms/domain/notice/application/port/outbound/DeleteNoticeByIdPort.java new file mode 100644 index 0000000..b66ef83 --- /dev/null +++ b/src/main/java/app/xquare/dms/domain/notice/application/port/outbound/DeleteNoticeByIdPort.java @@ -0,0 +1,6 @@ +package app.xquare.dms.domain.notice.application.port.outbound; + +public interface DeleteNoticeByIdPort { + + void deleteNoticeById(String id); +} diff --git a/src/main/java/app/xquare/dms/domain/notice/application/port/outbound/ExistsByIdPort.java b/src/main/java/app/xquare/dms/domain/notice/application/port/outbound/ExistsByIdPort.java new file mode 100644 index 0000000..4a7f00f --- /dev/null +++ b/src/main/java/app/xquare/dms/domain/notice/application/port/outbound/ExistsByIdPort.java @@ -0,0 +1,6 @@ +package app.xquare.dms.domain.notice.application.port.outbound; + +public interface ExistsByIdPort { + + boolean existsById(String id); +} diff --git a/src/main/java/app/xquare/dms/domain/notice/application/service/NoticeService.java b/src/main/java/app/xquare/dms/domain/notice/application/service/NoticeService.java index 87ab709..5330d6e 100644 --- a/src/main/java/app/xquare/dms/domain/notice/application/service/NoticeService.java +++ b/src/main/java/app/xquare/dms/domain/notice/application/service/NoticeService.java @@ -1,15 +1,15 @@ package app.xquare.dms.domain.notice.application.service; import app.xquare.dms.domain.notice.application.port.inbound.CreateNoticeUseCase; +import app.xquare.dms.domain.notice.application.port.inbound.DeleteNoticeUseCase; import app.xquare.dms.domain.notice.application.port.inbound.GetNoticeListUseCase; import app.xquare.dms.domain.notice.application.port.inbound.UpdateNoticeUseCase; import app.xquare.dms.domain.notice.application.port.inbound.dto.request.CreateNoticeRequest; import app.xquare.dms.domain.notice.application.port.inbound.dto.request.UpdateNoticeRequest; import app.xquare.dms.domain.notice.application.port.inbound.dto.response.NoticeListResponse; -import app.xquare.dms.domain.notice.application.port.outbound.FindNoticeByIdPort; -import app.xquare.dms.domain.notice.application.port.outbound.FindNoticePort; -import app.xquare.dms.domain.notice.application.port.outbound.SaveNoticePort; +import app.xquare.dms.domain.notice.application.port.outbound.*; import app.xquare.dms.domain.notice.domain.Notice; +import app.xquare.dms.domain.notice.exception.NoticeNotFoundException; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -19,11 +19,13 @@ @RequiredArgsConstructor @Service -public class NoticeService implements GetNoticeListUseCase, CreateNoticeUseCase, UpdateNoticeUseCase { +public class NoticeService implements GetNoticeListUseCase, CreateNoticeUseCase, UpdateNoticeUseCase, DeleteNoticeUseCase { private final FindNoticePort findNoticePort; private final SaveNoticePort saveNoticePort; private final FindNoticeByIdPort findNoticeByIdPort; + private final DeleteNoticeByIdPort deleteNoticeByIdPort; + private final ExistsByIdPort existsByIdPort; @Override public NoticeListResponse getNoticeList() { @@ -55,4 +57,13 @@ public void updateNotice(UpdateNoticeRequest request, String id) { saveNoticePort.saveNotice(notice); } + + @Override + public void deleteNotice(String id) { + if(!existsByIdPort.existsById(id)) { + throw NoticeNotFoundException.EXCEPTION; + } + + deleteNoticeByIdPort.deleteNoticeById(id); + } }