From acba2dfbed39c52cc824645191fbd25fed12fb18 Mon Sep 17 00:00:00 2001 From: jungjkim Date: Thu, 7 Mar 2024 17:34:59 +0900 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20[Feature]=20=ED=83=AC=ED=94=8C?= =?UTF-8?q?=EB=A6=BF=20=EC=82=AD=EC=A0=9C=20API=20(#696)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/TemplateAdminController.java | 27 +++++++++++++++++++ .../service/TemplateAdminService.java | 25 +++++++++++++++++ .../java/gg/utils/exception/ErrorCode.java | 1 + .../party/TemplateNotFoundException.java | 10 +++++++ 4 files changed, 63 insertions(+) create mode 100644 gg-pingpong-api/src/main/java/gg/party/api/admin/templates/controller/TemplateAdminController.java create mode 100644 gg-pingpong-api/src/main/java/gg/party/api/admin/templates/service/TemplateAdminService.java create mode 100644 gg-utils/src/main/java/gg/utils/exception/party/TemplateNotFoundException.java diff --git a/gg-pingpong-api/src/main/java/gg/party/api/admin/templates/controller/TemplateAdminController.java b/gg-pingpong-api/src/main/java/gg/party/api/admin/templates/controller/TemplateAdminController.java new file mode 100644 index 000000000..c8f0ff767 --- /dev/null +++ b/gg-pingpong-api/src/main/java/gg/party/api/admin/templates/controller/TemplateAdminController.java @@ -0,0 +1,27 @@ +package gg.party.api.admin.templates.controller; + +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import gg.party.api.admin.templates.service.TemplateAdminService; +import lombok.RequiredArgsConstructor; + +@RestController +@RequiredArgsConstructor +@RequestMapping("/party/admin/templates") +public class TemplateAdminController { + private final TemplateAdminService templateAdminService; + + /** + * 템플릿 삭제 + * return 204 status code(성공적인 삭제 status) + */ + @DeleteMapping("/{templateId}") + public ResponseEntity removeTemplate(@PathVariable Long templateId) { + templateAdminService.removeTemplate(templateId); + return ResponseEntity.noContent().build(); + } +} diff --git a/gg-pingpong-api/src/main/java/gg/party/api/admin/templates/service/TemplateAdminService.java b/gg-pingpong-api/src/main/java/gg/party/api/admin/templates/service/TemplateAdminService.java new file mode 100644 index 000000000..2b7f21ad5 --- /dev/null +++ b/gg-pingpong-api/src/main/java/gg/party/api/admin/templates/service/TemplateAdminService.java @@ -0,0 +1,25 @@ +package gg.party.api.admin.templates.service; + +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import gg.repo.party.TemplateRepository; +import gg.utils.exception.party.TemplateNotFoundException; +import lombok.RequiredArgsConstructor; + +@Service +@RequiredArgsConstructor +public class TemplateAdminService { + private final TemplateRepository templateRepository; + + /** + * 템플릿 삭제 + */ + @Transactional + public void removeTemplate(Long templateId) { + if (!templateRepository.existsById(templateId)) { + throw new TemplateNotFoundException(); + } + templateRepository.deleteById(templateId); + } +} diff --git a/gg-utils/src/main/java/gg/utils/exception/ErrorCode.java b/gg-utils/src/main/java/gg/utils/exception/ErrorCode.java index 8d85c8248..a98c40253 100644 --- a/gg-utils/src/main/java/gg/utils/exception/ErrorCode.java +++ b/gg-utils/src/main/java/gg/utils/exception/ErrorCode.java @@ -159,6 +159,7 @@ public enum ErrorCode { ROOM_REPORTED_ERROR(404, "PT103", "신고 상태로 접근이 불가능합니다."), COMMENT_NOT_FOUND(404, "PT104", "존재하지 않는 댓글입니다."), ROOMSTAT_NOT_FOUND(404, "PT105", "존재하지 않는 방 status입니다."), + TEMPLATE_NOT_FOUND(404, "PT106", "존재하지 않는 템플릿 입니다."), ROOM_NOT_ENOUGH_PEOPLE(400, "PT201", "시작할 수 있는 인원이 아닙니다."), USER_NOT_HOST(400, "PT203", "방장이 아닙니다"), ROOM_SAME_STATUS(400, "PT204", "이미 처리된 방 입니다."), diff --git a/gg-utils/src/main/java/gg/utils/exception/party/TemplateNotFoundException.java b/gg-utils/src/main/java/gg/utils/exception/party/TemplateNotFoundException.java new file mode 100644 index 000000000..bb03289ad --- /dev/null +++ b/gg-utils/src/main/java/gg/utils/exception/party/TemplateNotFoundException.java @@ -0,0 +1,10 @@ +package gg.utils.exception.party; + +import gg.utils.exception.ErrorCode; +import gg.utils.exception.custom.NotExistException; + +public class TemplateNotFoundException extends NotExistException { + public TemplateNotFoundException() { + super(ErrorCode.TEMPLATE_NOT_FOUND.getMessage(), ErrorCode.TEMPLATE_NOT_FOUND); + } +}