Skip to content

Commit

Permalink
Merge pull request #44 from team-xquare/feature/40-delete-notice
Browse files Browse the repository at this point in the history
  • Loading branch information
jeongjiwoo0522 authored Jun 5, 2022
2 parents f5cde4e + e0a98e2 commit 3f1fae3
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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() {
Expand All @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand All @@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package app.xquare.dms.domain.notice.application.port.inbound;

public interface DeleteNoticeUseCase {

void deleteNotice(String id);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package app.xquare.dms.domain.notice.application.port.outbound;

public interface DeleteNoticeByIdPort {

void deleteNoticeById(String id);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package app.xquare.dms.domain.notice.application.port.outbound;

public interface ExistsByIdPort {

boolean existsById(String id);
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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() {
Expand Down Expand Up @@ -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);
}
}

0 comments on commit 3f1fae3

Please sign in to comment.