-
Notifications
You must be signed in to change notification settings - Fork 0
[Feat/get runimos] 러니모 조회 api 두가지 구현 #49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
7214c1c
237a6de
7597223
2d2178e
effd52e
4fe1cf5
8530bc0
ca04d33
4e13984
d36f3a2
49a5ad2
46b5edd
3777955
bb3d19a
aa936ab
6456de4
de8aa69
b0359ee
8412e24
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| package org.runimo.runimo.runimo.controller.dto.response; | ||
|
|
||
| import io.swagger.v3.oas.annotations.media.Schema; | ||
| import java.util.List; | ||
|
|
||
| @Schema(description = "전체 러니모 종류 조회 응답") | ||
| public record GetRunimoTypeListResponse( | ||
| List<RunimoTypeGroup> runimoGroups | ||
| ) { | ||
|
|
||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| package org.runimo.runimo.runimo.controller.dto.response; | ||
|
|
||
| import io.swagger.v3.oas.annotations.media.Schema; | ||
| import java.util.List; | ||
|
|
||
| @Schema(description = "전체 러니모 종류 조회 응답") | ||
| public record RunimoTypeGroup( | ||
| @Schema(description = "러니모가 태어난 알 속성", example = "마당") | ||
| String eggType, | ||
|
|
||
| @Schema(description = "해당 알에서 태어나는 러니모 목록") | ||
| List<RunimoTypeInfo> runimoTypes | ||
| ) { | ||
|
|
||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| package org.runimo.runimo.runimo.controller.dto.response; | ||
|
|
||
| import io.swagger.v3.oas.annotations.media.Schema; | ||
|
|
||
| public record RunimoTypeInfo( | ||
| @Schema(description = "러니모 이름", example = "토끼") | ||
| String name, | ||
|
|
||
| @Schema(description = "러니모 이미지 url", example = "http://...") | ||
| String imgUrl, | ||
|
|
||
| @Schema(description = "러니모 code", example = "R-101") | ||
| String code, | ||
|
|
||
| @Schema(description = "러니모 상세설명", example = "마당알에서 태어난 마당 토끼예요.") | ||
| String description | ||
| ) { | ||
|
|
||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,19 @@ | ||
| package org.runimo.runimo.runimo.repository; | ||
|
|
||
| import java.util.List; | ||
| import java.util.Optional; | ||
| import org.runimo.runimo.runimo.domain.RunimoDefinition; | ||
| import org.runimo.runimo.runimo.service.model.RunimoTypeSimpleModel; | ||
| import org.springframework.data.jpa.repository.JpaRepository; | ||
| import org.springframework.data.jpa.repository.Query; | ||
|
|
||
| public interface RunimoDefinitionRepository extends JpaRepository<RunimoDefinition, Long> { | ||
|
|
||
| Optional<RunimoDefinition> findByCode(String runimoCode); | ||
|
|
||
| @Query(""" | ||
| select new org.runimo.runimo.runimo.service.model.RunimoTypeSimpleModel(rd.name, rd.imgUrl, rd.code, rd.type, rd.description) | ||
| from RunimoDefinition rd | ||
| """) | ||
| List<RunimoTypeSimpleModel> findAllToSimpleModel(); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,38 +1,22 @@ | ||
| package org.runimo.runimo.runimo.service.model; | ||
|
|
||
| import java.util.List; | ||
| import org.runimo.runimo.item.domain.EggType; | ||
| import org.runimo.runimo.runimo.controller.dto.response.RunimoInfo; | ||
|
|
||
| public record RunimoSimpleModel( | ||
| Long id, | ||
| String name, | ||
| String imgUrl, | ||
| String code, | ||
| String eggType, | ||
| String description | ||
| Long totalRunCount, | ||
| Long totalDistanceInMeters | ||
| ) { | ||
|
|
||
| public RunimoSimpleModel(Long id, String name, String imgUrl, String code, String eggType, | ||
| String description) { | ||
| this.id = id; | ||
| this.name = name; | ||
| this.imgUrl = imgUrl; | ||
| this.code = code; | ||
| this.eggType = eggType; | ||
| this.description = description; | ||
| public static List<RunimoInfo> toDtoList(List<RunimoSimpleModel> modelList, Long mainRunimoId) { | ||
| return modelList.stream().map(i -> | ||
| i.toDto(i.id.equals(mainRunimoId)) | ||
| ).toList(); | ||
| } | ||
|
|
||
| public RunimoSimpleModel(Long id, String name, String imgUrl, String code, EggType eggType, | ||
| String description) { | ||
| this(id, name, imgUrl, code, eggType.name(), description); | ||
| } | ||
|
|
||
| public static List<RunimoInfo> toDtoList(List<RunimoSimpleModel> modelList) { | ||
| return modelList.stream().map(RunimoSimpleModel::toDto).toList(); | ||
| } | ||
|
|
||
| private RunimoInfo toDto() { | ||
| return new RunimoInfo(id, name, imgUrl, code, eggType, description); | ||
| private RunimoInfo toDto(Boolean isMainRunimo) { | ||
| return new RunimoInfo(id, code, totalRunCount, totalDistanceInMeters, isMainRunimo); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| package org.runimo.runimo.runimo.service.model; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.HashMap; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import org.runimo.runimo.item.domain.EggType; | ||
| import org.runimo.runimo.runimo.controller.dto.response.RunimoTypeGroup; | ||
| import org.runimo.runimo.runimo.controller.dto.response.RunimoTypeInfo; | ||
|
|
||
| public record RunimoTypeSimpleModel( | ||
| String name, | ||
| String imgUrl, | ||
| String code, | ||
| String eggType, | ||
| String description | ||
| ) { | ||
|
|
||
| public RunimoTypeSimpleModel(String name, String imgUrl, String code, EggType eggType, | ||
| String description) { | ||
| this(name, imgUrl, code, eggType.getName(), description); | ||
| } | ||
|
|
||
| public static List<RunimoTypeGroup> toDtoList(List<RunimoTypeSimpleModel> modelList) { | ||
| Map<String, List<RunimoTypeInfo>> runimoDtoMap = toRunimoTypeMap( | ||
| modelList); | ||
|
|
||
| List<RunimoTypeGroup> runimoTypeGroups = toRunimoTypeGroups( | ||
| runimoDtoMap); | ||
|
|
||
| return runimoTypeGroups; | ||
| } | ||
|
|
||
| private RunimoTypeInfo toDto() { | ||
| return new RunimoTypeInfo(name, imgUrl, code, description); | ||
| } | ||
|
|
||
|
|
||
| /** | ||
| * EggType enum 클래스 순서 기준으로 EggType 별 러니모 그룹목록 생성 | ||
| */ | ||
| private static List<RunimoTypeGroup> toRunimoTypeGroups( | ||
| Map<String, List<RunimoTypeInfo>> runimoDtoMap) { | ||
|
|
||
| List<RunimoTypeGroup> runimoTypeGroups = new ArrayList<>(); | ||
| for (EggType eggType : EggType.values()) { | ||
| String key = eggType.getName(); | ||
| runimoTypeGroups.add(new RunimoTypeGroup(key, runimoDtoMap.get(key))); | ||
| } | ||
|
|
||
| return runimoTypeGroups; | ||
| } | ||
|
Comment on lines
+42
to
+52
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Verification agent 🧩 Analysis chainEnsure order consistency for egg type groups The method creates RunimoTypeGroup objects based on the order of EggType enum values, which is a good approach for maintaining a consistent order in the response. However, there's a potential issue if the 🏁 Script executed: #!/bin/bash
# Check if there's error handling for missing egg types in the map
# First, check if there's any null check when accessing runimoDtoMap.get(key)
rg "runimoDtoMap\.get\(" -A 3 -B 3
# Then check if all EggType values are expected to be present in the database
echo "Checking for SQL scripts that populate EggType data:"
fd -e sql | xargs grep -l "EggType" | xargs catLength of output: 1049 Address Null Handling for Egg Type Map Entries The current implementation correctly preserves the order by iterating over the
|
||
|
|
||
| /** | ||
| * EggType 별 러니모 분류 map 생성 | ||
| */ | ||
| private static Map<String, List<RunimoTypeInfo>> toRunimoTypeMap( | ||
| List<RunimoTypeSimpleModel> modelList) { | ||
|
|
||
| Map<String, List<RunimoTypeInfo>> runimoTypeDtos = new HashMap<>(); | ||
| for (RunimoTypeSimpleModel model : modelList) { | ||
| String key = model.eggType(); | ||
| if (!runimoTypeDtos.containsKey(key)) { | ||
| runimoTypeDtos.put(key, new ArrayList<>()); | ||
| } | ||
| runimoTypeDtos.get(key).add(model.toDto()); | ||
| } | ||
|
|
||
| return runimoTypeDtos; | ||
| } | ||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,14 @@ | ||
| package org.runimo.runimo.runimo.service.usecase; | ||
|
|
||
| import org.runimo.runimo.runimo.controller.dto.response.GetMyRunimoListResponse; | ||
| import org.runimo.runimo.runimo.controller.dto.response.GetRunimoTypeListResponse; | ||
| import org.runimo.runimo.runimo.controller.dto.response.SetMainRunimoResponse; | ||
|
|
||
| public interface RunimoUsecase { | ||
|
|
||
| GetMyRunimoListResponse getMyRunimoList(Long userId); | ||
|
|
||
| SetMainRunimoResponse setMainRunimo(Long userId, Long runimoId); | ||
|
|
||
| GetRunimoTypeListResponse getRunimoTypeList(); | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.