Add Steam API client, service, controller
Build, Test & Push Core Service / quality-check (push) Successful in 9s
Build, Test & Push Core Service / docker (push) Successful in 1m44s

Introduce Steam integration: add SteamClientConfig (RestClient bean), SteamApiService (calls GetPlayerSummaries and returns a Player DTO), SteamPlayerSummaryResponse DTO, and SteamTestController (/api/steam/test/{steamId}) for quick testing. Update SecurityConfig to permit the test endpoint and adjust the SecurityFilterChain bean signature. Add Steam API settings: base-url in application.yml and a dev API key in application-dev.yml. Includes basic error logging and optional response handling when no player is found.
This commit is contained in:
lobo committed 2026-04-19 11:38:31 +02:00
1 parent 04dcab45da
commit bba756728d
7 files changed
+116 -7

No files matched your search

@@ -27,7 +27,8 @@ public class SecurityConfig {
"/internal/**", // Allow internal service communication "/internal/**", // Allow internal service communication
"/actuator/health", "/actuator/health",
"/actuator/prometheus", "/actuator/prometheus",
"/error" "/error",
"/api/steam/test/**"
}; };
private final JwtAuthenticationFilter jwtAuthFilter; private final JwtAuthenticationFilter jwtAuthFilter;
@@ -49,7 +50,7 @@ public class SecurityConfig {
} }
@Bean @Bean
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception { public SecurityFilterChain securityFilterChain(HttpSecurity http) {
http http
.csrf(AbstractHttpConfigurer::disable) .csrf(AbstractHttpConfigurer::disable)
.cors(cors -> cors.configurationSource(corsConfigurationSource())) .cors(cors -> cors.configurationSource(corsConfigurationSource()))
@@ -63,4 +64,4 @@ public class SecurityConfig {
return http.build(); return http.build();
} }
} }
@@ -0,0 +1,16 @@
package core_service.domain.steam_adapter.config;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.client.RestClient;
@Configuration
public class SteamClientConfig {
@Bean
public RestClient steamRestClient(@Value("${app.steam.base-url}") String baseUrl) {
return RestClient.builder()
.baseUrl(baseUrl)
.build();
}
}
@@ -0,0 +1,32 @@
package core_service.domain.steam_adapter.controller;
import core_service.domain.steam_adapter.controller.dto.response.SteamPlayerSummaryResponse;
import core_service.domain.steam_adapter.service.SteamApiService;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.Optional;
@RestController
@RequestMapping("/api/steam/test")
@RequiredArgsConstructor
public class SteamTestController {
private final SteamApiService steamApiService;
@GetMapping("/{steamId}")
public ResponseEntity<?> testSteamConnection(@PathVariable String steamId) {
Optional<SteamPlayerSummaryResponse.Player> playerOpt = steamApiService.getPlayerSummary(steamId);
if (playerOpt.isPresent()) {
return ResponseEntity.ok(playerOpt.get());
} else {
return ResponseEntity.notFound().build();
}
}
}
@@ -0,0 +1,15 @@
package core_service.domain.steam_adapter.controller.dto.response;
import java.util.List;
public record SteamPlayerSummaryResponse(SteamResponse response) {
public record SteamResponse(List<Player> players) {}
public record Player(
String steamid,
String personaname,
String profileurl,
String avatarfull
) {}
}
@@ -0,0 +1,45 @@
package core_service.domain.steam_adapter.service;
import core_service.domain.steam_adapter.controller.dto.response.SteamPlayerSummaryResponse;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestClient;
import java.util.Optional;
@Slf4j
@Service
@RequiredArgsConstructor
public class SteamApiService {
private final RestClient steamRestClient;
@Value("${app.steam.api-key}")
private String apiKey;
public Optional<SteamPlayerSummaryResponse.Player> getPlayerSummary(String steamId) {
try {
log.info("Fetching Steam profile for SteamID: {}", steamId);
SteamPlayerSummaryResponse response = steamRestClient.get()
.uri(uriBuilder -> uriBuilder
.path("/ISteamUser/GetPlayerSummaries/v0002/")
.queryParam("key", apiKey)
.queryParam("steamids", steamId)
.build())
.retrieve()
.body(SteamPlayerSummaryResponse.class);
if (response != null && response.response() != null && !response.response().players().isEmpty()) {
return Optional.of(response.response().players().get(0));
}
} catch (Exception e) {
log.error("Error communicating with Steam API for SteamID: {}", steamId, e);
}
return Optional.empty();
}
}
+3 -4
View File
@@ -7,7 +7,8 @@ app:
cors: cors:
# Local development: allow all origins to prevent CORS issues # Local development: allow all origins to prevent CORS issues
allowed-origins: "*" allowed-origins: "*"
steam:
api-key: "54EF220BF9A9BF849DB4E33FC4B0FDA3"
# Optional: Make SQL logs visible for debugging # Optional: Make SQL logs visible for debugging
spring: spring:
jpa: jpa:
@@ -15,6 +16,4 @@ spring:
security: security:
jwt: jwt:
secret: "NzC9tQP1eTp496SxoVYslH1bqn81Tbfz74NjkFqdcVe7wayjcRN8IeZvJWd1s6NEWgwEXe9rdccvOn2HtJ4fdq" secret: "NzC9tQP1eTp496SxoVYslH1bqn81Tbfz74NjkFqdcVe7wayjcRN8IeZvJWd1s6NEWgwEXe9rdccvOn2HtJ4fdq"
steam:
api-key: "54EF220BF9A9BF849DB4E33FC4B0FDA3"
+1
View File
@@ -42,6 +42,7 @@ app:
allowed-origins: "https://tbp.andreas-dahm.eu" allowed-origins: "https://tbp.andreas-dahm.eu"
steam: steam:
api-key: ${STEAM_API_KEY} api-key: ${STEAM_API_KEY}
base-url: https://api.steampowered.com
playerService-url: https://api.steampowered.com/IPlayerService/GetOwnedGames/v1/ playerService-url: https://api.steampowered.com/IPlayerService/GetOwnedGames/v1/
storeService-url: https://api.steampowered.com/IStoreService/GetAppList/v1/ storeService-url: https://api.steampowered.com/IStoreService/GetAppList/v1/
imageService-url: https://cdn.cloudflare.steamstatic.com/steam/apps/ imageService-url: https://cdn.cloudflare.steamstatic.com/steam/apps/