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 87c7c4b commit ee5529b
Show file tree
Hide file tree
Showing 9 changed files with 125 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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<ConceptsResponse> getAllConceptsInfo() {
return ApiResponse.success(conceptQueryService.findAllConcepts());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.nice.petudio.api.controller.concept.dto;


public record ConceptResponse(String mainImageUri, String name, String description, Boolean isNew) {
}
Original file line number Diff line number Diff line change
@@ -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<ConceptResponse> conceptInfos) {

public static ConceptsResponse convertEntitiesToDto(List<Concept> concepts, MessageSource messageSource, LocalDateTime now) {
List<ConceptResponse> 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);
}
}
Original file line number Diff line number Diff line change
@@ -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 {
}
Original file line number Diff line number Diff line change
@@ -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());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.nice.petudio.api.controller.concept.service;

public class ConceptServiceUtils {
}
7 changes: 7 additions & 0 deletions src/main/java/com/nice/petudio/domain/concept/Concept.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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));
}
}
Original file line number Diff line number Diff line change
@@ -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<Concept> findAllConcept();
}
Original file line number Diff line number Diff line change
@@ -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<Concept> findAllConcept() {
return queryFactory
.selectFrom(concept)
.fetch();
}
}

0 comments on commit ee5529b

Please sign in to comment.