From a150dd272d82e388e05b205b2cd85704f10f6823 Mon Sep 17 00:00:00 2001 From: yukudaa Date: Thu, 2 May 2024 16:34:02 +0900 Subject: [PATCH] =?UTF-8?q?[Feat]=20=EB=9D=BC=EC=9D=B4=EC=97=87=20?= =?UTF-8?q?=EC=A0=84=EC=A0=81=EA=B2=80=EC=83=89=20=EA=B8=B0=EB=8A=A5=20(#2?= =?UTF-8?q?1)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../application/riot/AccountService.java | 33 ++++++++++ .../application/riot/BasicRiotApiService.java | 31 ++++++++++ .../application/riot/ChampionDataService.java | 49 +++++++++++++++ .../application/riot/ChampionImgService.java | 22 +++++++ .../riot/ChampionMasteryService.java | 62 +++++++++++++++++++ .../application/riot/RecordService.java | 36 +++++++++++ .../application/riot/SummonerService.java | 50 +++++++++++++++ .../org/doochul/ui/RoitSearchController.java | 49 +++++++++++++++ .../java/org/doochul/ui/riot/dto/Account.java | 8 +++ .../org/doochul/ui/riot/dto/ChampionData.java | 15 +++++ .../doochul/ui/riot/dto/ChampionMastery.java | 11 ++++ .../org/doochul/ui/riot/dto/LeagueEntry.java | 11 ++++ .../doochul/ui/riot/dto/RecordMatchId.java | 6 ++ .../org/doochul/ui/riot/dto/Summoner.java | 12 ++++ 14 files changed, 395 insertions(+) create mode 100644 doochul/src/main/java/org/doochul/application/riot/AccountService.java create mode 100644 doochul/src/main/java/org/doochul/application/riot/BasicRiotApiService.java create mode 100644 doochul/src/main/java/org/doochul/application/riot/ChampionDataService.java create mode 100644 doochul/src/main/java/org/doochul/application/riot/ChampionImgService.java create mode 100644 doochul/src/main/java/org/doochul/application/riot/ChampionMasteryService.java create mode 100644 doochul/src/main/java/org/doochul/application/riot/RecordService.java create mode 100644 doochul/src/main/java/org/doochul/application/riot/SummonerService.java create mode 100644 doochul/src/main/java/org/doochul/ui/RoitSearchController.java create mode 100644 doochul/src/main/java/org/doochul/ui/riot/dto/Account.java create mode 100644 doochul/src/main/java/org/doochul/ui/riot/dto/ChampionData.java create mode 100644 doochul/src/main/java/org/doochul/ui/riot/dto/ChampionMastery.java create mode 100644 doochul/src/main/java/org/doochul/ui/riot/dto/LeagueEntry.java create mode 100644 doochul/src/main/java/org/doochul/ui/riot/dto/RecordMatchId.java create mode 100644 doochul/src/main/java/org/doochul/ui/riot/dto/Summoner.java diff --git a/doochul/src/main/java/org/doochul/application/riot/AccountService.java b/doochul/src/main/java/org/doochul/application/riot/AccountService.java new file mode 100644 index 0000000..c3340c3 --- /dev/null +++ b/doochul/src/main/java/org/doochul/application/riot/AccountService.java @@ -0,0 +1,33 @@ +package org.doochul.application.riot; + +import org.doochul.ui.riot.dto.Account; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpMethod; +import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Service; +import org.springframework.web.client.RestTemplate; + +@Service +public class AccountService { + @Value("${riot.api.key}") + private String API_KEY; + + public Account getAccountInfomation(String gameName, String tagLine) { + String api_url = "https://asia.api.riotgames.com/riot/account/v1/accounts/by-riot-id/" + gameName + "/" + tagLine; + HttpHeaders headers = new HttpHeaders(); + headers.set("X-Riot-Token", API_KEY); + + RestTemplate restTemplate = new RestTemplate(); + ResponseEntity response = restTemplate.exchange( + api_url, + HttpMethod.GET, + new HttpEntity<>(headers), + Account.class + + ); + Account account = response.getBody(); + return account; + } +} diff --git a/doochul/src/main/java/org/doochul/application/riot/BasicRiotApiService.java b/doochul/src/main/java/org/doochul/application/riot/BasicRiotApiService.java new file mode 100644 index 0000000..77b62bf --- /dev/null +++ b/doochul/src/main/java/org/doochul/application/riot/BasicRiotApiService.java @@ -0,0 +1,31 @@ +package org.doochul.application.riot; + +import org.springframework.core.ParameterizedTypeReference; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpMethod; +import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Service; +import org.springframework.web.client.RestTemplate; + +import java.util.List; + +@Service +public class BasicRiotApiService { + + public String getLatestLOLVersion() { + String api_url = "https://ddragon.leagueoflegends.com/api/versions.json"; + + RestTemplate restTemplate = new RestTemplate(); + ResponseEntity> response = restTemplate.exchange( + api_url, + HttpMethod.GET, + HttpEntity.EMPTY, + new ParameterizedTypeReference>() { + } + + ); + List versions = response.getBody(); + String latestVersion = versions.get(0); + return latestVersion; + } +} diff --git a/doochul/src/main/java/org/doochul/application/riot/ChampionDataService.java b/doochul/src/main/java/org/doochul/application/riot/ChampionDataService.java new file mode 100644 index 0000000..3a6f38c --- /dev/null +++ b/doochul/src/main/java/org/doochul/application/riot/ChampionDataService.java @@ -0,0 +1,49 @@ +package org.doochul.application.riot; + +import lombok.AllArgsConstructor; +import org.doochul.ui.riot.dto.ChampionData; +import org.springframework.core.ParameterizedTypeReference; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpMethod; +import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Service; +import org.springframework.web.client.RestTemplate; + +import java.util.Map; + +@Service +@AllArgsConstructor +public class ChampionDataService { + private final BasicRiotApiService basicRiotApiService; + + public ChampionData.Champion getChampionInfoByChampionId(String receivedChampionKey) { + if(receivedChampionKey == null) { + receivedChampionKey = "266"; + } + + String latestLOLVersion = basicRiotApiService.getLatestLOLVersion(); + + String api_url = "https://ddragon.leagueoflegends.com/cdn/"+ latestLOLVersion +"/data/ko_KR/champion.json"; + + RestTemplate restTemplate = new RestTemplate(); + ResponseEntity response = restTemplate.exchange( + api_url, + HttpMethod.GET, + HttpEntity.EMPTY, + new ParameterizedTypeReference() {} + + ); + + ChampionData championData = response.getBody(); + + Map championMappingMap = championData.data(); + + for (ChampionData.Champion value : championMappingMap.values()) { + if (value.key().equals(receivedChampionKey)) { + return value; + } + + } + return null; + } +} diff --git a/doochul/src/main/java/org/doochul/application/riot/ChampionImgService.java b/doochul/src/main/java/org/doochul/application/riot/ChampionImgService.java new file mode 100644 index 0000000..66245cb --- /dev/null +++ b/doochul/src/main/java/org/doochul/application/riot/ChampionImgService.java @@ -0,0 +1,22 @@ +package org.doochul.application.riot; + +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +@Service +@RequiredArgsConstructor +public class ChampionImgService { + + private final BasicRiotApiService basicRiotApiService; + + public String getChampionPortraitImgURLByChampionName(String championName) { + if(championName == null) { + return "https://ddragon.leagueoflegends.com/cdn/13.24.1/img/champion/Teemo.png"; + } + String latestLOLVersion = basicRiotApiService.getLatestLOLVersion(); + String api_url = "https://ddragon.leagueoflegends.com/cdn/" + +latestLOLVersion+"/img/champion/"+championName+".png"; + return api_url; + } +} + diff --git a/doochul/src/main/java/org/doochul/application/riot/ChampionMasteryService.java b/doochul/src/main/java/org/doochul/application/riot/ChampionMasteryService.java new file mode 100644 index 0000000..57f4597 --- /dev/null +++ b/doochul/src/main/java/org/doochul/application/riot/ChampionMasteryService.java @@ -0,0 +1,62 @@ +package org.doochul.application.riot; + +import org.doochul.ui.riot.dto.ChampionMastery; +import org.doochul.ui.riot.dto.LeagueEntry; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.core.ParameterizedTypeReference; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpMethod; +import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Service; +import org.springframework.web.client.RestTemplate; + +import java.util.List; + +@Service +public class ChampionMasteryService { + + @Value("${riot.api.key}") + private String API_KEY; + + public List getChampionMasteryInformationsByPUUID(String PUUID, Integer count) { + if (count == null) { + count = 3; + } + String api_url = "https://kr.api.riotgames.com/lol/champion-mastery/" + + "v4/champion-masteries/by-puuid/" + PUUID + "/top?count=" + Integer.toString(count); + + HttpHeaders headers = new HttpHeaders(); + headers.set("X-Riot-Token", API_KEY); + + RestTemplate restTemplate = new RestTemplate(); + ResponseEntity> response = restTemplate.exchange( + api_url, + HttpMethod.GET, + new HttpEntity<>(headers), + new ParameterizedTypeReference>() { + } + ); + List championMasteryDTOList = response.getBody(); + return championMasteryDTOList; + } + + // 티어 + public List getUserTear(String encryptedSummonerId) { + String api_url = "https://kr.api.riotgames.com/lol/league/v4/entries/by-summoner/" + encryptedSummonerId; + HttpHeaders headers = new HttpHeaders(); + headers.set("X-Riot-Token", API_KEY); + + RestTemplate restTemplate = new RestTemplate(); + ResponseEntity> response = restTemplate.exchange( + api_url, + HttpMethod.GET, + new HttpEntity<>(headers), + new ParameterizedTypeReference>() { + } + ); + List LeagueEntryList = response.getBody(); + return LeagueEntryList; + + } +} diff --git a/doochul/src/main/java/org/doochul/application/riot/RecordService.java b/doochul/src/main/java/org/doochul/application/riot/RecordService.java new file mode 100644 index 0000000..5a9ab72 --- /dev/null +++ b/doochul/src/main/java/org/doochul/application/riot/RecordService.java @@ -0,0 +1,36 @@ +package org.doochul.application.riot; + +import org.springframework.beans.factory.annotation.Value; +import org.springframework.core.ParameterizedTypeReference; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpMethod; +import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Service; +import org.springframework.web.client.RestTemplate; + +@Service +public class RecordService { + + @Value("${riot.api.key}") + private String API_KEY; + + // matchId 가져오기 + public String[] getMatchId(String puuid, Integer count) { + String api_url = "https://asia.api.riotgames.com/lol/match/v5/matches/by-puuid/" + puuid + "/ids?start=0&count=" + count + "&api_key=" + API_KEY; + HttpHeaders headers = new HttpHeaders(); + headers.set("X-Riot-Token", API_KEY); + RestTemplate restTemplate = new RestTemplate(); + ResponseEntity response = restTemplate.exchange( + api_url, + HttpMethod.GET, + new HttpEntity<>(headers), + new ParameterizedTypeReference() { + } + ); + String match = response.getBody().replaceAll("\\[|\\]", ""); + String[] matchId = match.split(","); + return matchId; + + } +} diff --git a/doochul/src/main/java/org/doochul/application/riot/SummonerService.java b/doochul/src/main/java/org/doochul/application/riot/SummonerService.java new file mode 100644 index 0000000..f9deddf --- /dev/null +++ b/doochul/src/main/java/org/doochul/application/riot/SummonerService.java @@ -0,0 +1,50 @@ +package org.doochul.application.riot; + +import org.doochul.ui.riot.dto.Summoner; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpMethod; +import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Service; +import org.springframework.web.client.RestTemplate; + +@Service +public class SummonerService { + + private final BasicRiotApiService basicRiotApiService; + + @Value("${riot.api.key}") + private String API_KEY; + + public SummonerService(BasicRiotApiService basicRiotApiService) { + this.basicRiotApiService = basicRiotApiService; + } + + public Summoner getSummonerInformationByPUUID(String PUUID) { + String api_url = "https://kr.api.riotgames.com/lol/summoner/v4/summoners/by-puuid/" + PUUID; + HttpHeaders headers = new HttpHeaders(); + headers.set("X-Riot-Token", API_KEY); + + RestTemplate restTemplate = new RestTemplate(); + ResponseEntity response = restTemplate.exchange( + api_url, + HttpMethod.GET, + new HttpEntity<>(headers), + Summoner.class + ); + Summoner summoner = response.getBody(); + return summoner; + } + + public String getSummonerProfileIcon(Integer profileIconID) { + String latestVersion = basicRiotApiService.getLatestLOLVersion(); + if (profileIconID == null) { + profileIconID = 1; + } + String url = "https://ddragon.leagueoflegends.com/cdn/" + latestVersion + "/img/profileicon/" + Integer.toString(profileIconID) + ".png"; + return url; + } + + +} \ No newline at end of file diff --git a/doochul/src/main/java/org/doochul/ui/RoitSearchController.java b/doochul/src/main/java/org/doochul/ui/RoitSearchController.java new file mode 100644 index 0000000..1742dae --- /dev/null +++ b/doochul/src/main/java/org/doochul/ui/RoitSearchController.java @@ -0,0 +1,49 @@ +package org.doochul.ui; + +import lombok.AllArgsConstructor; +import org.doochul.application.riot.*; + +import org.doochul.ui.riot.dto.Account; +import org.doochul.ui.riot.dto.Summoner; +import org.doochul.ui.riot.dto.ChampionMastery; +import org.doochul.ui.riot.dto.ChampionData; +import org.doochul.ui.riot.dto.LeagueEntry; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestParam; + +import java.util.List; + +@Controller +@AllArgsConstructor +public class RoitSearchController { + + private final AccountService accountService; + private final SummonerService summonerService; + private final ChampionMasteryService championMasteryService; + private final ChampionDataService championDataService; + private final ChampionImgService championImgService; + private final RecordService recordService; + + @GetMapping("/search") + public String search(@RequestParam String gameName, @RequestParam("tagLine") String tagLine) { + Account account = accountService.getAccountInfomation(gameName, tagLine); + + Summoner summoner = summonerService.getSummonerInformationByPUUID(account.puuid()); + + List championMasteryList = championMasteryService.getChampionMasteryInformationsByPUUID(account.puuid(), 5); + for (ChampionMastery championMasteryEach : championMasteryList) { + ChampionData.Champion champion = championDataService.getChampionInfoByChampionId(Long.toString( + championMasteryEach.championId())); + + championMasteryEach.championName(champion.name()); + championMasteryEach.championPortraitImgURL(championImgService.getChampionPortraitImgURLByChampionName(champion.id())); + } + + List leagueEntryDtoList = championMasteryService.getUserTear(summoner.id()); + String[] matchId = recordService.getMatchId(account.puuid(), 5); + + + return "search"; + } +} diff --git a/doochul/src/main/java/org/doochul/ui/riot/dto/Account.java b/doochul/src/main/java/org/doochul/ui/riot/dto/Account.java new file mode 100644 index 0000000..2bdb14e --- /dev/null +++ b/doochul/src/main/java/org/doochul/ui/riot/dto/Account.java @@ -0,0 +1,8 @@ +package org.doochul.ui.riot.dto; + +public record Account ( + String puuid, + String gameName, + String tagLine +){ +} diff --git a/doochul/src/main/java/org/doochul/ui/riot/dto/ChampionData.java b/doochul/src/main/java/org/doochul/ui/riot/dto/ChampionData.java new file mode 100644 index 0000000..186f390 --- /dev/null +++ b/doochul/src/main/java/org/doochul/ui/riot/dto/ChampionData.java @@ -0,0 +1,15 @@ +package org.doochul.ui.riot.dto; + +import java.util.Map; + +public record ChampionData( + Map data +) { + public record Champion( + String id, + String key, + String name, + String title + ) { + } +} diff --git a/doochul/src/main/java/org/doochul/ui/riot/dto/ChampionMastery.java b/doochul/src/main/java/org/doochul/ui/riot/dto/ChampionMastery.java new file mode 100644 index 0000000..e4b7a8e --- /dev/null +++ b/doochul/src/main/java/org/doochul/ui/riot/dto/ChampionMastery.java @@ -0,0 +1,11 @@ +package org.doochul.ui.riot.dto; + +public record ChampionMastery( + + Long championId, + Integer championLevel, + Integer championPoints, + String championName, + String championPortraitImgURL +) { +} diff --git a/doochul/src/main/java/org/doochul/ui/riot/dto/LeagueEntry.java b/doochul/src/main/java/org/doochul/ui/riot/dto/LeagueEntry.java new file mode 100644 index 0000000..6e9952c --- /dev/null +++ b/doochul/src/main/java/org/doochul/ui/riot/dto/LeagueEntry.java @@ -0,0 +1,11 @@ +package org.doochul.ui.riot.dto; + +public record LeagueEntry ( + String leagueId, + String queueType, + String tier, + String rank, + String summonerId, + String summonerName +){ +} diff --git a/doochul/src/main/java/org/doochul/ui/riot/dto/RecordMatchId.java b/doochul/src/main/java/org/doochul/ui/riot/dto/RecordMatchId.java new file mode 100644 index 0000000..7889de5 --- /dev/null +++ b/doochul/src/main/java/org/doochul/ui/riot/dto/RecordMatchId.java @@ -0,0 +1,6 @@ +package org.doochul.ui.riot.dto; + +public record RecordMatchId( + String matchId +) { +} diff --git a/doochul/src/main/java/org/doochul/ui/riot/dto/Summoner.java b/doochul/src/main/java/org/doochul/ui/riot/dto/Summoner.java new file mode 100644 index 0000000..324d12c --- /dev/null +++ b/doochul/src/main/java/org/doochul/ui/riot/dto/Summoner.java @@ -0,0 +1,12 @@ +package org.doochul.ui.riot.dto; + +public record Summoner( + String accountId, + Long revisionDate, + String id, + String puuid, + String name, + Long summonerLevel, + Integer profileIconId +) { +}