[Feature]: Spieler bannen #15
4 changed files with 35 additions and 1 deletions
17
api/api.yml
17
api/api.yml
|
@ -282,6 +282,23 @@ paths:
|
||||||
responses:
|
responses:
|
||||||
|
|||||||
200:
|
200:
|
||||||
description: "Successfully banned player!"
|
description: "Successfully banned player!"
|
||||||
snoweuph
commented
401,500 & 503 fehlen 401,500 & 503 fehlen
|
|||||||
|
/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:
|
||||||
snoweuph
commented
404 hinzufügen, fals der speiler nicht gefunden wird 404 hinzufügen, fals der speiler nicht gefunden wird
|
|||||||
|
200:
|
||||||
|
description: "Successfully unbanned player!"
|
||||||
401:
|
401:
|
||||||
$ref: "#/components/responses/401Unauthorized"
|
$ref: "#/components/responses/401Unauthorized"
|
||||||
500:
|
500:
|
||||||
|
|
|
@ -93,4 +93,10 @@ public class AdminApiController implements AdminApi {
|
||||||
|
|
||||||
return ResponseEntity.ok(playersMapped);
|
return ResponseEntity.ok(playersMapped);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ResponseEntity<Void> unbanPlayer(Long id) {
|
||||||
|
this.playerService.unbanPlayer(id);
|
||||||
|
return null;
|
||||||
snoweuph
commented
st null hier richtig? wollen wir nicht ein 200 zurückgeben? st null hier richtig? wollen wir nicht ein 200 zurückgeben?
|
|||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,4 +57,11 @@ public class PlayerService {
|
||||||
this.playerRepository.saveAndFlush(player);
|
this.playerRepository.saveAndFlush(player);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void unbanPlayer(Long id) {
|
||||||
snoweuph
commented
Wenn der Spieler nicht existiert, sollte diese Funktion einen PlayerNotFound Exception schmeißen Wenn der Spieler nicht existiert, sollte diese Funktion einen PlayerNotFound Exception schmeißen
|
|||||||
|
this.playerRepository.findById(id).ifPresent(player -> {
|
||||||
|
player.setBanned(false);
|
||||||
|
this.playerRepository.saveAndFlush(player);
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,7 +45,7 @@ public class ServerApiController implements ServerApi {
|
||||||
@Override
|
@Override
|
||||||
public ResponseEntity<Void> playerRegister(PlayerRegistrationData body) {
|
public ResponseEntity<Void> playerRegister(PlayerRegistrationData body) {
|
||||||
if(playerRepository.existsByUsername(body.getUsername())){
|
if(playerRepository.existsByUsername(body.getUsername())){
|
||||||
return new ResponseEntity<>(HttpStatus.CONFLICT);
|
return new ResponseEntity<>(HttpStatus.FORBIDDEN);
|
||||||
snoweuph
commented
warum die änderung? warum die änderung?
|
|||||||
}
|
}
|
||||||
Player newPlayer = new Player();
|
Player newPlayer = new Player();
|
||||||
newPlayer.setUsername(body.getUsername());
|
newPlayer.setUsername(body.getUsername());
|
||||||
|
@ -61,6 +61,10 @@ public class ServerApiController implements ServerApi {
|
||||||
@Override
|
@Override
|
||||||
public ResponseEntity<PlayerLoginSession> playerLogin(PlayerLoginData body) {
|
public ResponseEntity<PlayerLoginSession> playerLogin(PlayerLoginData body) {
|
||||||
Player player = playerRepository.findByUsername(body.getUsername());
|
Player player = playerRepository.findByUsername(body.getUsername());
|
||||||
|
if(player.isBanned())
|
||||||
|
{
|
||||||
|
return new ResponseEntity<>(HttpStatus.CONFLICT);
|
||||||
snoweuph
commented
403 währe hier richtig. 403 ist für wenn man sich authentiziert hat, aber keine zugriffsrechte hat 403 währe hier richtig.
403 ist für wenn man sich authentiziert hat, aber keine zugriffsrechte hat
|
|||||||
|
}
|
||||||
if(player == null){
|
if(player == null){
|
||||||
return new ResponseEntity<>(HttpStatus.UNAUTHORIZED);
|
return new ResponseEntity<>(HttpStatus.UNAUTHORIZED);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue
404 wenn spieler nicht gefunden