Refactor API structure and enhance logging/debugging.
Modularized OpenAPI definitions by splitting into dedicated files for teams, bans, and errors. Improved backend logging for database connections, CORS configuration, and debugging. Updated application properties to support environment-specific CORS origins and logging levels.
This commit is contained in:
parent
23f298b8c9
commit
2137459e9b
|
|
@ -13,12 +13,9 @@ public class CorsConfig implements WebMvcConfigurer {
|
|||
@Value("${cors.allowed-origins}")
|
||||
private String[] allowedOrigins;
|
||||
|
||||
public CorsConfig() {
|
||||
log.info("test");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addCorsMappings(CorsRegistry registry) {
|
||||
log.info("Registering CORS mappings for {}", String.join(", ", allowedOrigins));
|
||||
registry.addMapping("/**")
|
||||
.allowedOrigins(allowedOrigins)
|
||||
.allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS")
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ public class TeamApiController implements TeamApi {
|
|||
Connection.getConnection(Databases.LUCK_PERMS, configuration -> configuration.addMapper(TeamMemberMapper.class))
|
||||
.thenApply(connection -> {
|
||||
connection.runQuery(sqlSession -> {
|
||||
log.info("Loading team members for group {}", group);
|
||||
log.debug("Loading team members for group {}", group);
|
||||
List<Player> players = sqlSession.getMapper(TeamMemberMapper.class).getTeamMembers("group." + group);
|
||||
playerGroupFuture.complete(players);
|
||||
});
|
||||
|
|
|
|||
8
backend/src/main/resources/application-test.properties
Normal file
8
backend/src/main/resources/application-test.properties
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
spring.application.name=AltitudeWeb
|
||||
database.name=${DB_NAME:web_db}
|
||||
database.port=${DB_PORT:3306}
|
||||
database.host=${DB_HOST:localhost}
|
||||
database.user=${DB_USER:root}
|
||||
database.password=${DB_PASSWORD:root}
|
||||
cors.allowed-origins=${CORS:http://localhost:4200}
|
||||
logging.level.com.alttd.altitudeweb=DEBUG
|
||||
|
|
@ -4,4 +4,5 @@ database.port=${DB_PORT:3306}
|
|||
database.host=${DB_HOST:localhost}
|
||||
database.user=${DB_USER:root}
|
||||
database.password=${DB_PASSWORD:root}
|
||||
cors.allowed-origins=${CORS:http://localhost:4200}
|
||||
cors.allowed-origins=${CORS:https://alttd.com}
|
||||
logging.level.com.alttd.altitudeweb=INFO
|
||||
|
|
|
|||
|
|
@ -42,16 +42,20 @@ public class Connection {
|
|||
}
|
||||
CompletableFuture<DatabaseSettings> settingsFuture = new CompletableFuture<>();
|
||||
getConnection(Databases.DEFAULT, (mapper -> mapper.addMapper(SettingsMapper.class))).thenApply(connection -> {
|
||||
log.debug("Loading settings for database {}", database.getInternalName());
|
||||
connection.runQuery(session -> {
|
||||
log.debug("Running query to load settings for database");
|
||||
DatabaseSettings loadedSettings = session.getMapper(SettingsMapper.class).getSettings(database.getInternalName());
|
||||
if (loadedSettings == null) {
|
||||
log.error("Failed to load settings for database {}", database.getInternalName());
|
||||
}
|
||||
log.debug("Loaded settings {}", loadedSettings);
|
||||
settingsFuture.complete(loadedSettings);
|
||||
});
|
||||
return null;
|
||||
});
|
||||
return settingsFuture.thenApply(loadedSettings -> {
|
||||
log.debug("Storing connection for database {}", database.getInternalName());
|
||||
Connection connection = new Connection(loadedSettings, addMappers);
|
||||
connections.put(database, connection);
|
||||
return connection;
|
||||
|
|
@ -66,7 +70,9 @@ public class Connection {
|
|||
System.getenv("DB_USER"),
|
||||
System.getenv("DB_PASS")
|
||||
);
|
||||
log.debug("Loaded default database settings {}", databaseSettings);
|
||||
Connection connection = new Connection(databaseSettings, addMappers);
|
||||
log.debug("Created default database connection {}", connection);
|
||||
return CompletableFuture.completedFuture(connection);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,10 +1,12 @@
|
|||
import {Component} from '@angular/core';
|
||||
import {ScrollService} from '../scroll/scroll.service';
|
||||
import {BASE_PATH, Player, TeamService} from '../../api';
|
||||
import {BASE_PATH} from '../../api';
|
||||
import {CommonModule, NgOptimizedImage} from '@angular/common';
|
||||
import {HeaderComponent} from '../header/header.component';
|
||||
import {CookieService} from 'ngx-cookie-service';
|
||||
import {map, Observable, shareReplay} from 'rxjs';
|
||||
import {TeamService} from '../../api/api/team.service';
|
||||
import {Player} from '../../api/model/player';
|
||||
|
||||
@Component({
|
||||
selector: 'app-team',
|
||||
|
|
|
|||
|
|
@ -10,96 +10,7 @@ tags:
|
|||
- name: player
|
||||
description: Retrieve player information
|
||||
paths:
|
||||
/player/teamMembers/{group}:
|
||||
get:
|
||||
tags:
|
||||
- team
|
||||
summary: Get team members
|
||||
description: Retrieve players who are part of the specified team
|
||||
operationId: getTeamMembers
|
||||
parameters:
|
||||
- name: group
|
||||
in: path
|
||||
required: true
|
||||
description: The group name of the team
|
||||
schema:
|
||||
type: string
|
||||
responses:
|
||||
'200':
|
||||
description: successful operation
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/TeamMembers'
|
||||
default:
|
||||
description: Unexpected error
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: "#/components/schemas/Error"
|
||||
/player/history:
|
||||
post:
|
||||
tags:
|
||||
- user
|
||||
summary: Get player history
|
||||
description: Retrieves all types of player history about the player
|
||||
operationId: getPlayerHistory
|
||||
requestBody:
|
||||
description: The player history
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/Player'
|
||||
responses:
|
||||
'200':
|
||||
description: successful operation
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/PlayerHistory'
|
||||
default:
|
||||
description: Unexpected error
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: "#/components/schemas/Error"
|
||||
components:
|
||||
schemas:
|
||||
PlayerHistory:
|
||||
type: object
|
||||
properties:
|
||||
punishmentType:
|
||||
type: string
|
||||
punishment:
|
||||
type: string
|
||||
active:
|
||||
type: boolean
|
||||
start:
|
||||
type: integer
|
||||
format: int64
|
||||
duration:
|
||||
type: integer
|
||||
format: int64
|
||||
TeamMembers:
|
||||
type: array
|
||||
items:
|
||||
$ref: '#/components/schemas/Player'
|
||||
Player:
|
||||
type: object
|
||||
properties:
|
||||
name:
|
||||
type: string
|
||||
description: The name of the player
|
||||
example: a_name
|
||||
uuid:
|
||||
type: string
|
||||
example: 0c35e520-927e-4c6a-87ad-ff0739c22e9d
|
||||
description: The uuid of the team player
|
||||
required:
|
||||
- name
|
||||
- uuid
|
||||
Error:
|
||||
type: object
|
||||
properties:
|
||||
reason:
|
||||
type: string
|
||||
/team:
|
||||
$ref: './sub_api/team/team.yml'
|
||||
/history:
|
||||
$ref: './sub_api/bans/bans.yml'
|
||||
|
|
|
|||
58
open_api/src/main/resources/sub_api/bans/bans.yml
Normal file
58
open_api/src/main/resources/sub_api/bans/bans.yml
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
paths:
|
||||
/history:
|
||||
post:
|
||||
tags:
|
||||
- user
|
||||
summary: Get player history
|
||||
description: Retrieves all types of player history about the player
|
||||
operationId: getPlayerHistory
|
||||
requestBody:
|
||||
description: The player history
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/Player'
|
||||
responses:
|
||||
'200':
|
||||
description: successful operation
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/PlayerHistory'
|
||||
default:
|
||||
description: Unexpected error
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: "../generic/errors.yml#/components/schemas/Error"
|
||||
components:
|
||||
schemas:
|
||||
PlayerHistory:
|
||||
type: object
|
||||
properties:
|
||||
punishmentType:
|
||||
type: string
|
||||
punishment:
|
||||
type: string
|
||||
active:
|
||||
type: boolean
|
||||
start:
|
||||
type: integer
|
||||
format: int64
|
||||
duration:
|
||||
type: integer
|
||||
format: int64
|
||||
Player:
|
||||
type: object
|
||||
properties:
|
||||
name:
|
||||
type: string
|
||||
description: The name of the player
|
||||
example: a_name
|
||||
uuid:
|
||||
type: string
|
||||
example: 0c35e520-927e-4c6a-87ad-ff0739c22e9d
|
||||
description: The uuid of the team player
|
||||
required:
|
||||
- name
|
||||
- uuid
|
||||
7
open_api/src/main/resources/sub_api/generic/errors.yml
Normal file
7
open_api/src/main/resources/sub_api/generic/errors.yml
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
components:
|
||||
schemas:
|
||||
Error:
|
||||
type: object
|
||||
properties:
|
||||
reason:
|
||||
type: string
|
||||
48
open_api/src/main/resources/sub_api/team/team.yml
Normal file
48
open_api/src/main/resources/sub_api/team/team.yml
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
paths:
|
||||
/{group}:
|
||||
get:
|
||||
tags:
|
||||
- team
|
||||
summary: Get team members
|
||||
description: Retrieve players who are part of the specified team
|
||||
operationId: getTeamMembers
|
||||
parameters:
|
||||
- name: group
|
||||
in: path
|
||||
required: true
|
||||
description: The group name of the team
|
||||
schema:
|
||||
type: string
|
||||
responses:
|
||||
'200':
|
||||
description: successful operation
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/TeamMembers'
|
||||
default:
|
||||
description: Unexpected error
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: "../generic/errors.yml#/components/schemas/Error"
|
||||
components:
|
||||
schemas:
|
||||
TeamMembers:
|
||||
type: array
|
||||
items:
|
||||
$ref: '#/components/schemas/Player'
|
||||
Player:
|
||||
type: object
|
||||
properties:
|
||||
name:
|
||||
type: string
|
||||
description: The name of the player
|
||||
example: a_name
|
||||
uuid:
|
||||
type: string
|
||||
example: 0c35e520-927e-4c6a-87ad-ff0739c22e9d
|
||||
description: The uuid of the team player
|
||||
required:
|
||||
- name
|
||||
- uuid
|
||||
Loading…
Reference in New Issue
Block a user