Skip to content

Commit

Permalink
Merge branch 'be/develop' of https://github.com/woowacourse-teams/202…
Browse files Browse the repository at this point in the history
…4-pokerogue-helper into be/infra/#467-migrate-prod-db
  • Loading branch information
jongmee committed Nov 29, 2024
2 parents 5349762 + 5062795 commit d0d9d49
Show file tree
Hide file tree
Showing 19 changed files with 165 additions and 70 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package com.pokerogue.helper.ability.dto;

import com.pokerogue.helper.global.config.ImageUrl;
import com.pokerogue.helper.type.data.Type;

public record AbilityTypeResponse(String typeLogo, String typeName) {

public static AbilityTypeResponse from(Type type) {
return new AbilityTypeResponse(type.getImage(), type.getKoName());
return new AbilityTypeResponse(ImageUrl.getTypeImage(type.getName()), type.getKoName());
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.pokerogue.helper.battle.controller;

import com.pokerogue.helper.battle.dto.BattleResultResponse;
import com.pokerogue.helper.battle.dto.BattleResultResponseV1;
import com.pokerogue.helper.battle.dto.BattleResultResponseV2;
import com.pokerogue.helper.battle.dto.WeatherResponse;
import com.pokerogue.helper.battle.service.BattleService;
import com.pokerogue.helper.battle.service.WeatherService;
Expand All @@ -26,11 +27,20 @@ public ApiResponse<List<WeatherResponse>> weatherList() {
}

@GetMapping("/api/v1/battle")
public ApiResponse<BattleResultResponse> battleResult(@RequestParam("weather-id") String weatherId,
@RequestParam("my-pokemon-id") String myPokemonId,
@RequestParam("rival-pokemon-id") String rivalPokemonId,
@RequestParam("my-move-id") String myMoveId) {
public ApiResponse<BattleResultResponseV1> battleResultV1(@RequestParam("weather-id") String weatherId,
@RequestParam("my-pokemon-id") String myPokemonId,
@RequestParam("rival-pokemon-id") String rivalPokemonId,
@RequestParam("my-move-id") String myMoveId) {
return new ApiResponse<>("배틀 예측 결과 불러오기에 성공했습니다.",
battleService.calculateBattleResult(weatherId, myPokemonId, rivalPokemonId, myMoveId));
battleService.calculateBattleResultV1(weatherId, myPokemonId, rivalPokemonId, myMoveId));
}

@GetMapping("/api/v2/battle")
public ApiResponse<BattleResultResponseV2> battleResultV2(@RequestParam("weather-id") String weatherId,
@RequestParam("my-pokemon-id") String myPokemonId,
@RequestParam("rival-pokemon-id") String rivalPokemonId,
@RequestParam("my-move-id") String myMoveId) {
return new ApiResponse<>("배틀 예측 결과 불러오기에 성공했습니다.",
battleService.calculateBattleResultV2(weatherId, myPokemonId, rivalPokemonId, myMoveId));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.pokerogue.helper.battle.dto;

import com.pokerogue.helper.move.data.Move;
import com.pokerogue.helper.move.data.MoveCategory;
import com.pokerogue.helper.type.data.Type;

public record BattleResultResponseV1(
int power,
double multiplier,
double accuracy,
String moveName,
String moveDescription,
String moveType,
String moveCategory
) {
public static BattleResultResponseV1 from(Move move, double multiplier, double accuracy) {
Type moveType = move.getType();
MoveCategory moveCategory = move.getMoveCategory();

return new BattleResultResponseV1(
move.getPower(),
multiplier,
accuracy,
move.getName(),
move.getEffect(),
moveType.getKoName(),
moveCategory.getName()
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import com.pokerogue.helper.move.data.MoveCategory;
import com.pokerogue.helper.type.data.Type;

public record BattleResultResponse(
public record BattleResultResponseV2(
int power,
double multiplier,
double accuracy,
Expand All @@ -15,11 +15,11 @@ public record BattleResultResponse(
boolean isPreemptive
) {

public static BattleResultResponse from(Move move, double multiplier, double accuracy, boolean isPreemptive) {
public static BattleResultResponseV2 from(Move move, double multiplier, double accuracy, boolean isPreemptive) {
Type moveType = move.getType();
MoveCategory moveCategory = move.getMoveCategory();

return new BattleResultResponse(
return new BattleResultResponseV2(
move.getPower(),
multiplier,
accuracy,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package com.pokerogue.helper.battle.service;

import com.pokerogue.helper.battle.data.Weather;
import com.pokerogue.helper.battle.dto.BattleResultResponse;
import com.pokerogue.helper.battle.dto.BattleResultResponseV1;
import com.pokerogue.helper.battle.dto.BattleResultResponseV2;
import com.pokerogue.helper.global.exception.ErrorMessage;
import com.pokerogue.helper.global.exception.GlobalCustomException;
import com.pokerogue.helper.move.data.Move;
Expand All @@ -19,11 +20,37 @@ public class BattleService {
private final PokemonRepository pokemonRepository;
private final BattleCalculator battleCalculator;

public BattleResultResponse calculateBattleResult(
public BattleResultResponseV1 calculateBattleResultV1(
String weatherId,
String myPokemonId,
String rivalPokemonId,
String myMoveId) {
BattleResult battleResult = calculateBattleResult(weatherId, myPokemonId, rivalPokemonId, myMoveId);
return BattleResultResponseV1.from(battleResult.move, battleResult.totalMultiplier, battleResult.finalAccuracy);
}

public BattleResultResponseV2 calculateBattleResultV2(
String weatherId,
String myPokemonId,
String rivalPokemonId,
String myMoveId) {
BattleResult battleResult = calculateBattleResult(weatherId, myPokemonId, rivalPokemonId, myMoveId);
boolean isPreemptive = battleCalculator.decidePreemptiveAttack(battleResult.rivalPokemon, battleResult.myPokemon);

return BattleResultResponseV2.from(
battleResult.move,
battleResult.totalMultiplier,
battleResult.finalAccuracy,
isPreemptive
);
}

private BattleResult calculateBattleResult(
String weatherId,
String myPokemonId,
String rivalPokemonId,
String myMoveId
) {
Weather weather = Weather.findById(weatherId)
.orElseThrow(() -> new GlobalCustomException(ErrorMessage.WEATHER_NOT_FOUND));
Pokemon myPokemon = pokemonRepository.findById(myPokemonId)
Expand All @@ -35,8 +62,32 @@ public BattleResultResponse calculateBattleResult(

double finalAccuracy = battleCalculator.calculateAccuracy(move, weather);
double totalMultiplier = battleCalculator.calculateTotalMultiplier(move, weather, rivalPokemon, myPokemon);
boolean isPreemptive = battleCalculator.decidePreemptiveAttack(rivalPokemon, myPokemon);

return BattleResultResponse.from(move, totalMultiplier, finalAccuracy, isPreemptive);
return new BattleResult(weather, myPokemon, rivalPokemon, move, finalAccuracy, totalMultiplier);
}

private static class BattleResult {
Weather weather;
Pokemon myPokemon;
Pokemon rivalPokemon;
Move move;
double finalAccuracy;
double totalMultiplier;

BattleResult(
Weather weather,
Pokemon myPokemon,
Pokemon rivalPokemon,
Move move,
double finalAccuracy,
double totalMultiplier
) {
this.weather = weather;
this.myPokemon = myPokemon;
this.rivalPokemon = rivalPokemon;
this.move = move;
this.finalAccuracy = finalAccuracy;
this.totalMultiplier = totalMultiplier;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import com.pokerogue.helper.biome.dto.NextBiomeResponse;
import com.pokerogue.helper.biome.dto.TrainerPokemonResponse;
import com.pokerogue.helper.biome.repository.BiomeRepository;
import com.pokerogue.helper.global.config.ImageUrl;
import com.pokerogue.helper.global.constant.SortingCriteria;
import com.pokerogue.helper.global.exception.ErrorMessage;
import com.pokerogue.helper.global.exception.GlobalCustomException;
Expand Down Expand Up @@ -122,7 +123,7 @@ private List<BiomePokemonResponse> getBiomePokemons(List<String> biomePokemons)
private List<BiomeTypeResponse> getTypesResponses(List<Type> types) {
return types.stream()
.map(type -> new BiomeTypeResponse(
type.getImage(),
ImageUrl.getTypeImage(type.getName()),
type.getKoName())
)
.toList();
Expand All @@ -133,7 +134,7 @@ private List<BiomeTypeResponse> getTrainerTypesResponses(List<Trainer> trainers)
.map(Trainer::getTypes)
.flatMap(List::stream)
.map(type -> new BiomeTypeResponse(
type.getImage(),
ImageUrl.getTypeImage(type.getName()),
type.getKoName())
)
.toList();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
package com.pokerogue.helper.pokemon.config;
package com.pokerogue.helper.global.config;

public enum ImageUrl {

BASE_URL("https://dl70s9ccojnge.cloudfront.net/pokerogue-helper/pokerogue"),
BASE_URL("https://d11z3l5940xyw9.cloudfront.net/pokerogue"),
POKEMON_FRONT("/pokemon/front/"),
POKEMON_BACK("/pokemon/back/"),
TYPE("/type/"),
MOVE_CATEGORY("/move-category/"),
BIOME("/biome/"),
;

public static final String PNG = ".png";
private static final String PNG = ".png";
private final String url;

ImageUrl(String url) {
Expand All @@ -29,4 +29,11 @@ public static String getBiomeImage(String id) {
return BASE_URL.url + BIOME.url + id + PNG;
}

public static String getMoveCategoryImage(String id) {
return BASE_URL.url + MOVE_CATEGORY.url + id + PNG;
}

public static String getTypeImage(String id) {
return BASE_URL.url + TYPE.url + id;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,17 @@
@Getter
public enum MoveCategory {

STATUS("변화", "status", "https://dl70s9ccojnge.cloudfront.net/pokerogue-helper/pokerogue/move-category/status"),
SPECIAL("특수", "special",
"https://dl70s9ccojnge.cloudfront.net/pokerogue-helper/pokerogue/move-category/special"),
PHYSICAL("물리", "physical",
"https://dl70s9ccojnge.cloudfront.net/pokerogue-helper/pokerogue/move-category/physical"),
STATUS("변화", "status"),
SPECIAL("특수", "special"),
PHYSICAL("물리", "physical"),
;

private final String name;
private final String engName;
private final String image;

MoveCategory(String name, String engName, String image) {
MoveCategory(String name, String engName) {
this.name = name;
this.engName = engName;
this.image = image;
}

public static Optional<MoveCategory> findByEngName(String name) {
Expand All @@ -36,10 +32,6 @@ private boolean hasSameEngName(String name) {
return this.engName.equals(name);
}

public String getImage() {
return image + ".png";
}

public static MoveCategory convertFrom(String moveCategoryData) {
return findByEngName(moveCategoryData)
.orElseThrow(() -> new GlobalCustomException(ErrorMessage.MOVE_CATEGORY_NOT_FOUND));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.pokerogue.helper.move.dto;

import com.pokerogue.helper.global.config.ImageUrl;
import com.pokerogue.helper.move.data.Move;
import com.pokerogue.helper.move.data.MoveCategory;
import com.pokerogue.helper.move.data.MoveFlag;
Expand Down Expand Up @@ -38,9 +39,9 @@ public static MoveDetailResponse from(Move move, List<String> levelMoveIdsContai
move.getId(),
move.getKoName(),
type.getName(),
type.getImage(),
ImageUrl.getTypeImage(type.getName()),
moveCategory.getEngName(),
moveCategory.getImage(),
ImageUrl.getMoveCategoryImage(moveCategory.getEngName()),
move.getMoveTarget().getId(),
move.getPower(),
move.getAccuracy(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.pokerogue.helper.move.dto;

import com.pokerogue.helper.global.config.ImageUrl;
import com.pokerogue.helper.move.data.Move;
import com.pokerogue.helper.move.data.MoveCategory;
import com.pokerogue.helper.type.data.Type;
Expand All @@ -24,9 +25,9 @@ public static MoveResponse from(Move move) {
move.getId(),
move.getKoName(),
type.getName(),
type.getImage(),
ImageUrl.getTypeImage(type.getName()),
moveCategory.getEngName(),
moveCategory.getImage(),
ImageUrl.getMoveCategoryImage(moveCategory.getEngName()),
move.getPower(),
move.getAccuracy(),
move.getEffect()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.pokerogue.helper.pokemon.dto;

import com.pokerogue.helper.global.config.ImageUrl;
import com.pokerogue.helper.move.data.Move;
import com.pokerogue.helper.move.data.MoveCategory;
import com.pokerogue.helper.type.data.Type;
Expand Down Expand Up @@ -27,9 +28,9 @@ public static EggMoveResponse from(Move move) {
move.getPower(),
move.getAccuracy(),
type.getName(),
type.getImage(),
ImageUrl.getTypeImage(type.getName()),
moveCategory.getName(),
moveCategory.getImage()
ImageUrl.getMoveCategoryImage(moveCategory.getEngName())
);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.pokerogue.helper.pokemon.dto;


import com.pokerogue.helper.pokemon.config.ImageUrl;
import com.pokerogue.helper.global.config.ImageUrl;
import com.pokerogue.helper.pokemon.data.Evolution;
import com.pokerogue.helper.pokemon.data.Pokemon;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.pokerogue.helper.pokemon.dto;

import com.pokerogue.helper.biome.data.Biome;
import com.pokerogue.helper.pokemon.config.ImageUrl;
import com.pokerogue.helper.global.config.ImageUrl;

public record PokemonBiomeResponse(String id, String name, String image) {
public static PokemonBiomeResponse from(Biome biome) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.pokerogue.helper.pokemon.dto;

import com.pokerogue.helper.pokemon.config.ImageUrl;
import com.pokerogue.helper.global.config.ImageUrl;
import com.pokerogue.helper.pokemon.data.Pokemon;
import com.pokerogue.helper.type.dto.PokemonTypeResponse;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.pokerogue.helper.pokemon.dto;

import com.pokerogue.helper.global.config.ImageUrl;
import com.pokerogue.helper.move.data.Move;
import com.pokerogue.helper.move.data.MoveCategory;
import com.pokerogue.helper.type.data.Type;
Expand Down Expand Up @@ -27,9 +28,9 @@ public static PokemonMoveResponse from(Move move, Integer level) {
move.getPower(),
move.getAccuracy(),
moveType.getName(),
moveType.getImage(),
ImageUrl.getTypeImage(moveType.getName()),
moveCategory.getName(),
moveCategory.getImage()
ImageUrl.getMoveCategoryImage(moveCategory.getEngName())
);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.pokerogue.helper.pokemon.dto;

import com.pokerogue.helper.pokemon.config.ImageUrl;
import com.pokerogue.helper.global.config.ImageUrl;
import com.pokerogue.helper.pokemon.data.Pokemon;
import com.pokerogue.helper.type.dto.PokemonTypeResponse;
import java.util.List;
Expand Down
Loading

0 comments on commit d0d9d49

Please sign in to comment.