From 42578909c051827d22db04ac417fa3855129caa4 Mon Sep 17 00:00:00 2001 From: PgmJun Date: Sat, 27 Jan 2024 01:16:03 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=EC=BB=A8=EC=85=89=20=EC=84=B8=EB=B6=80?= =?UTF-8?q?=20=EC=A1=B0=ED=9A=8C=20=EA=B8=B0=EB=8A=A5=20=EA=B5=AC=ED=98=84?= =?UTF-8?q?=20#32?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/concept/ConceptController.java | 18 ++++++++-- .../concept/dto/ConceptDetailResponse.java | 20 +++++++++++ .../concept/dto/ConceptResponse.java | 5 --- .../concept/dto/ConceptRetrieveResponse.java | 9 +++++ .../concept/dto/ConceptsResponse.java | 27 -------------- .../concept/dto/ConceptsRetrieveResponse.java | 30 ++++++++++++++++ .../concept/service/ConceptQueryService.java | 14 +++++--- .../concept/service/ConceptServiceUtils.java | 11 ++++++ .../nice/petudio/domain/concept/Concept.java | 36 +++++++++---------- .../concept/repository/ConceptRepository.java | 3 ++ src/main/resources/sql/data.sql | 1 - src/main/resources/sql/schema.sql | 26 +++++++------- 12 files changed, 129 insertions(+), 71 deletions(-) create mode 100644 src/main/java/com/nice/petudio/api/controller/concept/dto/ConceptDetailResponse.java delete mode 100644 src/main/java/com/nice/petudio/api/controller/concept/dto/ConceptResponse.java create mode 100644 src/main/java/com/nice/petudio/api/controller/concept/dto/ConceptRetrieveResponse.java delete mode 100644 src/main/java/com/nice/petudio/api/controller/concept/dto/ConceptsResponse.java create mode 100644 src/main/java/com/nice/petudio/api/controller/concept/dto/ConceptsRetrieveResponse.java diff --git a/src/main/java/com/nice/petudio/api/controller/concept/ConceptController.java b/src/main/java/com/nice/petudio/api/controller/concept/ConceptController.java index dbbf201..71498c9 100644 --- a/src/main/java/com/nice/petudio/api/controller/concept/ConceptController.java +++ b/src/main/java/com/nice/petudio/api/controller/concept/ConceptController.java @@ -1,6 +1,8 @@ package com.nice.petudio.api.controller.concept; -import com.nice.petudio.api.controller.concept.dto.ConceptsResponse; +import com.nice.petudio.api.controller.concept.dto.ConceptDetailResponse; +import com.nice.petudio.api.controller.concept.dto.ConceptsRetrieveResponse; +import com.nice.petudio.api.controller.concept.service.ConceptCommandService; import com.nice.petudio.api.controller.concept.service.ConceptQueryService; import com.nice.petudio.api.dto.ApiResponse; import com.nice.petudio.common.auth.auth.Auth; @@ -8,6 +10,7 @@ import lombok.RequiredArgsConstructor; import org.springframework.http.HttpStatus; import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseStatus; import org.springframework.web.bind.annotation.RestController; @@ -17,12 +20,21 @@ @RequiredArgsConstructor public class ConceptController { private final ConceptQueryService conceptQueryService; + private final ConceptCommandService conceptCommandService; @Auth @Operation(summary = "[인증] AI 프로필 컨셉 전체 조회") @ResponseStatus(HttpStatus.OK) @GetMapping("/concepts") - public ApiResponse getAllConceptsInfo() { - return ApiResponse.success(conceptQueryService.findAllConcepts()); + public ApiResponse getAllConceptsInfo() { + return ApiResponse.success(conceptQueryService.findAllConceptsInfo()); + } + + @Auth + @Operation(summary = "[인증] AI 프로필 컨셉 조회") + @ResponseStatus(HttpStatus.OK) + @GetMapping("/concept/detail/{conceptId}") + public ApiResponse getConceptInfo(@PathVariable Long conceptId) { + return ApiResponse.success(conceptQueryService.findConceptDetailById(conceptId)); } } diff --git a/src/main/java/com/nice/petudio/api/controller/concept/dto/ConceptDetailResponse.java b/src/main/java/com/nice/petudio/api/controller/concept/dto/ConceptDetailResponse.java new file mode 100644 index 0000000..47d7e46 --- /dev/null +++ b/src/main/java/com/nice/petudio/api/controller/concept/dto/ConceptDetailResponse.java @@ -0,0 +1,20 @@ +package com.nice.petudio.api.controller.concept.dto; + + +import com.nice.petudio.domain.concept.Concept; +import java.util.List; +import lombok.AccessLevel; +import lombok.Builder; + +@Builder(access = AccessLevel.PRIVATE) +public record ConceptDetailResponse(List successImageUris, List failImageUris) { + + public static ConceptDetailResponse fromEntity(Concept concept) { + return ConceptDetailResponse.builder() + .successImageUris(List.of(concept.getSuccessImage1Uri(), concept.getSuccessImage2Uri(), + concept.getSuccessImage3Uri(), concept.getSuccessImage4Uri())) + .failImageUris(List.of(concept.getFailImage1lUri(), concept.getFailImage2Uri(), + concept.getFailImage3Uri(), concept.getFailImage4Uri())) + .build(); + } +} diff --git a/src/main/java/com/nice/petudio/api/controller/concept/dto/ConceptResponse.java b/src/main/java/com/nice/petudio/api/controller/concept/dto/ConceptResponse.java deleted file mode 100644 index 6277de0..0000000 --- a/src/main/java/com/nice/petudio/api/controller/concept/dto/ConceptResponse.java +++ /dev/null @@ -1,5 +0,0 @@ -package com.nice.petudio.api.controller.concept.dto; - - -public record ConceptResponse(String mainImageUri, String name, String description, Boolean isNew) { -} diff --git a/src/main/java/com/nice/petudio/api/controller/concept/dto/ConceptRetrieveResponse.java b/src/main/java/com/nice/petudio/api/controller/concept/dto/ConceptRetrieveResponse.java new file mode 100644 index 0000000..f91b776 --- /dev/null +++ b/src/main/java/com/nice/petudio/api/controller/concept/dto/ConceptRetrieveResponse.java @@ -0,0 +1,9 @@ +package com.nice.petudio.api.controller.concept.dto; + + +import lombok.AccessLevel; +import lombok.Builder; + +@Builder(access = AccessLevel.PRIVATE) +public record ConceptRetrieveResponse(String mainImageUri, String name, String description, Boolean isNew) { +} diff --git a/src/main/java/com/nice/petudio/api/controller/concept/dto/ConceptsResponse.java b/src/main/java/com/nice/petudio/api/controller/concept/dto/ConceptsResponse.java deleted file mode 100644 index 5d1d970..0000000 --- a/src/main/java/com/nice/petudio/api/controller/concept/dto/ConceptsResponse.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.nice.petudio.api.controller.concept.dto; - -import com.nice.petudio.common.util.MessageUtils; -import com.nice.petudio.domain.concept.Concept; -import com.nice.petudio.domain.concept.ConceptMessageType; -import java.time.LocalDateTime; -import java.util.ArrayList; -import java.util.List; -import org.springframework.context.MessageSource; - -public record ConceptsResponse(List conceptInfos) { - - public static ConceptsResponse convertEntitiesToDto(List concepts, MessageSource messageSource, LocalDateTime now) { - List conceptsResponse = new ArrayList<>(); - - for (Concept concept : concepts) { - String conceptMessagePrefix = concept.getConceptType().getMessagePrefix(); - - String conceptName = MessageUtils.getMessage(messageSource, conceptMessagePrefix + ConceptMessageType.NAME.getType()); - String conceptDescription = MessageUtils.getMessage(messageSource, conceptMessagePrefix + ConceptMessageType.DESCRIPTION.getType()); - - conceptsResponse.add(new ConceptResponse(concept.getMainImage(), conceptName, conceptDescription, concept.validateIsNew( - now))); - } - return new ConceptsResponse(conceptsResponse); - } -} diff --git a/src/main/java/com/nice/petudio/api/controller/concept/dto/ConceptsRetrieveResponse.java b/src/main/java/com/nice/petudio/api/controller/concept/dto/ConceptsRetrieveResponse.java new file mode 100644 index 0000000..f3ef353 --- /dev/null +++ b/src/main/java/com/nice/petudio/api/controller/concept/dto/ConceptsRetrieveResponse.java @@ -0,0 +1,30 @@ +package com.nice.petudio.api.controller.concept.dto; + +import com.nice.petudio.common.util.MessageUtils; +import com.nice.petudio.domain.concept.Concept; +import com.nice.petudio.domain.concept.ConceptMessageType; +import java.time.LocalDateTime; +import java.util.ArrayList; +import java.util.List; +import org.springframework.context.MessageSource; + +public record ConceptsRetrieveResponse(List conceptInfos) { + + public static ConceptsRetrieveResponse convertEntitiesToDto(List concepts, MessageSource messageSource, + LocalDateTime now) { + List conceptsResponse = new ArrayList<>(); + + for (Concept concept : concepts) { + String conceptMessagePrefix = concept.getConceptType().getMessagePrefix(); + + String conceptName = MessageUtils.getMessage(messageSource, + conceptMessagePrefix + ConceptMessageType.NAME.getType()); + String conceptDescription = MessageUtils.getMessage(messageSource, + conceptMessagePrefix + ConceptMessageType.DESCRIPTION.getType()); + + conceptsResponse.add(new ConceptRetrieveResponse(concept.getMainImageUri(), conceptName, conceptDescription, + concept.validateIsNew(now))); + } + return new ConceptsRetrieveResponse(conceptsResponse); + } +} diff --git a/src/main/java/com/nice/petudio/api/controller/concept/service/ConceptQueryService.java b/src/main/java/com/nice/petudio/api/controller/concept/service/ConceptQueryService.java index 1fd4ad8..0c60d30 100644 --- a/src/main/java/com/nice/petudio/api/controller/concept/service/ConceptQueryService.java +++ b/src/main/java/com/nice/petudio/api/controller/concept/service/ConceptQueryService.java @@ -1,6 +1,8 @@ package com.nice.petudio.api.controller.concept.service; -import com.nice.petudio.api.controller.concept.dto.ConceptsResponse; +import com.nice.petudio.api.controller.concept.dto.ConceptDetailResponse; +import com.nice.petudio.api.controller.concept.dto.ConceptsRetrieveResponse; +import com.nice.petudio.domain.concept.Concept; import com.nice.petudio.domain.concept.repository.ConceptRepository; import java.time.LocalDateTime; import lombok.RequiredArgsConstructor; @@ -15,9 +17,13 @@ public class ConceptQueryService { private final MessageSource messageSource; private final ConceptRepository conceptRepository; - - public ConceptsResponse findAllConcepts() { - return ConceptsResponse.convertEntitiesToDto(conceptRepository.findAllConcept(), messageSource, + public ConceptsRetrieveResponse findAllConceptsInfo() { + return ConceptsRetrieveResponse.convertEntitiesToDto(conceptRepository.findAllConcept(), messageSource, LocalDateTime.now()); } + + public ConceptDetailResponse findConceptDetailById(Long conceptId) { + Concept concept = ConceptServiceUtils.findByConceptId(conceptRepository, conceptId); + return ConceptDetailResponse.fromEntity(concept); + } } diff --git a/src/main/java/com/nice/petudio/api/controller/concept/service/ConceptServiceUtils.java b/src/main/java/com/nice/petudio/api/controller/concept/service/ConceptServiceUtils.java index f455409..b66e5a0 100644 --- a/src/main/java/com/nice/petudio/api/controller/concept/service/ConceptServiceUtils.java +++ b/src/main/java/com/nice/petudio/api/controller/concept/service/ConceptServiceUtils.java @@ -1,4 +1,15 @@ package com.nice.petudio.api.controller.concept.service; +import com.nice.petudio.common.exception.error.ErrorCode; +import com.nice.petudio.common.exception.model.NotFoundException; +import com.nice.petudio.domain.concept.Concept; +import com.nice.petudio.domain.concept.repository.ConceptRepository; + public class ConceptServiceUtils { + + public static Concept findByConceptId(ConceptRepository conceptRepository, Long conceptId) { + return conceptRepository.findById(conceptId) + .orElseThrow(() -> new NotFoundException(ErrorCode.NOT_FOUND_CONCEPT_EXCEPTION, + String.format("존재하지 않는 conceptId(%d) 입니다.", conceptId))); + } } diff --git a/src/main/java/com/nice/petudio/domain/concept/Concept.java b/src/main/java/com/nice/petudio/domain/concept/Concept.java index e2e3ae1..17feb9c 100644 --- a/src/main/java/com/nice/petudio/domain/concept/Concept.java +++ b/src/main/java/com/nice/petudio/domain/concept/Concept.java @@ -31,32 +31,32 @@ public class Concept extends BaseEntity { @Column(name = "concept_type", length = 30, nullable = false) private ConceptType conceptType; - @Column(name = "concept_main_image", length = 200, nullable = false) - private String mainImage; + @Column(name = "concept_main_image_uri", length = 200, nullable = false) + private String mainImageUri; - @Column(name = "concept_sub_image1", length = 200, nullable = false) - private String subImage1; + @Column(name = "concept_success_image1_uri", length = 200, nullable = false) + private String successImage1Uri; - @Column(name = "concept_sub_image2", length = 200, nullable = false) - private String subImage2; + @Column(name = "concept_success_image2_uri", length = 200, nullable = false) + private String successImage2Uri; - @Column(name = "concept_sub_image3", length = 200, nullable = false) - private String subImage3; + @Column(name = "concept_success_image3_uri", length = 200, nullable = false) + private String successImage3Uri; - @Column(name = "concept_sub_image4", length = 200, nullable = false) - private String subImage4; + @Column(name = "concept_success_image4_uri", length = 200, nullable = false) + private String successImage4Uri; - @Column(name = "concept_fail_image1", length = 200, nullable = false) - private String failImage1; + @Column(name = "concept_fail_image1_uri", length = 200, nullable = false) + private String failImage1lUri; - @Column(name = "concept_fail_image2", length = 200, nullable = false) - private String failImage2; + @Column(name = "concept_fail_image2_uri", length = 200, nullable = false) + private String failImage2Uri; - @Column(name = "concept_fail_image3", length = 200, nullable = false) - private String failImage3; + @Column(name = "concept_fail_image3_uri", length = 200, nullable = false) + private String failImage3Uri; - @Column(name = "concept_fail_image4", length = 200, nullable = false) - private String failImage4; + @Column(name = "concept_fail_image4_uri", length = 200, nullable = false) + private String failImage4Uri; public boolean validateIsNew(LocalDateTime now) { diff --git a/src/main/java/com/nice/petudio/domain/concept/repository/ConceptRepository.java b/src/main/java/com/nice/petudio/domain/concept/repository/ConceptRepository.java index 80ab900..cd716dd 100644 --- a/src/main/java/com/nice/petudio/domain/concept/repository/ConceptRepository.java +++ b/src/main/java/com/nice/petudio/domain/concept/repository/ConceptRepository.java @@ -1,7 +1,10 @@ package com.nice.petudio.domain.concept.repository; import com.nice.petudio.domain.concept.Concept; +import com.nice.petudio.domain.concept.ConceptType; +import java.util.Optional; import org.springframework.data.jpa.repository.JpaRepository; public interface ConceptRepository extends ConceptRepositoryCustom, JpaRepository { + Optional findByConceptType(ConceptType conceptType); } diff --git a/src/main/resources/sql/data.sql b/src/main/resources/sql/data.sql index 672c7d5..7378b40 100644 --- a/src/main/resources/sql/data.sql +++ b/src/main/resources/sql/data.sql @@ -1,3 +1,2 @@ -# Concept Data Insert (컨셉 추가 시, 여기에 추가) INSERT INTO concepts VALUES(1, 'CONCEPT_3D', 'mainImage','image','image','image','image','image','image','image','image', '2024-01-24 23:48:52','2024-01-24 23:48:52'); INSERT INTO concepts VALUES(2, 'CONCEPT_TRENDY', 'mainImage','image','image','image','image','image','image','image','image', '2024-01-24 23:48:52','2024-01-24 23:48:52'); diff --git a/src/main/resources/sql/schema.sql b/src/main/resources/sql/schema.sql index 0dbca4c..8610dcc 100644 --- a/src/main/resources/sql/schema.sql +++ b/src/main/resources/sql/schema.sql @@ -39,19 +39,19 @@ CREATE TABLE `points` CREATE TABLE `concepts` ( - `concept_id` bigint AUTO_INCREMENT PRIMARY KEY, - `concept_type` varchar(30) NOT NULL, - `concept_main_image` varchar(200) NOT NULL, - `concept_sub_image1` varchar(200) NOT NULL, - `concept_sub_image2` varchar(200) NOT NULL, - `concept_sub_image3` varchar(200) NOT NULL, - `concept_sub_image4` varchar(200) NOT NULL, - `concept_fail_image1` varchar(200) NOT NULL, - `concept_fail_image2` varchar(200) NOT NULL, - `concept_fail_image3` varchar(200) NOT NULL, - `concept_fail_image4` varchar(200) NOT NULL, - `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, - `modified_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP + `concept_id` bigint AUTO_INCREMENT PRIMARY KEY, + `concept_type` varchar(30) NOT NULL, + `concept_main_image_uri` varchar(200) NOT NULL, + `concept_success_image1_uri` varchar(200) NOT NULL, + `concept_success_image2_uri` varchar(200) NOT NULL, + `concept_success_image3_uri` varchar(200) NOT NULL, + `concept_success_image4_uri` varchar(200) NOT NULL, + `concept_fail_image1_uri` varchar(200) NOT NULL, + `concept_fail_image2_uri` varchar(200) NOT NULL, + `concept_fail_image3_uri` varchar(200) NOT NULL, + `concept_fail_image4_uri` varchar(200) NOT NULL, + `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + `modified_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP ); CREATE TABLE `pets`