TD-34: Solved comments made by reviewer
All checks were successful
Quality Check / Validate OAS (push) Successful in 33s
Quality Check / Validate OAS (pull_request) Successful in 34s
Quality Check / Testing (push) Successful in 1m13s
Quality Check / Linting (push) Successful in 1m16s
Quality Check / Static Analysis (push) Successful in 1m22s
Quality Check / Static Analysis (pull_request) Successful in 1m15s
Quality Check / Linting (pull_request) Successful in 1m30s
Quality Check / Testing (pull_request) Successful in 50s
All checks were successful
Quality Check / Validate OAS (push) Successful in 33s
Quality Check / Validate OAS (pull_request) Successful in 34s
Quality Check / Testing (push) Successful in 1m13s
Quality Check / Linting (push) Successful in 1m16s
Quality Check / Static Analysis (push) Successful in 1m22s
Quality Check / Static Analysis (pull_request) Successful in 1m15s
Quality Check / Linting (pull_request) Successful in 1m30s
Quality Check / Testing (pull_request) Successful in 50s
This commit is contained in:
parent
2ccc9f14c5
commit
2740cc53be
5 changed files with 48 additions and 31 deletions
|
@ -59,9 +59,9 @@ components:
|
|||
required:
|
||||
- username
|
||||
#############################################
|
||||
# PlayerApiModel #
|
||||
# AdministratablePlayer #
|
||||
#############################################
|
||||
PlayerApiModel:
|
||||
AdministratablePlayer:
|
||||
description: a Player
|
||||
type: object
|
||||
properties:
|
||||
|
@ -205,7 +205,7 @@ paths:
|
|||
schema:
|
||||
type: array
|
||||
items:
|
||||
$ref: "#/components/schemas/PlayerApiModel"
|
||||
$ref: "#/components/schemas/AdministratablePlayer"
|
||||
401:
|
||||
$ref: "#/components/responses/401Unauthorized"
|
||||
500:
|
||||
|
|
|
@ -4,8 +4,8 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
|||
import de.towerdefence.server.auth.UserSession;
|
||||
import de.towerdefence.server.oas.AdminApi;
|
||||
import de.towerdefence.server.oas.models.AdminAuthInfo;
|
||||
import de.towerdefence.server.oas.models.AdministratablePlayer;
|
||||
import de.towerdefence.server.oas.models.GetAllPlayersConfigurationData;
|
||||
import de.towerdefence.server.oas.models.PlayerApiModel;
|
||||
import de.towerdefence.server.player.Player;
|
||||
import de.towerdefence.server.player.PlayerRepository;
|
||||
import de.towerdefence.server.utils.PlayerMapperService;
|
||||
|
@ -54,7 +54,7 @@ public class AdminApiController implements AdminApi {
|
|||
}
|
||||
|
||||
@Override
|
||||
public ResponseEntity<List<PlayerApiModel>> getAllPlayers(GetAllPlayersConfigurationData body) {
|
||||
public ResponseEntity<List<AdministratablePlayer>> getAllPlayers(GetAllPlayersConfigurationData body) {
|
||||
|
||||
var order = body.getOrder();
|
||||
var page = body.getPage();
|
||||
|
@ -65,7 +65,14 @@ public class AdminApiController implements AdminApi {
|
|||
if (order == null) {
|
||||
order = GetAllPlayersConfigurationData.OrderEnum.DESCENDING;
|
||||
}
|
||||
Sort.Direction direction = order == GetAllPlayersConfigurationData.OrderEnum.ASCENDING ? Sort.Direction.ASC : Sort.Direction.DESC;
|
||||
Sort.Direction direction;
|
||||
|
||||
if (order == GetAllPlayersConfigurationData.OrderEnum.ASCENDING) {
|
||||
direction = Sort.Direction.ASC;
|
||||
} else {
|
||||
direction = Sort.Direction.DESC;
|
||||
}
|
||||
|
||||
Pageable pageable = PageRequest.of(page, pageSize, Sort.by(direction, sortBy));
|
||||
|
||||
Page<Player> playerPage;
|
||||
|
@ -76,8 +83,13 @@ public class AdminApiController implements AdminApi {
|
|||
playerPage = playerRepository.findAll(pageable);
|
||||
}
|
||||
|
||||
List<PlayerApiModel> playersMapped = playerMapperService.mapPlayerToApiPlayers(playerPage.getContent());
|
||||
List<AdministratablePlayer> playersMapped =
|
||||
playerMapperService.mapPlayersToAdministratablePlayers(playerPage.getContent());
|
||||
|
||||
return playersMapped.isEmpty() ? ResponseEntity.noContent().build() : ResponseEntity.ok(playersMapped);
|
||||
if (playersMapped.isEmpty()) {
|
||||
return ResponseEntity.noContent().build();
|
||||
} else {
|
||||
return ResponseEntity.ok(playersMapped);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package de.towerdefence.server.utils;
|
||||
|
||||
import de.towerdefence.server.oas.models.PlayerApiModel;
|
||||
import de.towerdefence.server.oas.models.AdministratablePlayer;
|
||||
import de.towerdefence.server.player.Player;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
|
@ -10,13 +10,19 @@ import java.util.List;
|
|||
@Component
|
||||
public class PlayerMapperService {
|
||||
|
||||
public List<PlayerApiModel> mapPlayerToApiPlayers(List<Player> players) {
|
||||
List<PlayerApiModel> apiPlayers = new ArrayList<>();
|
||||
public List<AdministratablePlayer> mapPlayersToAdministratablePlayers(List<Player> players) {
|
||||
List<AdministratablePlayer> apiPlayers = new ArrayList<>();
|
||||
for (Player player : players) {
|
||||
PlayerApiModel apiPlayer = new PlayerApiModel();
|
||||
AdministratablePlayer apiPlayer = new AdministratablePlayer();
|
||||
apiPlayer.setUsername(player.getUsername());
|
||||
apiPlayers.add(apiPlayer);
|
||||
}
|
||||
return apiPlayers;
|
||||
}
|
||||
|
||||
public AdministratablePlayer mapPlayerToAdministratablePlayer(Player player) {
|
||||
AdministratablePlayer apiPlayer = new AdministratablePlayer();
|
||||
apiPlayer.setUsername(player.getUsername());
|
||||
return apiPlayer;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,6 +13,8 @@ import org.springframework.test.context.ActiveProfiles;
|
|||
import org.springframework.test.web.servlet.MockMvc;
|
||||
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@SpringBootTest
|
||||
@AutoConfigureMockMvc(addFilters = false)
|
||||
|
@ -34,23 +36,20 @@ public abstract class IntegrationTest {
|
|||
void setUp() {
|
||||
playerRepository.deleteAll();
|
||||
|
||||
Player player1 = new Player();
|
||||
player1.setUsername("Alex");
|
||||
try {
|
||||
playerService.setPassword(player1, "1234");
|
||||
} catch (NoSuchAlgorithmException e) {return;}
|
||||
Map<String, String> players = new HashMap<>();
|
||||
players.put("Alex", "1234");
|
||||
players.put("Zorro", "1234");
|
||||
|
||||
this.playerRepository.save(player1);
|
||||
|
||||
Player player2 = new Player();
|
||||
player2.setUsername("Zorro");
|
||||
try {
|
||||
playerService.setPassword(player2, "1234");
|
||||
} catch (NoSuchAlgorithmException e) {return;}
|
||||
|
||||
this.playerRepository.save(player2);
|
||||
|
||||
System.out.println("LISTE: " + playerRepository.findAll());
|
||||
players.forEach((username, password) -> {
|
||||
Player player = new Player();
|
||||
player.setUsername(username);
|
||||
try {
|
||||
playerService.setPassword(player, password);
|
||||
playerRepository.save(player);
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
System.err.println("Error setting password for player: " + username);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
|
@ -58,5 +57,5 @@ public abstract class IntegrationTest {
|
|||
playerRepository.deleteAll();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@ import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilde
|
|||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
|
||||
|
||||
class GetAllPlayersPaginatedAndSortedTest extends IntegrationTest {
|
||||
class GetAllPlayersTest extends IntegrationTest {
|
||||
|
||||
private MockHttpServletRequestBuilder createGetAllPlayersRequest(String requestBody) {
|
||||
return MockMvcRequestBuilders.get(baseUri + "/admin/players")
|
||||
|
@ -80,4 +80,4 @@ class GetAllPlayersPaginatedAndSortedTest extends IntegrationTest {
|
|||
.andExpect(jsonPath("$[0].username").value("Alex"))
|
||||
.andExpect(jsonPath("$").isNotEmpty());
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue