-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
125 additions
and
0 deletions.
There are no files selected for viewing
28 changes: 28 additions & 0 deletions
28
src/main/java/com/nice/petudio/api/controller/concept/ConceptController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
src/main/java/com/nice/petudio/api/controller/concept/dto/ConceptResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) { | ||
} |
27 changes: 27 additions & 0 deletions
27
src/main/java/com/nice/petudio/api/controller/concept/dto/ConceptsResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/main/java/com/nice/petudio/api/controller/concept/service/ConceptCommandService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { | ||
} |
23 changes: 23 additions & 0 deletions
23
src/main/java/com/nice/petudio/api/controller/concept/service/ConceptQueryService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
src/main/java/com/nice/petudio/api/controller/concept/service/ConceptServiceUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
src/main/java/com/nice/petudio/domain/concept/repository/ConceptRepositoryCustom.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} |
16 changes: 16 additions & 0 deletions
16
src/main/java/com/nice/petudio/domain/concept/repository/ConceptRepositoryImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |