Skip to content

Commit

Permalink
[SELC-4334] feat: Added api getUserDetailsById (#55)
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinSi96 authored Feb 21, 2024
1 parent bae8a7d commit 2e22821
Show file tree
Hide file tree
Showing 9 changed files with 116 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import io.smallrye.mutiny.Uni;
import it.pagopa.selfcare.onboarding.common.PartyRole;
import it.pagopa.selfcare.user.constant.OnboardedProductState;
import it.pagopa.selfcare.user.controller.response.UserDetailResponse;
import it.pagopa.selfcare.user.controller.response.UserInstitutionResponse;
import it.pagopa.selfcare.user.controller.response.UserResponse;
import it.pagopa.selfcare.user.controller.response.UsersNotificationResponse;
Expand Down Expand Up @@ -77,6 +78,19 @@ public Uni<UserProductsResponse> getUserProductsInfo(@PathParam(value = "userId"
.map(userMapper::toUserProductsResponse);
}

/**
* getUserById function returns all the information of a user retrieved from pdv given the userId
* @param userId String
* @return A uni UserDetailResponse
*/
@Operation(summary = "Retrieves user's information from pdv")
@GET
@Path("/{id}/details")
@Produces(MediaType.APPLICATION_JSON)
public Uni<UserDetailResponse> getUserDetailsById(@PathParam(value = "id") String userId) {
return userService.getUserById(userId).onItem().transform(userMapper::toUserResponse);
}

/**
* The deleteProducts function is used to delete logically the association institution and product.
*
Expand Down Expand Up @@ -161,24 +175,22 @@ public Uni<UsersNotificationResponse> getUsers(@QueryParam(value = "page") @Defa
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Multi<UserInstitutionResponse> retrievePaginatedAndFilteredUser(@QueryParam(value = "institutionId") String institutionId,
@QueryParam(value = "userId") String userId,
@QueryParam(value = "roles") List<PartyRole> roles,
@QueryParam(value = "states") List<String> states,
@QueryParam(value = "products") List<String> products,
@QueryParam(value = "productRoles") List<String> productRoles,
@QueryParam(value = "page") @DefaultValue("0") Integer page,
@QueryParam(value = "size") @DefaultValue("100") Integer size) {
@QueryParam(value = "userId") String userId,
@QueryParam(value = "roles") List<PartyRole> roles,
@QueryParam(value = "states") List<String> states,
@QueryParam(value = "products") List<String> products,
@QueryParam(value = "productRoles") List<String> productRoles,
@QueryParam(value = "page") @DefaultValue("0") Integer page,
@QueryParam(value = "size") @DefaultValue("100") Integer size) {
return userService.findPaginatedUserInstitutions(institutionId, userId, roles, states, products, productRoles, page, size);
}

/**
* The updateUserRegistryAndSendNotification function is a service that sends notification when user data get's updated.
*
* @param userId String
* @param userId String
* @param institutionId String
*
* @return Uni&lt;response&gt;
*
*/
@Operation(summary = "Service to update user in user-registry and send notification when user data gets updated")
@ResponseStatus(HttpStatus.SC_NO_CONTENT)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package it.pagopa.selfcare.user.controller.response;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class CertifiableFieldResponse<T> {
private T value;
private boolean certified;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package it.pagopa.selfcare.user.controller.response;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.Map;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class UserDetailResponse {
private String id;
private String fiscalCode;
private CertifiableFieldResponse<String> name;
private CertifiableFieldResponse<String> familyName;
private CertifiableFieldResponse<String> email;
private Map<String, WorkContactResponse> workContacts;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package it.pagopa.selfcare.user.controller.response;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class WorkContactResponse {
private CertifiableFieldResponse<String> email;
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package it.pagopa.selfcare.user.mapper;

import it.pagopa.selfcare.user.controller.response.OnboardedProductResponse;
import it.pagopa.selfcare.user.controller.response.UserDetailResponse;
import it.pagopa.selfcare.user.controller.response.UserNotificationResponse;
import it.pagopa.selfcare.user.controller.response.UserResponse;
import it.pagopa.selfcare.user.controller.response.product.InstitutionProducts;
Expand Down Expand Up @@ -30,6 +31,8 @@ default String fromCertifiabletoString(CertifiableFieldResourceOfstring certifia
return certifiableFieldResourceOfstring.getValue();
}

UserDetailResponse toUserResponse(UserResource userResource);

@Named("retrieveMailFromWorkContacts")
default String retrieveMailFromWorkContacts(Map<String, WorkContactResource> map, String userMailUuid){
if(map!=null && !map.isEmpty() && map.containsKey(userMailUuid)){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import it.pagopa.selfcare.user.controller.response.UserResponse;
import it.pagopa.selfcare.user.entity.UserInfo;
import it.pagopa.selfcare.user.model.notification.UserNotificationToSend;
import org.openapi.quarkus.user_registry_json.model.UserResource;

import java.time.LocalDateTime;
import java.util.List;
Expand All @@ -35,4 +36,6 @@ public interface UserService {

Uni<List<UserInstitutionResponse>> findAllByIds(List<String> userIds);
Uni<Void> updateUserProductCreatedAt(String institutionId, List<String> userIds, String productId, LocalDateTime createdAt);

Uni<UserResource> getUserById(String userId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.apache.commons.lang3.StringUtils;
import org.eclipse.microprofile.rest.client.inject.RestClient;
import org.openapi.quarkus.user_registry_json.api.UserApi;
import org.openapi.quarkus.user_registry_json.model.UserResource;

import java.time.LocalDateTime;
import java.util.ArrayList;
Expand Down Expand Up @@ -170,6 +171,12 @@ public Uni<Void> updateUserProductCreatedAt(String institutionId, List<String> u
});
}

@Override
public Uni<UserResource> getUserById(String userId) {
Uni<UserResource> userResourceUni = userRegistryApi.findByIdUsingGET(USERS_WORKS_FIELD_LIST, userId);
return userResourceUni;
}

@Override
public Uni<List<UserNotificationToSend>> findPaginatedUserNotificationToSend(Integer size, Integer page, String productId) {
Map<String, Object> queryParameter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@
import org.apache.http.HttpStatus;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import org.openapi.quarkus.user_registry_json.model.CertifiableFieldResourceOfstring;
import org.openapi.quarkus.user_registry_json.model.MutableUserFieldsDto;
import org.openapi.quarkus.user_registry_json.model.UserResource;
import org.openapi.quarkus.user_registry_json.model.WorkContactResource;

import java.util.*;

Expand Down Expand Up @@ -158,6 +161,26 @@ void updateUserStatus() {
.statusCode(204);
}

@Test
@TestSecurity(user = "userJwt")
void getUserDetailsById(){
UserResource userResource = new UserResource();
userResource.setEmail(new CertifiableFieldResourceOfstring(CertifiableFieldResourceOfstring.CertificationEnum.NONE, "email"));
userResource.setName(new CertifiableFieldResourceOfstring(CertifiableFieldResourceOfstring.CertificationEnum.NONE, "name"));
userResource.setFamilyName(new CertifiableFieldResourceOfstring(CertifiableFieldResourceOfstring.CertificationEnum.NONE, "familyName"));
userResource.setFiscalCode("fiscalCode");
userResource.setWorkContacts(Map.of("userMailUuid", new WorkContactResource(new CertifiableFieldResourceOfstring(CertifiableFieldResourceOfstring.CertificationEnum.NONE, "email"))));

Mockito.when(userService.getUserById(any())).thenReturn(Uni.createFrom().item(userResource));

given()
.when()
.contentType(ContentType.JSON)
.get("/test_user_id/details")
.then()
.statusCode(200);
}

@Test
@TestSecurity(user = "userJwt")
void updateUserStatusError() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,20 @@ void getUsersEmailsTest() {
assertEquals("[email protected]", actual.get(0));
}

@Test
void getUserById(){
when(userRegistryApi.findByIdUsingGET(any(), any()))
.thenReturn(Uni.createFrom().item(userResource));
UniAssertSubscriber<UserResource> subscriber = userService
.getUserById("userId")
.subscribe()
.withSubscriber(UniAssertSubscriber.create());

UserResource actual = subscriber.assertCompleted().awaitItem().getItem();
assertNotNull(actual);
assertEquals(userResource.getId(), actual.getId());
}


@Test
void getUserProductsByInstitutionTest() {
Expand Down

0 comments on commit 2e22821

Please sign in to comment.