From 778a18d1dd0264a3d5f06541551b450220c9350b Mon Sep 17 00:00:00 2001 From: Pelayori <31128562+Pelayori@users.noreply.github.com> Date: Tue, 5 Mar 2024 00:50:31 +0100 Subject: [PATCH] Test fix for sql generation --- src/main/java/com/uniovi/entities/ApiKey.java | 2 +- src/main/java/com/uniovi/repositories/ApiKeyRepository.java | 2 +- src/main/java/com/uniovi/repositories/RestApiLogRepository.java | 2 +- src/main/java/com/uniovi/services/impl/ApiKeyServiceImpl.java | 2 +- src/main/java/com/uniovi/services/impl/PlayerServiceImpl.java | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/uniovi/entities/ApiKey.java b/src/main/java/com/uniovi/entities/ApiKey.java index 464ff90f..43f65b89 100644 --- a/src/main/java/com/uniovi/entities/ApiKey.java +++ b/src/main/java/com/uniovi/entities/ApiKey.java @@ -19,7 +19,7 @@ public class ApiKey { private Long id; @Column(unique = true) - private String key = UUID.randomUUID().toString(); + private String keyToken = UUID.randomUUID().toString(); @OneToOne private Player player; diff --git a/src/main/java/com/uniovi/repositories/ApiKeyRepository.java b/src/main/java/com/uniovi/repositories/ApiKeyRepository.java index fb4b79f1..a576d810 100644 --- a/src/main/java/com/uniovi/repositories/ApiKeyRepository.java +++ b/src/main/java/com/uniovi/repositories/ApiKeyRepository.java @@ -4,5 +4,5 @@ import org.springframework.data.repository.CrudRepository; public interface ApiKeyRepository extends CrudRepository { - ApiKey findByKey(String key); + ApiKey findByKeyToken(String key); } diff --git a/src/main/java/com/uniovi/repositories/RestApiLogRepository.java b/src/main/java/com/uniovi/repositories/RestApiLogRepository.java index 8368fc3a..49f17456 100644 --- a/src/main/java/com/uniovi/repositories/RestApiLogRepository.java +++ b/src/main/java/com/uniovi/repositories/RestApiLogRepository.java @@ -10,6 +10,6 @@ public interface RestApiLogRepository extends CrudRepository { List findByApiKey(ApiKey apiKey); - @Query("SELECT r FROM RestApiAccessLog r WHERE r.apiKey.user = ?1") + @Query("SELECT r FROM RestApiAccessLog r WHERE r.apiKey.player = ?1") List findByUser(Player user); } diff --git a/src/main/java/com/uniovi/services/impl/ApiKeyServiceImpl.java b/src/main/java/com/uniovi/services/impl/ApiKeyServiceImpl.java index 7c8ebde3..da597a9c 100644 --- a/src/main/java/com/uniovi/services/impl/ApiKeyServiceImpl.java +++ b/src/main/java/com/uniovi/services/impl/ApiKeyServiceImpl.java @@ -27,6 +27,6 @@ public ApiKey createApiKey(Player forPlayer) { @Override public ApiKey getApiKey(String apiKey) { - return apiKeyRepository.findByKey(apiKey); + return apiKeyRepository.findByKeyToken(apiKey); } } diff --git a/src/main/java/com/uniovi/services/impl/PlayerServiceImpl.java b/src/main/java/com/uniovi/services/impl/PlayerServiceImpl.java index 7ffd4913..b928c030 100644 --- a/src/main/java/com/uniovi/services/impl/PlayerServiceImpl.java +++ b/src/main/java/com/uniovi/services/impl/PlayerServiceImpl.java @@ -99,7 +99,7 @@ public List getUsersByRole(String role) { public void generateApiKey(Player player) { ApiKey apiKey = new ApiKey(); Associations.PlayerApiKey.addApiKey(player, apiKey); - System.out.println("Generated API key for " + player.getUsername() + ": " + apiKey.getKey()); + System.out.println("Generated API key for " + player.getUsername() + ": " + apiKey.getKeyToken()); playerRepository.save(player); } }