diff --git a/gg-admin-repo/src/main/java/gg/admin/repo/category/CategoryAdminRepository.java b/gg-admin-repo/src/main/java/gg/admin/repo/category/CategoryAdminRepository.java index dc06e48a0..7bd01c701 100644 --- a/gg-admin-repo/src/main/java/gg/admin/repo/category/CategoryAdminRepository.java +++ b/gg-admin-repo/src/main/java/gg/admin/repo/category/CategoryAdminRepository.java @@ -5,5 +5,5 @@ import gg.data.party.Category; public interface CategoryAdminRepository extends JpaRepository { - + Boolean existsByName(String categoryName); } diff --git a/gg-data/src/main/java/gg/data/party/Category.java b/gg-data/src/main/java/gg/data/party/Category.java index 1c4aa7467..30c4610ce 100644 --- a/gg-data/src/main/java/gg/data/party/Category.java +++ b/gg-data/src/main/java/gg/data/party/Category.java @@ -22,4 +22,7 @@ public class Category extends BaseTimeEntity { @Column(name = "name", length = 10) private String name; + public Category(String name) { + this.name = name; + } } diff --git a/gg-pingpong-api/src/main/java/gg/party/api/admin/category/controller/CategoryAdminController.java b/gg-pingpong-api/src/main/java/gg/party/api/admin/category/controller/CategoryAdminController.java index 83f637f4c..64145f78d 100644 --- a/gg-pingpong-api/src/main/java/gg/party/api/admin/category/controller/CategoryAdminController.java +++ b/gg-pingpong-api/src/main/java/gg/party/api/admin/category/controller/CategoryAdminController.java @@ -1,11 +1,15 @@ package gg.party.api.admin.category.controller; +import org.springframework.http.HttpStatus; 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.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +import gg.party.api.admin.category.controller.request.CategoryAddAdminReqDto; import gg.party.api.admin.category.service.CategoryAdminService; import lombok.RequiredArgsConstructor; @@ -22,6 +26,17 @@ public class CategoryAdminController { @DeleteMapping("{category_id}") public ResponseEntity categoryRemove(@PathVariable("category_id") Long categoryId) { categoryAdminService.removeCategory(categoryId); - return ResponseEntity.noContent().build(); + return ResponseEntity.status(HttpStatus.NO_CONTENT).build(); + } + + /** + * 카테고리 추가 + * @param reqDto 추가할 카테고리 이름 + * @return 추가 성공 여부 + */ + @PostMapping + public ResponseEntity categoryAdd(@RequestBody CategoryAddAdminReqDto reqDto) { + categoryAdminService.addCategory(reqDto); + return ResponseEntity.status(HttpStatus.CREATED).build(); } } diff --git a/gg-pingpong-api/src/main/java/gg/party/api/admin/category/controller/request/CategoryAddAdminReqDto.java b/gg-pingpong-api/src/main/java/gg/party/api/admin/category/controller/request/CategoryAddAdminReqDto.java new file mode 100644 index 000000000..e154c0f20 --- /dev/null +++ b/gg-pingpong-api/src/main/java/gg/party/api/admin/category/controller/request/CategoryAddAdminReqDto.java @@ -0,0 +1,10 @@ +package gg.party.api.admin.category.controller.request; + +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Getter +@NoArgsConstructor +public class CategoryAddAdminReqDto { + private String categoryName; +} diff --git a/gg-pingpong-api/src/main/java/gg/party/api/admin/category/service/CategoryAdminService.java b/gg-pingpong-api/src/main/java/gg/party/api/admin/category/service/CategoryAdminService.java index ba9063438..85f0dbbd0 100644 --- a/gg-pingpong-api/src/main/java/gg/party/api/admin/category/service/CategoryAdminService.java +++ b/gg-pingpong-api/src/main/java/gg/party/api/admin/category/service/CategoryAdminService.java @@ -6,6 +6,8 @@ import gg.admin.repo.category.CategoryAdminRepository; import gg.admin.repo.room.RoomAdminRepository; import gg.data.party.Category; +import gg.party.api.admin.category.controller.request.CategoryAddAdminReqDto; +import gg.utils.exception.party.CategoryDuplicateException; import gg.utils.exception.party.CategoryNotFoundException; import gg.utils.exception.party.DefaultCategoryNeedException; import lombok.RequiredArgsConstructor; @@ -40,4 +42,19 @@ public void removeCategory(Long categoryId) { categoryAdminRepository.deleteById(categoryId); } + + /** + * 카테고리 추가 + * @param reqDto 추가할 카테고리 이름 + * @exception CategoryDuplicateException 중복된 카테고리 + */ + @Transactional + public void addCategory(CategoryAddAdminReqDto reqDto) { + String categoryName = reqDto.getCategoryName(); + + if (categoryAdminRepository.existsByName(categoryName)) { + throw new CategoryDuplicateException(); + } + categoryAdminRepository.save(new Category(categoryName)); + } } 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 fc657ed07..94a6df4aa 100644 --- a/gg-utils/src/main/java/gg/utils/exception/ErrorCode.java +++ b/gg-utils/src/main/java/gg/utils/exception/ErrorCode.java @@ -166,6 +166,7 @@ public enum ErrorCode { ROOM_SAME_STATUS(400, "PT204", "이미 처리된 방 입니다."), ROOM_NOT_OPEN(400, "PT205", "모집중인 방이 아닙니다."), ROOM_NOT_PARTICIPANT(400, "PT206", "참여하지 않은 방 입니다."), + CATEGORY_DUPLICATE(400, "PT207", "중복된 카테고리 입니다."), USER_ALREADY_IN_ROOM(409, "PT301", "이미 참여한 방 입니다."), ALREADY_REPORTED_ROOM(409, "PT302", "이미 신고한 방 입니다."); diff --git a/gg-utils/src/main/java/gg/utils/exception/party/CategoryDuplicateException.java b/gg-utils/src/main/java/gg/utils/exception/party/CategoryDuplicateException.java new file mode 100644 index 000000000..a49264b20 --- /dev/null +++ b/gg-utils/src/main/java/gg/utils/exception/party/CategoryDuplicateException.java @@ -0,0 +1,10 @@ +package gg.utils.exception.party; + +import gg.utils.exception.ErrorCode; +import gg.utils.exception.custom.DuplicationException; + +public class CategoryDuplicateException extends DuplicationException { + public CategoryDuplicateException() { + super(ErrorCode.CATEGORY_DUPLICATE.getMessage(), ErrorCode.CATEGORY_DUPLICATE); + } +}