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 new file mode 100644 index 0000000..dbbf201 --- /dev/null +++ b/src/main/java/com/nice/petudio/api/controller/concept/ConceptController.java @@ -0,0 +1,28 @@ +package com.nice.petudio.api.controller.concept; + +import com.nice.petudio.api.controller.concept.dto.ConceptsResponse; +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.RequestMapping; +import org.springframework.web.bind.annotation.ResponseStatus; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("/api/v1") +@RequiredArgsConstructor +public class ConceptController { + private final ConceptQueryService conceptQueryService; + + @Auth + @Operation(summary = "[인증] AI 프로필 컨셉 전체 조회") + @ResponseStatus(HttpStatus.OK) + @GetMapping("/concepts") + public ApiResponse getAllConceptsInfo() { + return ApiResponse.success(conceptQueryService.findAllConcepts()); + } +} 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 new file mode 100644 index 0000000..6277de0 --- /dev/null +++ b/src/main/java/com/nice/petudio/api/controller/concept/dto/ConceptResponse.java @@ -0,0 +1,5 @@ +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/ConceptsResponse.java b/src/main/java/com/nice/petudio/api/controller/concept/dto/ConceptsResponse.java new file mode 100644 index 0000000..5d1d970 --- /dev/null +++ b/src/main/java/com/nice/petudio/api/controller/concept/dto/ConceptsResponse.java @@ -0,0 +1,27 @@ +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/service/ConceptCommandService.java b/src/main/java/com/nice/petudio/api/controller/concept/service/ConceptCommandService.java new file mode 100644 index 0000000..c49278c --- /dev/null +++ b/src/main/java/com/nice/petudio/api/controller/concept/service/ConceptCommandService.java @@ -0,0 +1,11 @@ +package com.nice.petudio.api.controller.concept.service; + +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +@Service +@Transactional +@RequiredArgsConstructor +public class ConceptCommandService { +} 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 new file mode 100644 index 0000000..1fd4ad8 --- /dev/null +++ b/src/main/java/com/nice/petudio/api/controller/concept/service/ConceptQueryService.java @@ -0,0 +1,23 @@ +package com.nice.petudio.api.controller.concept.service; + +import com.nice.petudio.api.controller.concept.dto.ConceptsResponse; +import com.nice.petudio.domain.concept.repository.ConceptRepository; +import java.time.LocalDateTime; +import lombok.RequiredArgsConstructor; +import org.springframework.context.MessageSource; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +@Service +@Transactional(readOnly = true) +@RequiredArgsConstructor +public class ConceptQueryService { + private final MessageSource messageSource; + private final ConceptRepository conceptRepository; + + + public ConceptsResponse findAllConcepts() { + return ConceptsResponse.convertEntitiesToDto(conceptRepository.findAllConcept(), messageSource, + LocalDateTime.now()); + } +} 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 new file mode 100644 index 0000000..f455409 --- /dev/null +++ b/src/main/java/com/nice/petudio/api/controller/concept/service/ConceptServiceUtils.java @@ -0,0 +1,4 @@ +package com.nice.petudio.api.controller.concept.service; + +public class ConceptServiceUtils { +} 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 654536a..e2e3ae1 100644 --- a/src/main/java/com/nice/petudio/domain/concept/Concept.java +++ b/src/main/java/com/nice/petudio/domain/concept/Concept.java @@ -9,6 +9,7 @@ import jakarta.persistence.GenerationType; import jakarta.persistence.Id; import jakarta.persistence.Table; +import java.time.LocalDateTime; import lombok.AccessLevel; import lombok.AllArgsConstructor; import lombok.Getter; @@ -56,4 +57,10 @@ public class Concept extends BaseEntity { @Column(name = "concept_fail_image4", length = 200, nullable = false) private String failImage4; + + + public boolean validateIsNew(LocalDateTime now) { + // 컨셉이 생긴지 90일이 지나지 않았으면 'New 컨셉'에 해당 + return getCreatedAt().isAfter(now.minusDays(90)); + } } diff --git a/src/main/java/com/nice/petudio/domain/concept/repository/ConceptRepositoryCustom.java b/src/main/java/com/nice/petudio/domain/concept/repository/ConceptRepositoryCustom.java index a2aa516..7ba4cae 100644 --- a/src/main/java/com/nice/petudio/domain/concept/repository/ConceptRepositoryCustom.java +++ b/src/main/java/com/nice/petudio/domain/concept/repository/ConceptRepositoryCustom.java @@ -1,4 +1,8 @@ package com.nice.petudio.domain.concept.repository; +import com.nice.petudio.domain.concept.Concept; +import java.util.List; + public interface ConceptRepositoryCustom { + List findAllConcept(); } diff --git a/src/main/java/com/nice/petudio/domain/concept/repository/ConceptRepositoryImpl.java b/src/main/java/com/nice/petudio/domain/concept/repository/ConceptRepositoryImpl.java index 91f4773..ea1f9dc 100644 --- a/src/main/java/com/nice/petudio/domain/concept/repository/ConceptRepositoryImpl.java +++ b/src/main/java/com/nice/petudio/domain/concept/repository/ConceptRepositoryImpl.java @@ -1,4 +1,20 @@ package com.nice.petudio.domain.concept.repository; +import static com.nice.petudio.domain.concept.QConcept.concept; + +import com.nice.petudio.domain.concept.Concept; +import com.querydsl.jpa.impl.JPAQueryFactory; +import java.util.List; +import lombok.RequiredArgsConstructor; + +@RequiredArgsConstructor public class ConceptRepositoryImpl implements ConceptRepositoryCustom{ + private final JPAQueryFactory queryFactory; + + @Override + public List findAllConcept() { + return queryFactory + .selectFrom(concept) + .fetch(); + } }