Skip to content
This repository has been archived by the owner on Oct 15, 2024. It is now read-only.

[SELC-4086] feat: added API to retrieve all User from userIds #401

Merged
merged 3 commits into from
Feb 9, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 85 additions & 0 deletions app/src/main/resources/swagger/api-docs.json
Original file line number Diff line number Diff line change
Expand Up @@ -4876,6 +4876,60 @@
} ]
}
},
"/onboarded-users" : {
"get" : {
"tags" : [ "Persons" ],
"summary" : "Retrieve onboarded users according to identifiers in input",
"description" : "Retrieve onboarded users according to identifiers in input",
"operationId" : "getOnboardedUsersUsingGET",
"parameters" : [ {
"name" : "ids",
"in" : "query",
"description" : "Users unique identifiers",
"required" : true,
"style" : "form",
"explode" : true,
"schema" : {
"type" : "string"
}
} ],
"responses" : {
"204" : {
"description" : "No Content",
"content" : {
"*/*" : {
"schema" : {
"$ref" : "#/components/schemas/OnboardedUsersResponse"
}
}
}
},
"400" : {
"description" : "Bad Request",
"content" : {
"application/problem+json" : {
"schema" : {
"$ref" : "#/components/schemas/Problem"
}
}
}
},
"404" : {
"description" : "Not Found",
"content" : {
"application/problem+json" : {
"schema" : {
"$ref" : "#/components/schemas/Problem"
}
}
}
}
},
"security" : [ {
"bearerAuth" : [ "global" ]
} ]
}
},
"/relationships/{relationshipId}" : {
"get" : {
"tags" : [ "Persons" ],
Expand Down Expand Up @@ -7583,6 +7637,37 @@
}
}
},
"OnboardedUserResponse" : {
"title" : "OnboardedUserResponse",
"type" : "object",
"properties" : {
"bindings" : {
"type" : "array",
"items" : {
"$ref" : "#/components/schemas/UserBinding"
}
},
"createdAt" : {
"type" : "string",
"format" : "date-time"
},
"id" : {
"type" : "string"
}
}
},
"OnboardedUsersResponse" : {
"title" : "OnboardedUsersResponse",
"type" : "object",
"properties" : {
"users" : {
"type" : "array",
"items" : {
"$ref" : "#/components/schemas/OnboardedUserResponse"
}
}
}
},
"Onboarding" : {
"title" : "Onboarding",
"type" : "object",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import it.pagopa.selfcare.mscore.core.UserService;
import it.pagopa.selfcare.mscore.model.QueueEvent;
import it.pagopa.selfcare.mscore.model.UserNotificationToSend;
import it.pagopa.selfcare.mscore.model.onboarding.OnboardedUser;
import it.pagopa.selfcare.mscore.model.onboarding.OnboardingInfo;
import it.pagopa.selfcare.mscore.model.user.RelationshipInfo;
import it.pagopa.selfcare.mscore.model.user.User;
Expand Down Expand Up @@ -315,8 +316,8 @@ public ResponseEntity<UsersNotificationResponse> getUsers(@RequestParam(name = "
}

userNotificationResponse.setUsers(userNotificationMap.values().stream()
.map(UserNotificationBindingsResponse::new)
.toList());
.map(UserNotificationBindingsResponse::new)
.toList());

return ResponseEntity.ok(userNotificationResponse);
}
Expand Down Expand Up @@ -350,4 +351,29 @@ public ResponseEntity<Void> updateUserStatus(@ApiParam(value = "${swagger.mscore
userService.updateUserStatus(userId, institutionId, productId, role, productRole, status);
return ResponseEntity.noContent().build();
}

/**
* Get onboarded users from identifiers in input.
*
* @param userIds Users identifiers.
* @return ResponseEntity<OnboardedUsersResponse>
* <p>
* * Code: 204, Message: Update successful, DataType: No Content
* * Code: 400, Message: Bad Request, DataType: Problem
* * Code: 404, Message: Not Found, DataType: Problem
*/
@ResponseStatus(HttpStatus.NO_CONTENT)
@ApiOperation(value = "${swagger.mscore.api.users.getOnboardedUsers}", notes = "${swagger.mscore.api.users.getOnboardedUsers}")
@GetMapping(value = "/onboarded-users")
public ResponseEntity<OnboardedUsersResponse> getOnboardedUsers(@ApiParam(value = "${swagger.mscore.users.userIds}", required = true)
@RequestParam(value = "ids") List<String> userIds) {
log.debug("getOnboardedUsers - userIds: {}", userIds);
final List<OnboardedUser> onboardedUsers = userService.findAllByIds(userIds);
OnboardedUsersResponse response = OnboardedUsersResponse.builder()
.users(onboardedUsers.stream()
.map(userMapper::toOnboardedUserResponse)
.toList())
.build();
return ResponseEntity.ok(response);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public interface UserMapper {
InstitutionUpdate toInstitutionUpdate(InstitutionUpdateRequest request);

UserNotificationResponse toUserNotification(UserNotificationToSend user);
OnboardedUserResponse toOnboardedUserResponse(OnboardedUser onboardedUser);

@Named("retrieveMailFromWorkContacts")
default String retrieveMailFromWorkContacts(Map<String, WorkContact> map, String institutionId){
Expand Down
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you could use "InstitutionProducts" rather of create another object....they are very similar

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With new commit, I have used UserProductsResponse object that inside has an attribute List

Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package it.pagopa.selfcare.mscore.web.model.user;

import it.pagopa.selfcare.mscore.model.user.UserBinding;
import lombok.Data;

import java.time.OffsetDateTime;
import java.util.List;

@Data
public class OnboardedUserResponse {
private String id;
private List<UserBinding> bindings;
private OffsetDateTime createdAt;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package it.pagopa.selfcare.mscore.web.model.user;

import lombok.Builder;
import lombok.Data;

import java.util.List;

@Data
@Builder
public class OnboardedUsersResponse {
private List<OnboardedUserResponse> users;
}
2 changes: 2 additions & 0 deletions web/src/main/resources/swagger/swagger_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,12 @@ swagger.mscore.users.products=Retrieves products info and role which the user is
swagger.mscore.users=Retrieves user given userId and optional ProductId
swagger.mscore.users.delete.products=Delete logically the association institution and product
swagger.mscore.api.users.updateUserStatus=Update user status with optional filter for institution, product, role and productRole
swagger.mscore.api.users.getOnboardedUsers=Retrieve onboarded users according to identifiers in input
swagger.mscore.institutions.delegations=Retrieve institution's delegations
swagger.mscore.institutions.delegations.mode=Mode (full or normal) to retreieve institution's delegations
swagger.mscore.institutions.brokers=Retrieve institution brokers
swagger.mscore.users.userId=User's unique identifier
swagger.mscore.users.userIds=Users unique identifiers
swagger.mscore.api.users.updateUser=Service to send notification when user data get's updated
swagger.mscore.institutions.api.getInstitutionUsers=Retrieve institution's users
swagger.mscore.api.users.findAll=Retrieve all users according to optional params in input
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import it.pagopa.selfcare.mscore.constant.RelationshipState;
import it.pagopa.selfcare.mscore.core.UserRelationshipService;
import it.pagopa.selfcare.mscore.core.UserService;
import it.pagopa.selfcare.mscore.core.UserServiceImpl;
import it.pagopa.selfcare.mscore.core.util.UserNotificationMapper;
import it.pagopa.selfcare.mscore.core.util.UserNotificationMapperImpl;
import it.pagopa.selfcare.mscore.model.CertifiedField;
Expand Down Expand Up @@ -649,5 +648,22 @@ void updateUserStatus() throws Exception {
.andExpect(MockMvcResultMatchers.status().isNoContent());
}

@Test
void onboardedUsers() throws Exception {
final OnboardedUser onboardedUser = new OnboardedUser();
onboardedUser.setId("userId");
when(userService.findAllByIds(any())).thenReturn(List.of(onboardedUser));

MockHttpServletRequestBuilder requestBuilder = MockMvcRequestBuilders
.get("/onboarded-users")
.queryParam("ids","userId")
.contentType(MediaType.APPLICATION_JSON);

MockMvcBuilders.standaloneSetup(userController)
.build()
.perform(requestBuilder)
.andExpect(MockMvcResultMatchers.status().isOk());
}

}

Loading