Skip to content

Commit

Permalink
[SELC-4532] Fix: Refactor API to retrieve list of user's institution …
Browse files Browse the repository at this point in the history
…after dashboard login (#379)
  • Loading branch information
flaminiaScarciofolo committed Mar 19, 2024
1 parent 02d2f85 commit 12a4cb4
Show file tree
Hide file tree
Showing 12 changed files with 245 additions and 103 deletions.
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package it.pagopa.selfcare.dashboard.connector.api;

import it.pagopa.selfcare.dashboard.connector.model.institution.InstitutionInfo;
import it.pagopa.selfcare.dashboard.connector.model.institution.InstitutionBase;
import it.pagopa.selfcare.dashboard.connector.model.user.MutableUserFieldsDto;
import it.pagopa.selfcare.dashboard.connector.model.user.User;

import java.util.List;

public interface UserApiConnector {

List<InstitutionInfo> getUserProducts(String userId);
List<InstitutionBase> getUserInstitutions(String userId);

User getUserById(String userId);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package it.pagopa.selfcare.dashboard.connector.model.institution;

import lombok.Data;
import lombok.extern.slf4j.Slf4j;

@Data
@Slf4j
public class InstitutionBase {

private String id;
private String name;
private String userRole;
private String status;
private String parentDescription;

}
218 changes: 179 additions & 39 deletions connector/rest/docs/openapi/selfcare-user-docs.json
Original file line number Diff line number Diff line change
Expand Up @@ -878,6 +878,105 @@
]
}
},
"/users/{userId}/institution/{institutionId}": {
"get": {
"tags": [
"User Controller"
],
"summary": "The retrieveUsers function is used to retrieve a list of users from the UserInstitution collection and userRegistry.\nAt first it try to retrieve a UserInstitution document associated with a logged user (admin)\nIf this userInstitution object is not null, so user has AdminRole, it try to retriew the userInstitutions filtered by given institutionId, roles, states, products and productRoles\nand optional given personId, otherwise it do the same query using the logged user id instead of personId.\nAfter that it retrieve personal user data, foreach userId retrieved, from userRegistry and return a stream of UserDataResponse objects containing the requested user data.",
"parameters": [
{
"name": "institutionId",
"in": "path",
"required": true,
"schema": {
"type": "string"
}
},
{
"name": "userId",
"in": "path",
"required": true,
"schema": {
"type": "string"
}
},
{
"name": "personId",
"in": "query",
"schema": {
"type": "string"
}
},
{
"name": "productRoles",
"in": "query",
"schema": {
"type": "array",
"items": {
"type": "string"
}
}
},
{
"name": "products",
"in": "query",
"schema": {
"type": "array",
"items": {
"type": "string"
}
}
},
{
"name": "roles",
"in": "query",
"schema": {
"type": "array",
"items": {
"type": "string"
}
}
},
{
"name": "states",
"in": "query",
"schema": {
"type": "array",
"items": {
"type": "string"
}
}
}
],
"responses": {
"200": {
"description": "OK",
"content": {
"application/json": {
"schema": {
"type": "array",
"items": {
"$ref": "#/components/schemas/UserDataResponse"
}
}
}
}
},
"401": {
"description": "Not Authorized"
},
"403": {
"description": "Not Allowed"
}
},
"security": [
{
"SecurityScheme": []
}
]
}
},
"/users/{userId}/institutions/{institutionId}/products/{productId}": {
"delete": {
"tags": [
Expand Down Expand Up @@ -928,7 +1027,7 @@
]
}
},
"/users/{userId}/products": {
"/users/{userId}/institutions": {
"get": {
"tags": [
"User Controller"
Expand Down Expand Up @@ -967,7 +1066,7 @@
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/UserProductsResponse"
"$ref": "#/components/schemas/UserInfoResponse"
}
}
}
Expand Down Expand Up @@ -1071,29 +1170,6 @@
],
"type": "string"
},
"InstitutionProducts": {
"type": "object",
"properties": {
"institutionId": {
"type": "string"
},
"institutionName": {
"type": "string"
},
"institutionRootName": {
"type": "string"
},
"userMailUuid": {
"type": "string"
},
"products": {
"type": "array",
"items": {
"$ref": "#/components/schemas/OnboardedProductResponse"
}
}
}
},
"LocalDate": {
"format": "date",
"type": "string",
Expand Down Expand Up @@ -1254,6 +1330,44 @@
}
}
},
"UserDataResponse": {
"type": "object",
"properties": {
"id": {
"type": "string"
},
"userId": {
"type": "string"
},
"institutionId": {
"type": "string"
},
"institutionDescription": {
"type": "string"
},
"institutionRootName": {
"type": "string"
},
"userMailUuid": {
"type": "string"
},
"role": {
"type": "string"
},
"status": {
"type": "string"
},
"products": {
"type": "array",
"items": {
"$ref": "#/components/schemas/OnboardedProductResponse"
}
},
"userResponse": {
"$ref": "#/components/schemas/UserResponse"
}
}
},
"UserDetailResponse": {
"type": "object",
"properties": {
Expand All @@ -1280,6 +1394,20 @@
}
}
},
"UserInfoResponse": {
"type": "object",
"properties": {
"userId": {
"type": "string"
},
"institutions": {
"type": "array",
"items": {
"$ref": "#/components/schemas/UserInstitutionRoleResponse"
}
}
}
},
"UserInstitutionResponse": {
"type": "object",
"properties": {
Expand Down Expand Up @@ -1309,6 +1437,26 @@
}
}
},
"UserInstitutionRoleResponse": {
"type": "object",
"properties": {
"institutionId": {
"type": "string"
},
"institutionName": {
"type": "string"
},
"institutionRootName": {
"type": "string"
},
"role": {
"$ref": "#/components/schemas/PartyRole"
},
"status": {
"$ref": "#/components/schemas/OnboardedProductState"
}
}
},
"UserNotificationResponse": {
"type": "object",
"properties": {
Expand Down Expand Up @@ -1364,20 +1512,6 @@
}
}
},
"UserProductsResponse": {
"type": "object",
"properties": {
"id": {
"type": "string"
},
"bindings": {
"type": "array",
"items": {
"$ref": "#/components/schemas/InstitutionProducts"
}
}
}
},
"UserResponse": {
"required": [
"id",
Expand All @@ -1403,6 +1537,12 @@
},
"email": {
"type": "string"
},
"workContacts": {
"type": "object",
"additionalProperties": {
"type": "string"
}
}
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import it.pagopa.selfcare.commons.base.logging.LogUtils;
import it.pagopa.selfcare.dashboard.connector.api.UserApiConnector;
import it.pagopa.selfcare.dashboard.connector.model.institution.InstitutionInfo;
import it.pagopa.selfcare.dashboard.connector.model.institution.InstitutionBase;
import it.pagopa.selfcare.dashboard.connector.model.user.MutableUserFieldsDto;
import it.pagopa.selfcare.dashboard.connector.model.user.User;
import it.pagopa.selfcare.dashboard.connector.rest.client.UserApiRestClient;
Expand All @@ -12,7 +12,7 @@
import it.pagopa.selfcare.user.generated.openapi.v1.dto.OnboardedProductState;
import it.pagopa.selfcare.user.generated.openapi.v1.dto.PermissionTypeEnum;
import it.pagopa.selfcare.user.generated.openapi.v1.dto.SearchUserDto;
import it.pagopa.selfcare.user.generated.openapi.v1.dto.UserProductsResponse;
import it.pagopa.selfcare.user.generated.openapi.v1.dto.UserInfoResponse;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
Expand All @@ -33,16 +33,16 @@ public class UserConnectorImpl implements UserApiConnector {
private final UserMapper userMapper;

@Override
public List<InstitutionInfo> getUserProducts(String userId) {
public List<InstitutionBase> getUserInstitutions(String userId) {
log.trace("getUserProducts start");
UserProductsResponse productsInfoUsingGET = userApiRestClient._usersUserIdProductsGet(userId, null,
UserInfoResponse userInfoResponse = userApiRestClient._usersUserIdInstitutionsGet(userId, null,
List.of(ACTIVE.name(), PENDING.name(), TOBEVALIDATED.name())).getBody();

if(Objects.isNull(productsInfoUsingGET) ||
Objects.isNull(productsInfoUsingGET.getBindings())) return List.of();
if(Objects.isNull(userInfoResponse) ||
Objects.isNull(userInfoResponse.getInstitutions())) return List.of();

List<InstitutionInfo> result = productsInfoUsingGET.getBindings().stream()
.map(institutionMapper::toInstitutionInfo)
List<InstitutionBase> result = userInfoResponse.getInstitutions().stream()
.map(institutionMapper::toInstitutionBase)
.toList();
log.debug("getUserProducts result = {}", result);
log.trace("getUserProducts end");
Expand Down
Loading

0 comments on commit 12a4cb4

Please sign in to comment.