Skip to content

Commit

Permalink
feat: 컨셉 세부 조회 기능 구현 #32
Browse files Browse the repository at this point in the history
  • Loading branch information
PgmJun committed Jan 27, 2024
1 parent ee5529b commit 4257890
Show file tree
Hide file tree
Showing 12 changed files with 129 additions and 71 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
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;
import io.swagger.v3.oas.annotations.Operation;
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;
Expand All @@ -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<ConceptsResponse> getAllConceptsInfo() {
return ApiResponse.success(conceptQueryService.findAllConcepts());
public ApiResponse<ConceptsRetrieveResponse> getAllConceptsInfo() {
return ApiResponse.success(conceptQueryService.findAllConceptsInfo());
}

@Auth
@Operation(summary = "[인증] AI 프로필 컨셉 조회")
@ResponseStatus(HttpStatus.OK)
@GetMapping("/concept/detail/{conceptId}")
public ApiResponse<ConceptDetailResponse> getConceptInfo(@PathVariable Long conceptId) {
return ApiResponse.success(conceptQueryService.findConceptDetailById(conceptId));
}
}
Original file line number Diff line number Diff line change
@@ -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<String> successImageUris, List<String> 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();
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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) {
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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<ConceptRetrieveResponse> conceptInfos) {

public static ConceptsRetrieveResponse convertEntitiesToDto(List<Concept> concepts, MessageSource messageSource,
LocalDateTime now) {
List<ConceptRetrieveResponse> 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);
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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)));
}
}
36 changes: 18 additions & 18 deletions src/main/java/com/nice/petudio/domain/concept/Concept.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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<Concept, Long> {
Optional<Concept> findByConceptType(ConceptType conceptType);
}
1 change: 0 additions & 1 deletion src/main/resources/sql/data.sql
Original file line number Diff line number Diff line change
@@ -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');
26 changes: 13 additions & 13 deletions src/main/resources/sql/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down

0 comments on commit 4257890

Please sign in to comment.