From 80c04c2ae48dd44459c92ebadaea829c5da637d3 Mon Sep 17 00:00:00 2001 From: mixedtape <54096846+mixedtape@users.noreply.github.com> Date: Fri, 26 Jan 2024 13:57:21 +0900 Subject: [PATCH 1/3] =?UTF-8?q?fix:=20hive=20=EA=B8=B0=EB=8A=A5=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../HHive/hhive/domain/category/data/MajorCategory.java | 6 ++++++ .../com/HHive/hhive/domain/category/data/SubCategory.java | 6 ++++++ .../HHive/hhive/domain/hive/controller/HiveController.java | 2 ++ .../HHive/hhive/domain/hive/dto/CreateHiveRequestDTO.java | 6 +++--- .../com/HHive/hhive/domain/hive/dto/HiveResponseDTO.java | 4 ++-- .../com/HHive/hhive/domain/hive/service/HiveService.java | 7 ++++++- 6 files changed, 25 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/HHive/hhive/domain/category/data/MajorCategory.java b/src/main/java/com/HHive/hhive/domain/category/data/MajorCategory.java index 729da29..7143f02 100644 --- a/src/main/java/com/HHive/hhive/domain/category/data/MajorCategory.java +++ b/src/main/java/com/HHive/hhive/domain/category/data/MajorCategory.java @@ -20,4 +20,10 @@ public String getTitle() { public static MajorCategory findByStringName(String categoryName) { return Arrays.stream(MajorCategory.values()).filter(majorCategory -> majorCategory.name().equals(categoryName)).findFirst().orElse(null); } + public static MajorCategory findByTitle(String title) { + return Arrays.stream(MajorCategory.values()) + .filter(majorCategory -> majorCategory.title.equals(title)) + .findFirst() + .orElse(null); + } } diff --git a/src/main/java/com/HHive/hhive/domain/category/data/SubCategory.java b/src/main/java/com/HHive/hhive/domain/category/data/SubCategory.java index d53f0e2..af9d531 100644 --- a/src/main/java/com/HHive/hhive/domain/category/data/SubCategory.java +++ b/src/main/java/com/HHive/hhive/domain/category/data/SubCategory.java @@ -35,4 +35,10 @@ public String getTitle() { public static SubCategory findByStringName(String categoryName) { return Arrays.stream(SubCategory.values()).filter(subCategory -> subCategory.name().equals(categoryName)).findFirst().orElse(null); } + public static SubCategory findByTitle(String title) { + return Arrays.stream(SubCategory.values()) + .filter(subCategory -> subCategory.title.equals(title)) + .findFirst() + .orElse(null); + } } diff --git a/src/main/java/com/HHive/hhive/domain/hive/controller/HiveController.java b/src/main/java/com/HHive/hhive/domain/hive/controller/HiveController.java index c496e90..3e04707 100644 --- a/src/main/java/com/HHive/hhive/domain/hive/controller/HiveController.java +++ b/src/main/java/com/HHive/hhive/domain/hive/controller/HiveController.java @@ -39,6 +39,8 @@ public class HiveController { public ResponseEntity> createHive( @AuthenticationPrincipal UserDetailsImpl userDetails, @RequestBody @Valid CreateHiveRequestDTO createHiveRequestDTO) { + + SubCategory.findByStringName(createHiveRequestDTO.getSubCategoryName()); HiveResponseDTO response = hiveService.createHive(userDetails.getUser(), createHiveRequestDTO); return ResponseEntity.ok() diff --git a/src/main/java/com/HHive/hhive/domain/hive/dto/CreateHiveRequestDTO.java b/src/main/java/com/HHive/hhive/domain/hive/dto/CreateHiveRequestDTO.java index 4f6480e..506fa91 100644 --- a/src/main/java/com/HHive/hhive/domain/hive/dto/CreateHiveRequestDTO.java +++ b/src/main/java/com/HHive/hhive/domain/hive/dto/CreateHiveRequestDTO.java @@ -19,11 +19,11 @@ public class CreateHiveRequestDTO { @NotBlank private String title; - private MajorCategory majorCategory; + private String majorCategoryName; - private SubCategory subCategory; + private String subCategoryName; - public Hive toEntity(User createdBy) { + public Hive toEntity(User createdBy,MajorCategory majorCategory,SubCategory subCategory) { return Hive.builder() .title(title) .majorCategory(majorCategory) diff --git a/src/main/java/com/HHive/hhive/domain/hive/dto/HiveResponseDTO.java b/src/main/java/com/HHive/hhive/domain/hive/dto/HiveResponseDTO.java index 8efde3f..68c064b 100644 --- a/src/main/java/com/HHive/hhive/domain/hive/dto/HiveResponseDTO.java +++ b/src/main/java/com/HHive/hhive/domain/hive/dto/HiveResponseDTO.java @@ -48,8 +48,8 @@ public static HiveResponseDTO of(Hive hive) { .majorCategory(majorName) .subCategory(subName) .introduction(hive.getIntroduction()) - .hostId(hive.getId()) - .hostName(hive.getUser().getEmail()) + .hostId(hive.getCreatorId()) + .hostName(hive.getUser().getUsername()) .createdAt(hive.getCreatedAt()) .modifiedAt(hive.getModifiedAt()) .build(); diff --git a/src/main/java/com/HHive/hhive/domain/hive/service/HiveService.java b/src/main/java/com/HHive/hhive/domain/hive/service/HiveService.java index 92abf56..8c44c7e 100644 --- a/src/main/java/com/HHive/hhive/domain/hive/service/HiveService.java +++ b/src/main/java/com/HHive/hhive/domain/hive/service/HiveService.java @@ -40,7 +40,9 @@ public HiveResponseDTO createHive(User user, CreateHiveRequestDTO createHiveRequ if (hiveRepository.findByTitle(createHiveRequestDTO.getTitle()).isPresent()) { throw new AlreadyExistHiveException(); } - Hive saveHive = hiveRepository.save(createHiveRequestDTO.toEntity(createBy)); + Hive saveHive = hiveRepository.save(createHiveRequestDTO.toEntity(createBy + ,MajorCategory.findByTitle(createHiveRequestDTO.getMajorCategoryName()) + ,SubCategory.findByTitle(createHiveRequestDTO.getSubCategoryName()))); hiveUserService.saveHiveUser(saveHive, createBy); return HiveResponseDTO.of(saveHive); @@ -51,6 +53,9 @@ public HiveResponseDTO createHive(User user, CreateHiveRequestDTO createHiveRequ public HiveResponseDTO updateHive(User user, Long hiveId, @Valid UpdateHiveRequestDTO updateHiveRequest) { Hive hive = getHiveAndCheckAuth(user, hiveId); + if (hiveRepository.findByTitle(updateHiveRequest.getTitle()).isPresent()) { + throw new AlreadyExistHiveException(); + } hive.update(updateHiveRequest); return HiveResponseDTO.of(hive); From 8c3959026068b623e9609e3a60d140a60c661318 Mon Sep 17 00:00:00 2001 From: mixedtape <54096846+mixedtape@users.noreply.github.com> Date: Fri, 26 Jan 2024 14:01:41 +0900 Subject: [PATCH 2/3] =?UTF-8?q?Revert=20"fix:=20hive=20=EA=B8=B0=EB=8A=A5?= =?UTF-8?q?=EC=88=98=EC=A0=95"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 80c04c2ae48dd44459c92ebadaea829c5da637d3. --- .../HHive/hhive/domain/category/data/MajorCategory.java | 6 ------ .../com/HHive/hhive/domain/category/data/SubCategory.java | 6 ------ .../HHive/hhive/domain/hive/controller/HiveController.java | 2 -- .../HHive/hhive/domain/hive/dto/CreateHiveRequestDTO.java | 6 +++--- .../com/HHive/hhive/domain/hive/dto/HiveResponseDTO.java | 4 ++-- .../com/HHive/hhive/domain/hive/service/HiveService.java | 7 +------ 6 files changed, 6 insertions(+), 25 deletions(-) diff --git a/src/main/java/com/HHive/hhive/domain/category/data/MajorCategory.java b/src/main/java/com/HHive/hhive/domain/category/data/MajorCategory.java index 7143f02..729da29 100644 --- a/src/main/java/com/HHive/hhive/domain/category/data/MajorCategory.java +++ b/src/main/java/com/HHive/hhive/domain/category/data/MajorCategory.java @@ -20,10 +20,4 @@ public String getTitle() { public static MajorCategory findByStringName(String categoryName) { return Arrays.stream(MajorCategory.values()).filter(majorCategory -> majorCategory.name().equals(categoryName)).findFirst().orElse(null); } - public static MajorCategory findByTitle(String title) { - return Arrays.stream(MajorCategory.values()) - .filter(majorCategory -> majorCategory.title.equals(title)) - .findFirst() - .orElse(null); - } } diff --git a/src/main/java/com/HHive/hhive/domain/category/data/SubCategory.java b/src/main/java/com/HHive/hhive/domain/category/data/SubCategory.java index af9d531..d53f0e2 100644 --- a/src/main/java/com/HHive/hhive/domain/category/data/SubCategory.java +++ b/src/main/java/com/HHive/hhive/domain/category/data/SubCategory.java @@ -35,10 +35,4 @@ public String getTitle() { public static SubCategory findByStringName(String categoryName) { return Arrays.stream(SubCategory.values()).filter(subCategory -> subCategory.name().equals(categoryName)).findFirst().orElse(null); } - public static SubCategory findByTitle(String title) { - return Arrays.stream(SubCategory.values()) - .filter(subCategory -> subCategory.title.equals(title)) - .findFirst() - .orElse(null); - } } diff --git a/src/main/java/com/HHive/hhive/domain/hive/controller/HiveController.java b/src/main/java/com/HHive/hhive/domain/hive/controller/HiveController.java index 3e04707..c496e90 100644 --- a/src/main/java/com/HHive/hhive/domain/hive/controller/HiveController.java +++ b/src/main/java/com/HHive/hhive/domain/hive/controller/HiveController.java @@ -39,8 +39,6 @@ public class HiveController { public ResponseEntity> createHive( @AuthenticationPrincipal UserDetailsImpl userDetails, @RequestBody @Valid CreateHiveRequestDTO createHiveRequestDTO) { - - SubCategory.findByStringName(createHiveRequestDTO.getSubCategoryName()); HiveResponseDTO response = hiveService.createHive(userDetails.getUser(), createHiveRequestDTO); return ResponseEntity.ok() diff --git a/src/main/java/com/HHive/hhive/domain/hive/dto/CreateHiveRequestDTO.java b/src/main/java/com/HHive/hhive/domain/hive/dto/CreateHiveRequestDTO.java index 506fa91..4f6480e 100644 --- a/src/main/java/com/HHive/hhive/domain/hive/dto/CreateHiveRequestDTO.java +++ b/src/main/java/com/HHive/hhive/domain/hive/dto/CreateHiveRequestDTO.java @@ -19,11 +19,11 @@ public class CreateHiveRequestDTO { @NotBlank private String title; - private String majorCategoryName; + private MajorCategory majorCategory; - private String subCategoryName; + private SubCategory subCategory; - public Hive toEntity(User createdBy,MajorCategory majorCategory,SubCategory subCategory) { + public Hive toEntity(User createdBy) { return Hive.builder() .title(title) .majorCategory(majorCategory) diff --git a/src/main/java/com/HHive/hhive/domain/hive/dto/HiveResponseDTO.java b/src/main/java/com/HHive/hhive/domain/hive/dto/HiveResponseDTO.java index 68c064b..8efde3f 100644 --- a/src/main/java/com/HHive/hhive/domain/hive/dto/HiveResponseDTO.java +++ b/src/main/java/com/HHive/hhive/domain/hive/dto/HiveResponseDTO.java @@ -48,8 +48,8 @@ public static HiveResponseDTO of(Hive hive) { .majorCategory(majorName) .subCategory(subName) .introduction(hive.getIntroduction()) - .hostId(hive.getCreatorId()) - .hostName(hive.getUser().getUsername()) + .hostId(hive.getId()) + .hostName(hive.getUser().getEmail()) .createdAt(hive.getCreatedAt()) .modifiedAt(hive.getModifiedAt()) .build(); diff --git a/src/main/java/com/HHive/hhive/domain/hive/service/HiveService.java b/src/main/java/com/HHive/hhive/domain/hive/service/HiveService.java index 8c44c7e..92abf56 100644 --- a/src/main/java/com/HHive/hhive/domain/hive/service/HiveService.java +++ b/src/main/java/com/HHive/hhive/domain/hive/service/HiveService.java @@ -40,9 +40,7 @@ public HiveResponseDTO createHive(User user, CreateHiveRequestDTO createHiveRequ if (hiveRepository.findByTitle(createHiveRequestDTO.getTitle()).isPresent()) { throw new AlreadyExistHiveException(); } - Hive saveHive = hiveRepository.save(createHiveRequestDTO.toEntity(createBy - ,MajorCategory.findByTitle(createHiveRequestDTO.getMajorCategoryName()) - ,SubCategory.findByTitle(createHiveRequestDTO.getSubCategoryName()))); + Hive saveHive = hiveRepository.save(createHiveRequestDTO.toEntity(createBy)); hiveUserService.saveHiveUser(saveHive, createBy); return HiveResponseDTO.of(saveHive); @@ -53,9 +51,6 @@ public HiveResponseDTO createHive(User user, CreateHiveRequestDTO createHiveRequ public HiveResponseDTO updateHive(User user, Long hiveId, @Valid UpdateHiveRequestDTO updateHiveRequest) { Hive hive = getHiveAndCheckAuth(user, hiveId); - if (hiveRepository.findByTitle(updateHiveRequest.getTitle()).isPresent()) { - throw new AlreadyExistHiveException(); - } hive.update(updateHiveRequest); return HiveResponseDTO.of(hive); From 24bd7d9982e743f2035525ae3b383142177cc615 Mon Sep 17 00:00:00 2001 From: mixedtape <54096846+mixedtape@users.noreply.github.com> Date: Fri, 26 Jan 2024 15:13:14 +0900 Subject: [PATCH 3/3] =?UTF-8?q?fix:=20=EC=B9=B4=ED=85=8C=EA=B3=A0=EB=A6=AC?= =?UTF-8?q?=20=ED=95=98=EC=9D=B4=EB=B8=8C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../HHive/hhive/domain/category/data/MajorCategory.java | 6 ++++++ .../com/HHive/hhive/domain/category/data/SubCategory.java | 6 ++++++ .../HHive/hhive/domain/hive/controller/HiveController.java | 2 ++ .../HHive/hhive/domain/hive/dto/CreateHiveRequestDTO.java | 6 +++--- .../com/HHive/hhive/domain/hive/dto/HiveResponseDTO.java | 4 ++-- .../com/HHive/hhive/domain/hive/service/HiveService.java | 7 ++++++- 6 files changed, 25 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/HHive/hhive/domain/category/data/MajorCategory.java b/src/main/java/com/HHive/hhive/domain/category/data/MajorCategory.java index 729da29..7143f02 100644 --- a/src/main/java/com/HHive/hhive/domain/category/data/MajorCategory.java +++ b/src/main/java/com/HHive/hhive/domain/category/data/MajorCategory.java @@ -20,4 +20,10 @@ public String getTitle() { public static MajorCategory findByStringName(String categoryName) { return Arrays.stream(MajorCategory.values()).filter(majorCategory -> majorCategory.name().equals(categoryName)).findFirst().orElse(null); } + public static MajorCategory findByTitle(String title) { + return Arrays.stream(MajorCategory.values()) + .filter(majorCategory -> majorCategory.title.equals(title)) + .findFirst() + .orElse(null); + } } diff --git a/src/main/java/com/HHive/hhive/domain/category/data/SubCategory.java b/src/main/java/com/HHive/hhive/domain/category/data/SubCategory.java index d53f0e2..af9d531 100644 --- a/src/main/java/com/HHive/hhive/domain/category/data/SubCategory.java +++ b/src/main/java/com/HHive/hhive/domain/category/data/SubCategory.java @@ -35,4 +35,10 @@ public String getTitle() { public static SubCategory findByStringName(String categoryName) { return Arrays.stream(SubCategory.values()).filter(subCategory -> subCategory.name().equals(categoryName)).findFirst().orElse(null); } + public static SubCategory findByTitle(String title) { + return Arrays.stream(SubCategory.values()) + .filter(subCategory -> subCategory.title.equals(title)) + .findFirst() + .orElse(null); + } } diff --git a/src/main/java/com/HHive/hhive/domain/hive/controller/HiveController.java b/src/main/java/com/HHive/hhive/domain/hive/controller/HiveController.java index c496e90..3e04707 100644 --- a/src/main/java/com/HHive/hhive/domain/hive/controller/HiveController.java +++ b/src/main/java/com/HHive/hhive/domain/hive/controller/HiveController.java @@ -39,6 +39,8 @@ public class HiveController { public ResponseEntity> createHive( @AuthenticationPrincipal UserDetailsImpl userDetails, @RequestBody @Valid CreateHiveRequestDTO createHiveRequestDTO) { + + SubCategory.findByStringName(createHiveRequestDTO.getSubCategoryName()); HiveResponseDTO response = hiveService.createHive(userDetails.getUser(), createHiveRequestDTO); return ResponseEntity.ok() diff --git a/src/main/java/com/HHive/hhive/domain/hive/dto/CreateHiveRequestDTO.java b/src/main/java/com/HHive/hhive/domain/hive/dto/CreateHiveRequestDTO.java index 4f6480e..506fa91 100644 --- a/src/main/java/com/HHive/hhive/domain/hive/dto/CreateHiveRequestDTO.java +++ b/src/main/java/com/HHive/hhive/domain/hive/dto/CreateHiveRequestDTO.java @@ -19,11 +19,11 @@ public class CreateHiveRequestDTO { @NotBlank private String title; - private MajorCategory majorCategory; + private String majorCategoryName; - private SubCategory subCategory; + private String subCategoryName; - public Hive toEntity(User createdBy) { + public Hive toEntity(User createdBy,MajorCategory majorCategory,SubCategory subCategory) { return Hive.builder() .title(title) .majorCategory(majorCategory) diff --git a/src/main/java/com/HHive/hhive/domain/hive/dto/HiveResponseDTO.java b/src/main/java/com/HHive/hhive/domain/hive/dto/HiveResponseDTO.java index 8efde3f..68c064b 100644 --- a/src/main/java/com/HHive/hhive/domain/hive/dto/HiveResponseDTO.java +++ b/src/main/java/com/HHive/hhive/domain/hive/dto/HiveResponseDTO.java @@ -48,8 +48,8 @@ public static HiveResponseDTO of(Hive hive) { .majorCategory(majorName) .subCategory(subName) .introduction(hive.getIntroduction()) - .hostId(hive.getId()) - .hostName(hive.getUser().getEmail()) + .hostId(hive.getCreatorId()) + .hostName(hive.getUser().getUsername()) .createdAt(hive.getCreatedAt()) .modifiedAt(hive.getModifiedAt()) .build(); diff --git a/src/main/java/com/HHive/hhive/domain/hive/service/HiveService.java b/src/main/java/com/HHive/hhive/domain/hive/service/HiveService.java index 92abf56..8c44c7e 100644 --- a/src/main/java/com/HHive/hhive/domain/hive/service/HiveService.java +++ b/src/main/java/com/HHive/hhive/domain/hive/service/HiveService.java @@ -40,7 +40,9 @@ public HiveResponseDTO createHive(User user, CreateHiveRequestDTO createHiveRequ if (hiveRepository.findByTitle(createHiveRequestDTO.getTitle()).isPresent()) { throw new AlreadyExistHiveException(); } - Hive saveHive = hiveRepository.save(createHiveRequestDTO.toEntity(createBy)); + Hive saveHive = hiveRepository.save(createHiveRequestDTO.toEntity(createBy + ,MajorCategory.findByTitle(createHiveRequestDTO.getMajorCategoryName()) + ,SubCategory.findByTitle(createHiveRequestDTO.getSubCategoryName()))); hiveUserService.saveHiveUser(saveHive, createBy); return HiveResponseDTO.of(saveHive); @@ -51,6 +53,9 @@ public HiveResponseDTO createHive(User user, CreateHiveRequestDTO createHiveRequ public HiveResponseDTO updateHive(User user, Long hiveId, @Valid UpdateHiveRequestDTO updateHiveRequest) { Hive hive = getHiveAndCheckAuth(user, hiveId); + if (hiveRepository.findByTitle(updateHiveRequest.getTitle()).isPresent()) { + throw new AlreadyExistHiveException(); + } hive.update(updateHiveRequest); return HiveResponseDTO.of(hive);