Skip to content

Commit

Permalink
FKS-1103 api/users accept list of userType and not only one userType
Browse files Browse the repository at this point in the history
  • Loading branch information
Erling Jahr committed Dec 19, 2024
1 parent fe38022 commit 049a3e2
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 15 deletions.
9 changes: 4 additions & 5 deletions src/main/java/no/fintlabs/user/ResponseFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,14 @@ public ResponseEntity<Map<String,Object>> toResponseEntity(
FintJwtEndUserPrincipal principal,
String search,
List<String> orgUnits,
String userType,
List<String> userType,
int page,
int size
) {
List<SimpleUser> simpleUsers = userService.getSimpleUsersUsingSpec(search,orgUnits,userType);
ResponseEntity<Map<String,Object>> entity = toResponseEntity(
toPage(simpleUsers,PageRequest.of(page, size)));
List<SimpleUser> simpleUsers = userService.getSimpleUsersUsingSpec(search,orgUnits,userType);

return entity;
return toResponseEntity(
toPage(simpleUsers,PageRequest.of(page, size)));
}

public ResponseEntity<Map<String, Object>> toResponseEntity(Page<SimpleUser> userPage) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/no/fintlabs/user/UserController.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public UserController(UserService userService, ResponseFactory responseFactory,
public ResponseEntity<Map<String, Object>> getSimpleUsers(@AuthenticationPrincipal Jwt jwt,
@RequestParam(value = "search", defaultValue = "%") String search,
@RequestParam(value = "orgUnits", required = false) List<String> orgUnits,
@RequestParam(value = "userType", defaultValue = "ALLTYPES") String userType,
@RequestParam(value = "userType", defaultValue = "ALLTYPES") List<String> userType,
@RequestParam(defaultValue = "0") int page,
@RequestParam(defaultValue = "${fint.kontroll.user-catalog.pagesize:20}") int size
) {
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/no/fintlabs/user/UserService.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,10 @@ public Optional<User> getUserById(Long id) {
}



public List<SimpleUser> getSimpleUsersUsingSpec(
String search,
List<String> orgUnits,
String userType
List<String> userType
){
UserSpesificationBuilder userSpesification = new UserSpesificationBuilder(search,orgUnits,userType);
List<User> userList = userRepository.findAll(userSpesification.build());
Expand Down
14 changes: 7 additions & 7 deletions src/main/java/no/fintlabs/user/UserSpesificationBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ public class UserSpesificationBuilder {

private final String search;
private final List<String> orgUnits;
private final String userType;
private final List<String> userType;

public UserSpesificationBuilder(String search, List<String> orgUnits, String userType) {
public UserSpesificationBuilder(String search, List<String> orgUnits, List<String> userType) {
this.search = search;
this.orgUnits = orgUnits;
this.userType = userType;
Expand All @@ -33,22 +33,22 @@ public Specification<User> build() {
if (!search.isEmpty()) {
userSpec = userSpec.and(usersNameLike(search));
}
if (!userType.equals("ALLTYPES")) {
userSpec = userSpec.and(userTypeEquals(userType.toLowerCase()));

if (!userType.contains("ALLTYPES")) {
userSpec = userSpec.and(userTypeEquals(userType));
}

return userSpec;
}

private Specification<User> allAutorizedOrgUnits(List<String> orgUnits) {

return (root, query, criteriaBuilder) -> criteriaBuilder
.in(root.get("mainOrganisationUnitId")).value(orgUnits);
}

private Specification<User> userTypeEquals(String userType) {
private Specification<User> userTypeEquals(List<String> userType) {
return (root, query, criteriaBuilder) -> criteriaBuilder
.equal(criteriaBuilder.lower(root.get("userType")), userType);
.in(root.get("userType")).value(userType);
}


Expand Down

0 comments on commit 049a3e2

Please sign in to comment.