Skip to content

Commit

Permalink
#11 Set query parameter 'game_biz' properly; Also add Honkai Impact f…
Browse files Browse the repository at this point in the history
…iltering.
  • Loading branch information
binchoo committed Jun 27, 2022
1 parent a8451b2 commit f79f9a2
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class UidSearchClientAdapter implements UidSearchClientPort {
@Override
public List<Uid> findUids(Hoyopass hoyopass) {
LtuidLtoken ltuidLtoken = getLtuidLtoken(hoyopass);
List<UserGameRole> userGameRoles = requestUserGameRoles(hoyopass, ltuidLtoken).getList();
List<UserGameRole> userGameRoles = requestUserGameRoles(hoyopass, ltuidLtoken);
return mapUserGameRoleToUid(userGameRoles, ltuidLtoken);
}

Expand All @@ -40,9 +40,11 @@ public List<Uid> findUids(Hoyopass hoyopass) {
* @throws IllegalArgumentException 통행증이 유효하지 않아 UID를 조회할 수 없었을 경우,
* <p> API 응답에서 null 데이터가 담겨 {@link NullPointerException}을 받았을 경우.
*/
private UserGameRoles requestUserGameRoles(Hoyopass hoyopass, LtuidLtoken ltuidLtoken) {
private List<UserGameRole> requestUserGameRoles(Hoyopass hoyopass, LtuidLtoken ltuidLtoken) {
try {
return accountApi.getUserGameRoles(ltuidLtoken).getData();
var userGameRoles = accountApi.getUserGameRoles(ltuidLtoken).getData().getList();
log.info("UserGameRoles: {}", userGameRoles);
return userGameRoles;
} catch (RetcodeException e) {
throw new IllegalArgumentException(
String.format("UID를 조회할 수 없는 통행증입니다: %s", hoyopass), e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ void givenValidHoyopass_findUids_returnsMatchingUids() {

var uids = uidSearchClientAdapter.findUids(validHoyopass);

assertThat(uids).hasSameSizeAs(userGameRoles);
assertThat(userGameRoles).hasSameSizeAs(uids);
IntStream.range(0, uids.size()).forEach (i-> {
var uid = uids.get(i);
var ugr = userGameRoles.get(i);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import org.binchoo.paimonganyu.hoyoapi.pojo.enums.HoyoGame;

@ToString
@Setter
Expand All @@ -22,6 +23,6 @@ public class UserGameRole {
boolean isOfficial;

public boolean isGenshinImpactRole() {
return gameBiz.equals("hk4e_global");
return HoyoGame.GENSHIN_IMPACT.gameBizEquals(gameBiz);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,39 @@
* @since : 2022-06-16
*/
public enum HoyoGame {
HONKAI_IMPACT(1), GENSHIN_IMPACT(2);

HONKAI_IMPACT(1, GameBiz.bh3_global),
GENSHIN_IMPACT(2, GameBiz.hk4e_global);

private int id;
private GameBiz gameBiz;

HoyoGame(int id) {
HoyoGame(int id, GameBiz gameBiz) {
this.id = id;
this.gameBiz = gameBiz;
}

public int gameId() {
return id;
return this.id;
}

public GameBiz gameBiz() {
return this.gameBiz;
}

public String gameBizString() {
return this.gameBiz.toString();
}

public boolean gameBizEquals(String gameBiz) {
return gameBiz.equalsIgnoreCase(this.gameBiz.toString());
}

public boolean gameBizEquals(GameBiz gameBiz) {
return gameBiz.equals(this.gameBiz);
}

public enum GameBiz {
hk4e_global, bh3_global;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@
import org.binchoo.paimonganyu.hoyoapi.pojo.HoyoResponse;
import org.binchoo.paimonganyu.hoyoapi.pojo.LtuidLtoken;
import org.binchoo.paimonganyu.hoyoapi.pojo.UserGameRoles;
import org.binchoo.paimonganyu.hoyoapi.pojo.enums.HoyoGame;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Component;
import org.springframework.web.reactive.function.client.WebClient;

import java.util.Collections;

import static org.binchoo.paimonganyu.hoyoapi.HoyolabConstant.*;

@Component
Expand All @@ -27,7 +26,6 @@ public class HoyolabAccountWebClient implements HoyolabAccountApi {
public HoyolabAccountWebClient() {
this.webClient = WebClient.builder()
.baseUrl(getBaseUrl())
.defaultUriVariables(Collections.singletonMap(PARAM_GAME_BIZ, "hk4e_global"))
.build();
}

Expand All @@ -38,7 +36,9 @@ public HoyolabAccountWebClient() {
@Override
public HoyoResponse<UserGameRoles> getUserGameRoles(LtuidLtoken ltuidLtoken) {
ResponseEntity<HoyoResponse<UserGameRoles>> response = webClient.get()
.uri(GET_USER_GAME_ROLE_URL)
.uri(uriBuilder -> uriBuilder.path(GET_USER_GAME_ROLE_URL)
.queryParam(PARAM_GAME_BIZ, HoyoGame.GENSHIN_IMPACT.gameBizString())
.build())
.cookie(COOKIE_LTOKEN, ltuidLtoken.getLtoken())
.cookie(COOKIE_LTUID, ltuidLtoken.getLtuid())
.retrieve()
Expand All @@ -58,6 +58,7 @@ public HoyoResponse<UserGameRoles> getUserGameRoleByRegion(LtuidLtoken ltuidLtok
.uri(uriBuilder -> uriBuilder
.path(GET_USER_GAME_ROLE_URL)
.queryParam(PARAM_REGION, region)
.queryParam(PARAM_GAME_BIZ, HoyoGame.GENSHIN_IMPACT.gameBizString())
.build())
.cookie(COOKIE_LTOKEN, ltuidLtoken.getLtoken())
.cookie(COOKIE_LTUID, ltuidLtoken.getLtuid())
Expand Down

0 comments on commit f79f9a2

Please sign in to comment.