Skip to content

Commit

Permalink
Remove ddragon profile
Browse files Browse the repository at this point in the history
This simplifies JSON mappings and configurations since Riot only supports Data Dragon.
  • Loading branch information
drumonii committed Sep 29, 2021
1 parent 0847803 commit f66dd42
Show file tree
Hide file tree
Showing 96 changed files with 466 additions and 1,464 deletions.
9 changes: 2 additions & 7 deletions backend/README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,12 @@ Development profile that also uses PostgreSQL with the url: `jdbc:postgresql://l
test::
Testing profile for https://junit.org/junit5/docs/current/user-guide/[JUnit 5] tests using H2.

In addition, there is one included Riot API profile:

ddragon::
Data Dragon

To override an active profile, set the `spring.profiles.active` argument property such as:

-Dspring.profiles.active=dev

Or using the environment variable `SPRING_PROFILES_ACTIVE`. Otherwise, if a profile is not specified, the `external`
and `ddragon` profiles will be active.
Or by using the environment variable `SPRING_PROFILES_ACTIVE`.
Otherwise, if a profile is not specified, the `external` profile will be active.

== Running the Backend locally
Create a run config that uses the `LeagueTrollBuildApplication` main class
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ interface LtbApi extends AllApis {}
/**
* View applicable to only Riot's ddragon API.
*/
interface RiotApi extends AllApis {}
interface RiotDdragonApi extends AllApis {}

}
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,6 @@ public class Profiles {
*/
public static final String EXTERNAL = "external";

/*
* Riot API profiles
*/

/**
* Profile for using Riot's {@code Data Dragon} API.
*/
public static final String DDRAGON = "ddragon";

/**
* Profile for local development.
*/
Expand Down Expand Up @@ -99,17 +90,4 @@ public class Profiles {
public @interface External {
}

/*
* Riot API profiles
*/

/**
* Indicates a {@code Data Dragon} API profile.
*/
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Profile(value = DDRAGON)
public @interface Ddragon {
}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.drumonii.loltrollbuild.config;

import com.drumonii.loltrollbuild.config.Profiles.Ddragon;
import com.drumonii.loltrollbuild.riot.api.RiotApiProperties;
import com.drumonii.loltrollbuild.riot.api.RiotClientHttpRequestInterceptor;
import com.fasterxml.jackson.databind.ObjectMapper;
Expand All @@ -24,171 +23,116 @@
@EnableConfigurationProperties(RiotApiProperties.class)
public class RiotApiConfig {

/**
* Configuration for the {@code Ddragon} {@link UriComponentsBuilder}s.
private final RiotApiProperties.Ddragon ddragon;

public RiotApiConfig(RiotApiProperties riotProperties) {
this.ddragon = riotProperties.getDdragon();
}

@Bean
public RestTemplate restTemplate(RestTemplateBuilder builder, ObjectMapper objectMapper) {
MappingJackson2HttpMessageConverter textJsonMappingJackson2HttpMessageConverter =
new MappingJackson2HttpMessageConverter(objectMapper);
textJsonMappingJackson2HttpMessageConverter.setSupportedMediaTypes(Arrays.asList(
MediaType.APPLICATION_JSON, MediaType.APPLICATION_OCTET_STREAM,
MediaType.parseMediaType("binary/octet-stream"), MediaType.parseMediaType("text/json;charset=UTF-8")));
return builder
.additionalMessageConverters(textJsonMappingJackson2HttpMessageConverter)
.additionalInterceptors(new RiotClientHttpRequestInterceptor())
.build();
}

/*
* JSON Uri Components
*/
@Configuration
@Ddragon
static class DdragonConfig {

private final RiotApiProperties riotProperties;

public DdragonConfig(RiotApiProperties riotProperties) {
this.riotProperties = riotProperties;
}

@Bean
public RestTemplate restTemplate(RestTemplateBuilder builder, ObjectMapper objectMapper) {
MappingJackson2HttpMessageConverter textJsonMappingJackson2HttpMessageConverter =
new MappingJackson2HttpMessageConverter(objectMapper);
textJsonMappingJackson2HttpMessageConverter.setSupportedMediaTypes(Arrays.asList(
MediaType.APPLICATION_JSON, MediaType.APPLICATION_OCTET_STREAM,
MediaType.parseMediaType("binary/octet-stream"), MediaType.parseMediaType("text/json;charset=UTF-8")));
return builder
.additionalMessageConverters(textJsonMappingJackson2HttpMessageConverter)
.additionalInterceptors(new RiotClientHttpRequestInterceptor())
.build();
}

/*
* Summoner Spells Uri Components
*/

@Bean
@Qualifier("summonerSpells")
public UriComponentsBuilder summonerSpellsUri() {
return UriComponentsBuilder.fromHttpUrl(riotProperties.getDdragon().getBaseUrl())
.path(riotProperties.getDdragon().getSummonerSpells());
}

/*
* Items Uri Components
*/

@Bean
@Qualifier("items")
public UriComponentsBuilder itemsUri() {
return UriComponentsBuilder.fromHttpUrl(riotProperties.getDdragon().getBaseUrl())
.path(riotProperties.getDdragon().getItems());
}

/*
* Champions Uri Components
*/

@Bean
@Qualifier("champions")
public UriComponentsBuilder championsUri() {
return UriComponentsBuilder.fromHttpUrl(riotProperties.getDdragon().getBaseUrl())
.path(riotProperties.getDdragon().getChampions());
}

/*
* Champions Uri Components
*/

@Bean
@Qualifier("champion")
public UriComponentsBuilder championUri() {
return UriComponentsBuilder.fromHttpUrl(riotProperties.getDdragon().getBaseUrl())
.path(riotProperties.getDdragon().getChampion());
}

/*
* Maps Uri Components
*/

@Bean
@Qualifier("maps")
public UriComponentsBuilder mapsUri() {
return UriComponentsBuilder.fromHttpUrl(riotProperties.getDdragon().getBaseUrl())
.path(riotProperties.getDdragon().getMaps());
}

/*
* Versions Uri Components
*/

@Bean
@Qualifier("versions")
public UriComponents versionsUri() {
return UriComponentsBuilder.fromHttpUrl(riotProperties.getDdragon().getBaseUrl())
.path(riotProperties.getDdragon().getVersions())
.buildAndExpand();
}

@Bean
@Qualifier("summonerSpells")
public UriComponentsBuilder summonerSpellsUri() {
return UriComponentsBuilder.fromHttpUrl(ddragon.getBaseUrl())
.path(ddragon.getSummonerSpells().replace("{locale}", ddragon.getLocale().toString()));
}

@Bean
@Qualifier("items")
public UriComponentsBuilder itemsUri() {
return UriComponentsBuilder.fromHttpUrl(ddragon.getBaseUrl())
.path(ddragon.getItems().replace("{locale}", ddragon.getLocale().toString()));
}

@Bean
@Qualifier("champions")
public UriComponentsBuilder championsUri() {
return UriComponentsBuilder.fromHttpUrl(ddragon.getBaseUrl())
.path(ddragon.getChampions().replace("{locale}", ddragon.getLocale().toString()));
}

@Bean
@Qualifier("champion")
public UriComponentsBuilder championUri() {
return UriComponentsBuilder.fromHttpUrl(ddragon.getBaseUrl())
.path(ddragon.getChampion().replace("{locale}", ddragon.getLocale().toString()));
}

@Bean
@Qualifier("maps")
public UriComponentsBuilder mapsUri() {
return UriComponentsBuilder.fromHttpUrl(ddragon.getBaseUrl())
.path(ddragon.getMaps().replace("{locale}", ddragon.getLocale().toString()));
}

/**
* Configuration for Data Dragon image {@link UriComponentsBuilder}.
@Bean
@Qualifier("versions")
public UriComponents versionsUri() {
return UriComponentsBuilder.fromHttpUrl(ddragon.getBaseUrl())
.path(ddragon.getVersions())
.buildAndExpand();
}

/*
* Image Uri Components
*/
@Configuration
static class DdragonImgConfig {

private final RiotApiProperties riotProperties;

public DdragonImgConfig(RiotApiProperties riotProperties) {
this.riotProperties = riotProperties;
}

/*
* Summoner Spells Img Uri Components
*/

@Bean
@Qualifier("summonerSpellsImg")
public UriComponentsBuilder summonerSpellImgUri() {
return UriComponentsBuilder.fromHttpUrl(riotProperties.getDdragon().getBaseUrl())
.path(riotProperties.getDdragon().getSummonerSpellsImg());
}

/*
* Items Img Uri Components
*/

@Bean
@Qualifier("itemsImg")
public UriComponentsBuilder itemsImgUri() {
return UriComponentsBuilder.fromHttpUrl(riotProperties.getDdragon().getBaseUrl())
.path(riotProperties.getDdragon().getItemsImg());
}

/*
* Champions Uri Components
*/

@Bean
@Qualifier("championsImg")
public UriComponentsBuilder championsImgUri() {
return UriComponentsBuilder.fromHttpUrl(riotProperties.getDdragon().getBaseUrl())
.path(riotProperties.getDdragon().getChampionsImg());
}

@Bean
@Qualifier("championsSpellImg")
public UriComponentsBuilder championsSpellImgUri() {
return UriComponentsBuilder.fromHttpUrl(riotProperties.getDdragon().getBaseUrl())
.path(riotProperties.getDdragon().getChampionsSpellImg());
}

@Bean
@Qualifier("championsPassiveImg")
public UriComponentsBuilder championsPassiveImgUri() {
return UriComponentsBuilder.fromHttpUrl(riotProperties.getDdragon().getBaseUrl())
.path(riotProperties.getDdragon().getChampionsPassiveImg());
}

/*
* Maps Uri Components
*/

@Bean
@Qualifier("mapsImg")
public UriComponentsBuilder mapsImgUri() {
return UriComponentsBuilder.fromHttpUrl(riotProperties.getDdragon().getBaseUrl())
.path(riotProperties.getDdragon().getMapsImg());
}

@Bean
@Qualifier("summonerSpellsImg")
public UriComponentsBuilder summonerSpellImgUri() {
return UriComponentsBuilder.fromHttpUrl(ddragon.getBaseUrl())
.path(ddragon.getSummonerSpellsImg());
}

@Bean
@Qualifier("itemsImg")
public UriComponentsBuilder itemsImgUri() {
return UriComponentsBuilder.fromHttpUrl(ddragon.getBaseUrl())
.path(ddragon.getItemsImg());
}

@Bean
@Qualifier("championsImg")
public UriComponentsBuilder championsImgUri() {
return UriComponentsBuilder.fromHttpUrl(ddragon.getBaseUrl())
.path(ddragon.getChampionsImg());
}

@Bean
@Qualifier("championsSpellImg")
public UriComponentsBuilder championsSpellImgUri() {
return UriComponentsBuilder.fromHttpUrl(ddragon.getBaseUrl())
.path(ddragon.getChampionsSpellImg());
}

@Bean
@Qualifier("championsPassiveImg")
public UriComponentsBuilder championsPassiveImgUri() {
return UriComponentsBuilder.fromHttpUrl(ddragon.getBaseUrl())
.path(ddragon.getChampionsPassiveImg());
}

@Bean
@Qualifier("mapsImg")
public UriComponentsBuilder mapsImgUri() {
return UriComponentsBuilder.fromHttpUrl(ddragon.getBaseUrl())
.path(ddragon.getMapsImg());
}

}

This file was deleted.

This file was deleted.

Loading

0 comments on commit f66dd42

Please sign in to comment.