Skip to content

Commit

Permalink
[BE-REFACTOR] 바이옴 타입 전달 시 이름과 함께 전달 (#270)
Browse files Browse the repository at this point in the history
* refactor: 바이옴 타입 반환 시 이름도 같이 반환하도록 수정

* chore: 서브모듈 커밋 시점 변경

* refactor: 타입만 로고 확장자 제거

* style: 개행 추가

* style: 개행 추가
  • Loading branch information
unifolio0 authored Aug 21, 2024
1 parent d5abb02 commit cc4558d
Show file tree
Hide file tree
Showing 9 changed files with 59 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ private String makeTypeFileName(String typeName) {
}

public String getPokerogueTypeImageFromS3(String typeName) {
String key = POKEROGUE_TYPE_IMAGE_FOLDER + typeName + "-1" + PNG_EXTENSION;
String key = POKEROGUE_TYPE_IMAGE_FOLDER + typeName;
return s3ImageClient.getFileUrl(key);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ public record BiomePokemonResponse(
String id,
String name,
String image,
List<BiomePokemonTypeResponse> pokemonTypeResponses
List<BiomeTypeResponse> pokemonTypeResponses
) {
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ public record BiomeResponse(
String id,
String name,
String image,
List<String> pokemonTypeLogos,
List<String> trainerTypeLogos
List<BiomeTypeResponse> pokemonTypeResponses,
List<BiomeTypeResponse> trainerTypeResponses
) {

public static BiomeResponse from(Biome biome, List<String> pokemonTypeLogos, List<String> trainerTypeLogos) {
public static BiomeResponse of(Biome biome, List<BiomeTypeResponse> pokemonTypeLogos, List<BiomeTypeResponse> trainerTypeLogos) {
return new BiomeResponse(
biome.getId(),
biome.getName(),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.pokerogue.helper.biome.dto;

public record BiomeTypeResponse(String typeLogo, String typeName) {
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,30 @@
package com.pokerogue.helper.biome.dto;

import com.pokerogue.helper.biome.data.Biome;
import java.util.List;

public record NextBiomeResponse(String id, String name, String image, String percent) {
public record NextBiomeResponse(
String id,
String name,
String image,
String percent,
List<BiomeTypeResponse> pokemonTypeResponses,
List<BiomeTypeResponse> trainerTypeResponses
) {

public static NextBiomeResponse of(Biome biome, String percent) {
return new NextBiomeResponse(biome.getId(), biome.getName(), biome.getImage(), percent);
public static NextBiomeResponse of(
Biome biome,
String percent,
List<BiomeTypeResponse> pokemonTypeResponses,
List<BiomeTypeResponse> trainerTypeResponses
) {
return new NextBiomeResponse(
biome.getId(),
biome.getName(),
biome.getImage(),
percent,
pokemonTypeResponses,
trainerTypeResponses
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
public record TrainerPokemonResponse(
String trainerName,
String trainerImage,
List<String> trainerTypeLogos,
List<BiomeTypeResponse> trainerTypeResponses,
List<BiomePokemonResponse> pokemons
) {

public static TrainerPokemonResponse from(
Trainer trainer,
List<String> trainerTypes,
List<BiomeTypeResponse> trainerTypes,
List<BiomePokemonResponse> trainerPokemons) {
return new TrainerPokemonResponse(
trainer.getName(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import com.pokerogue.helper.biome.dto.BiomeAllPokemonResponse;
import com.pokerogue.helper.biome.dto.BiomeDetailResponse;
import com.pokerogue.helper.biome.dto.BiomePokemonResponse;
import com.pokerogue.helper.biome.dto.BiomePokemonTypeResponse;
import com.pokerogue.helper.biome.dto.BiomeTypeResponse;
import com.pokerogue.helper.biome.dto.BiomeResponse;
import com.pokerogue.helper.biome.dto.NextBiomeResponse;
import com.pokerogue.helper.biome.dto.TrainerPokemonResponse;
Expand All @@ -32,10 +32,10 @@ public class BiomeService {

public List<BiomeResponse> findBiomes() {
return biomeRepository.findAll().stream()
.map(biome -> BiomeResponse.from(
.map(biome -> BiomeResponse.of(
biome,
getTrainerTypes(biome.getMainTypes()),
getTrainerTypes(biome.getTrainerTypes()))
getTypesResponses(biome.getMainTypes()),
getTypesResponses(biome.getTrainerTypes()))
)
.toList();
}
Expand Down Expand Up @@ -88,25 +88,25 @@ private List<BiomePokemonResponse> getBiomePokemons(List<String> biomePokemons)
.toList();
}

private List<BiomePokemonTypeResponse> getBiomePokemonTypeResponses(
private List<BiomeTypeResponse> getBiomePokemonTypeResponses(
BiomePokemonType type1,
BiomePokemonType type2
) {
List<BiomePokemonTypeResponse> biomePokemonTypeResponses = new ArrayList<>();
List<BiomeTypeResponse> biomeTypeRespons = new ArrayList<>();
if (!type1.getName().equals("없음")) {
biomePokemonTypeResponses.add(new BiomePokemonTypeResponse(
biomeTypeRespons.add(new BiomeTypeResponse(
biomePokemonTypeImageRepository.findPokemonTypeImageUrl(type1.name()),
type1.getName())
);
}
if (!type2.getName().equals("없음")) {
biomePokemonTypeResponses.add(new BiomePokemonTypeResponse(
biomeTypeRespons.add(new BiomeTypeResponse(
biomePokemonTypeImageRepository.findPokemonTypeImageUrl(type2.name()),
type2.getName())
);
}

return biomePokemonTypeResponses;
return biomeTypeRespons;
}

private List<TrainerPokemonResponse> getTrainerPokemons(Biome biome) {
Expand All @@ -120,16 +120,16 @@ private List<TrainerPokemonResponse> getTrainerPokemons(Biome biome) {
return biome.getTrainers().stream()
.map(trainer -> TrainerPokemonResponse.from(
trainer,
getTrainerTypes(trainer.getTrainerTypes()),
getTypesResponses(trainer.getTrainerTypes()),
getBiomePokemons(trainer.getPokemons()))
)
.toList();
}

private List<String> getTrainerTypes(List<String> trainerTypes) {
return trainerTypes.stream()
.map(trainerType -> biomePokemonTypeImageRepository.findPokemonTypeImageUrl(
BiomePokemonType.getBiomePokemonTypeByName(trainerType).name())
private List<BiomeTypeResponse> getTypesResponses(List<String> types) {
return types.stream()
.map(type -> new BiomeTypeResponse(biomePokemonTypeImageRepository.findPokemonTypeImageUrl(
BiomePokemonType.getBiomePokemonTypeByName(type).name()), type)
)
.toList();
}
Expand All @@ -140,8 +140,16 @@ private List<NextBiomeResponse> getNextBiomes(Biome biome) {
}

return biome.getNextBiome().stream()
.map(nextBiome -> NextBiomeResponse.of(biomeRepository.findById(nextBiome.getId())
.orElseThrow(() -> new GlobalCustomException(ErrorMessage.BIOME_NOT_FOUND)), nextBiome.getPercent()))
.map(nextBiomeInfo -> {
Biome nextBiome = biomeRepository.findById(nextBiomeInfo.getId())
.orElseThrow(() -> new GlobalCustomException(ErrorMessage.BIOME_NOT_FOUND));
return NextBiomeResponse.of(
nextBiome,
nextBiomeInfo.getPercent(),
getTypesResponses(nextBiome.getMainTypes()),
getTypesResponses(nextBiome.getTrainerTypes())
);
})
.toList();
}
}
2 changes: 1 addition & 1 deletion backend/pokerogue/src/main/resources

0 comments on commit cc4558d

Please sign in to comment.