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
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:
parent
bce1c6aa4e
commit
ca8942feba
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!"
|
||||||
|
/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:
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,4 +57,11 @@ public class PlayerService {
|
||||||
this.playerRepository.saveAndFlush(player);
|
this.playerRepository.saveAndFlush(player);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void unbanPlayer(Long id) {
|
||||||
|
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);
|
||||||
}
|
}
|
||||||
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);
|
||||||
|
}
|
||||||
if(player == null){
|
if(player == null){
|
||||||
return new ResponseEntity<>(HttpStatus.UNAUTHORIZED);
|
return new ResponseEntity<>(HttpStatus.UNAUTHORIZED);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue