Add Steam API client, service, controller

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 5881dd0613
commit a1b11882de
6 files changed
+113 -3

No files matched your search

@@ -27,7 +27,8 @@ public class SecurityConfig {
"/internal/**", // Allow internal service communication
"/actuator/health",
"/actuator/prometheus",
"/error"
"/error",
"/api/steam/test/**"
};
private final JwtAuthenticationFilter jwtAuthFilter;
@@ -49,7 +50,7 @@ public class SecurityConfig {
}
@Bean
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
public SecurityFilterChain securityFilterChain(HttpSecurity http) {
http
.csrf(AbstractHttpConfigurer::disable)
.cors(cors -> cors.configurationSource(corsConfigurationSource()))
@@ -63,4 +64,4 @@ public class SecurityConfig {
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();
}
}
+1
View File
@@ -42,6 +42,7 @@ app:
allowed-origins: "https://tbp.andreas-dahm.eu"
steam:
api-key: ${STEAM_API_KEY}
base-url: https://api.steampowered.com
playerService-url: https://api.steampowered.com/IPlayerService/GetOwnedGames/v1/
storeService-url: https://api.steampowered.com/IStoreService/GetAppList/v1/
imageService-url: https://cdn.cloudflare.steamstatic.com/steam/apps/