TD-4: Unban
Some checks failed
Quality Check / Validate OAS (push) Successful in 31s
Quality Check / Static Analysis (push) Failing after 54s
Quality Check / Linting (push) Successful in 57s
Quality Check / Testing (push) Failing after 58s
Quality Check / Validate OAS (pull_request) Successful in 32s
Quality Check / Static Analysis (pull_request) Failing after 57s
Quality Check / Testing (pull_request) Failing after 1m0s
Quality Check / Linting (pull_request) Successful in 1m3s

This commit is contained in:
Dorian Nemec 2025-03-12 13:53:02 +01:00
parent bce1c6aa4e
commit ca8942feba
4 changed files with 35 additions and 1 deletions

View file

@ -282,6 +282,23 @@ paths:
responses:
200:
description: "Successfully banned player!"
/admin/player/{id}/unban:
parameters:
- in: path
name: id
schema:
type: integer
format: int64
required: true
post:
operationId: "UnbanPlayer"
tags:
- admin
summary: "Unban player by id"
description: "Unbans a player by id, allowing them to play the game."
responses:
200:
description: "Successfully unbanned player!"
401:
$ref: "#/components/responses/401Unauthorized"
500:

View file

@ -93,4 +93,10 @@ public class AdminApiController implements AdminApi {
return ResponseEntity.ok(playersMapped);
}
@Override
public ResponseEntity<Void> unbanPlayer(Long id) {
this.playerService.unbanPlayer(id);
return null;
}
}

View file

@ -57,4 +57,11 @@ public class PlayerService {
this.playerRepository.saveAndFlush(player);
});
}
public void unbanPlayer(Long id) {
this.playerRepository.findById(id).ifPresent(player -> {
player.setBanned(false);
this.playerRepository.saveAndFlush(player);
});
}
}

View file

@ -45,7 +45,7 @@ public class ServerApiController implements ServerApi {
@Override
public ResponseEntity<Void> playerRegister(PlayerRegistrationData body) {
if(playerRepository.existsByUsername(body.getUsername())){
return new ResponseEntity<>(HttpStatus.CONFLICT);
return new ResponseEntity<>(HttpStatus.FORBIDDEN);
}
Player newPlayer = new Player();
newPlayer.setUsername(body.getUsername());
@ -61,6 +61,10 @@ public class ServerApiController implements ServerApi {
@Override
public ResponseEntity<PlayerLoginSession> playerLogin(PlayerLoginData body) {
Player player = playerRepository.findByUsername(body.getUsername());
if(player.isBanned())
{
return new ResponseEntity<>(HttpStatus.CONFLICT);
}
if(player == null){
return new ResponseEntity<>(HttpStatus.UNAUTHORIZED);
}