Skip to content

Commit

Permalink
Merge pull request feat/add-user-ldap
Browse files Browse the repository at this point in the history
fixed error in parse UserRole Enum
  • Loading branch information
superpollo2 authored May 24, 2024
2 parents 3325858 + a4e7046 commit 6627ead
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/main/java/com/consola/lis/jwt/JwtService.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ private String getToken(Map<String, Object> 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())
Expand Down
13 changes: 10 additions & 3 deletions src/main/java/com/consola/lis/model/enums/UserRole.java
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -14,4 +15,6 @@ public interface InventoryItemRepository extends JpaRepository<InventoryItem, St

@Query("SELECT p FROM InventoryItem p ")
Page<InventoryItem> findAllItems(Pageable pageable);

Page<InventoryItem> findByState(ItemState state, Pageable pageable);
}
1 change: 1 addition & 0 deletions src/main/java/com/consola/lis/service/RegisterService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 6627ead

Please sign in to comment.