From 3e367bbe58e503eb3829a1eb67b0f86da51d21c7 Mon Sep 17 00:00:00 2001 From: superpollo2 Date: Thu, 23 May 2024 20:18:43 -0500 Subject: [PATCH] fixed error in parse UserRole Enum --- src/main/java/com/consola/lis/jwt/JwtService.java | 2 +- .../java/com/consola/lis/model/enums/UserRole.java | 13 ++++++++++--- .../model/repository/InventoryItemRepository.java | 3 +++ .../com/consola/lis/service/RegisterService.java | 1 + 4 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/consola/lis/jwt/JwtService.java b/src/main/java/com/consola/lis/jwt/JwtService.java index 38f0c9c..bf7e310 100644 --- a/src/main/java/com/consola/lis/jwt/JwtService.java +++ b/src/main/java/com/consola/lis/jwt/JwtService.java @@ -36,7 +36,7 @@ private String getToken(Map extraClaims, UserLis user) { .builder() .claims(extraClaims) .claim("id", user.getIdUser()) - .claim("role", user.getRole().toString()) + .claim("role", user.getRole()) .claim("name", user.getName()) .claim("username", user.getUsername()) .subject(user.getUsername()) diff --git a/src/main/java/com/consola/lis/model/enums/UserRole.java b/src/main/java/com/consola/lis/model/enums/UserRole.java index 19fcb13..ffbf4e6 100644 --- a/src/main/java/com/consola/lis/model/enums/UserRole.java +++ b/src/main/java/com/consola/lis/model/enums/UserRole.java @@ -22,15 +22,22 @@ public String toString() { return this.lowerCase; } - public static UserRole fromString(String role) { + public static UserRole fromString(String text) { try { - return UserRole.valueOf(role.toUpperCase()); + for (UserRole role : UserRole.values()) { + if (role.lowerCase.equalsIgnoreCase(text)) { + return role; + } + } } catch (IllegalArgumentException e) { - return fromNumericString(role); + return fromNumericString(text); } + throw new IllegalArgumentException("No enum constant with text " + text); } + + public static UserRole fromNumericString(String numericString) { switch (numericString) { case "1005": diff --git a/src/main/java/com/consola/lis/model/repository/InventoryItemRepository.java b/src/main/java/com/consola/lis/model/repository/InventoryItemRepository.java index c69b454..c7ca8c0 100644 --- a/src/main/java/com/consola/lis/model/repository/InventoryItemRepository.java +++ b/src/main/java/com/consola/lis/model/repository/InventoryItemRepository.java @@ -2,6 +2,7 @@ import com.consola.lis.model.entity.InventoryItem; +import com.consola.lis.model.enums.ItemState; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.repository.JpaRepository; @@ -14,4 +15,6 @@ public interface InventoryItemRepository extends JpaRepository findAllItems(Pageable pageable); + + Page findByState(ItemState state, Pageable pageable); } \ No newline at end of file diff --git a/src/main/java/com/consola/lis/service/RegisterService.java b/src/main/java/com/consola/lis/service/RegisterService.java index 070d9b8..ec37cc6 100644 --- a/src/main/java/com/consola/lis/service/RegisterService.java +++ b/src/main/java/com/consola/lis/service/RegisterService.java @@ -3,6 +3,7 @@ import com.consola.lis.dto.*; import com.consola.lis.model.entity.UserHelloLis; import com.consola.lis.model.entity.UserLis; +import com.consola.lis.model.enums.UserRole; import com.consola.lis.model.repository.UserHelloLisRepository; import com.consola.lis.model.repository.UserLisRepository; import com.consola.lis.util.exception.AlreadyExistsException;