Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SELC-3816] Feat: Added UserV2Controller and Service for new API of BE-User #327

Closed
wants to merge 11 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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
182 changes: 182 additions & 0 deletions app/src/main/resources/swagger/api-docs.json
Original file line number Diff line number Diff line change
Expand Up @@ -3323,6 +3323,188 @@
"bearerAuth" : [ "global" ]
} ]
}
},
"/v2/institutions" : {
"get" : {
"tags" : [ "user" ],
"summary" : "getInstitutions",
"description" : "Service to get all the institutions related to logged user",
"operationId" : "getInstitutionsUsingGET_1",
"parameters" : [ {
"name" : "authenticated",
"in" : "query",
"required" : false,
"style" : "form",
"schema" : {
"type" : "boolean"
}
}, {
"name" : "authorities[0].authority",
"in" : "query",
"required" : false,
"style" : "form",
"schema" : {
"type" : "string"
}
}, {
"name" : "credentials",
"in" : "query",
"required" : false,
"style" : "form",
"schema" : {
"type" : "object"
}
}, {
"name" : "details",
"in" : "query",
"required" : false,
"style" : "form",
"schema" : {
"type" : "object"
}
}, {
"name" : "principal",
"in" : "query",
"required" : false,
"style" : "form",
"schema" : {
"type" : "object"
}
} ],
"responses" : {
"200" : {
"description" : "OK",
"content" : {
"application/json" : {
"schema" : {
"type" : "array",
"items" : {
"$ref" : "#/components/schemas/InstitutionBaseResource"
}
}
}
}
},
"400" : {
"description" : "Bad Request",
"content" : {
"application/problem+json" : {
"schema" : {
"$ref" : "#/components/schemas/Problem"
}
}
}
},
"401" : {
"description" : "Unauthorized",
"content" : {
"application/problem+json" : {
"schema" : {
"$ref" : "#/components/schemas/Problem"
}
}
}
},
"404" : {
"description" : "Not Found",
"content" : {
"application/problem+json" : {
"schema" : {
"$ref" : "#/components/schemas/Problem"
}
}
}
},
"500" : {
"description" : "Internal Server Error",
"content" : {
"application/problem+json" : {
"schema" : {
"$ref" : "#/components/schemas/Problem"
}
}
}
}
},
"security" : [ {
"bearerAuth" : [ "global" ]
} ]
}
},
"/v2/users/{id}" : {
"put" : {
"tags" : [ "user" ],
"summary" : "updateUser",
"description" : "Update previously added user",
"operationId" : "updateUserUsingPUT_1",
"parameters" : [ {
"name" : "id",
"in" : "path",
"description" : "User's unique identifier",
"required" : true,
"style" : "simple",
"schema" : {
"type" : "string",
"format" : "uuid"
}
}, {
"name" : "institutionId",
"in" : "query",
"description" : "Institution's unique internal identifier",
"required" : true,
"style" : "form",
"schema" : {
"type" : "string"
}
} ],
"requestBody" : {
"content" : {
"application/json" : {
"schema" : {
"$ref" : "#/components/schemas/UpdateUserDto"
}
}
}
},
"responses" : {
"204" : {
"description" : "No Content"
},
"400" : {
"description" : "Bad Request",
"content" : {
"application/problem+json" : {
"schema" : {
"$ref" : "#/components/schemas/Problem"
}
}
}
},
"401" : {
"description" : "Unauthorized",
"content" : {
"application/problem+json" : {
"schema" : {
"$ref" : "#/components/schemas/Problem"
}
}
}
},
"500" : {
"description" : "Internal Server Error",
"content" : {
"application/problem+json" : {
"schema" : {
"$ref" : "#/components/schemas/Problem"
}
}
}
}
},
"security" : [ {
"bearerAuth" : [ "global" ]
} ]
}
}
},
"components" : {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ class SwaggerConfigTest {
@MockBean
private UserService userServiceMock;

@MockBean
private UserV2Service userV2ServiceMock;

@MockBean
private BrokerService brokerService;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

@Slf4j
@Service
@ConditionalOnProperty(value = "dashboard.user.client.api-version", havingValue = "v2")
@RequiredArgsConstructor
public class UserConnectorImpl implements UserApiConnector {

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

import it.pagopa.selfcare.dashboard.connector.model.institution.InstitutionInfo;
import it.pagopa.selfcare.dashboard.connector.model.user.*;

import java.util.Collection;
import java.util.UUID;

public interface UserV2Service {

void updateUser(UUID id, String institutionId, MutableUserFieldsDto userDto);

Collection<InstitutionInfo> getInstitutions(String userId);


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package it.pagopa.selfcare.dashboard.core;

import it.pagopa.selfcare.commons.base.logging.LogUtils;
import it.pagopa.selfcare.dashboard.connector.api.MsCoreConnector;
import it.pagopa.selfcare.dashboard.connector.api.UserApiConnector;
import it.pagopa.selfcare.dashboard.connector.api.UserRegistryConnector;
import it.pagopa.selfcare.dashboard.connector.exception.ResourceNotFoundException;
import it.pagopa.selfcare.dashboard.connector.model.institution.Institution;
import it.pagopa.selfcare.dashboard.connector.model.institution.InstitutionInfo;
import it.pagopa.selfcare.dashboard.connector.model.user.*;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;

import java.util.Collection;
import java.util.EnumSet;
import java.util.Optional;
import java.util.UUID;
import java.util.stream.Collectors;

import static it.pagopa.selfcare.dashboard.connector.model.user.User.Fields.*;

@Slf4j
@Service
@RequiredArgsConstructor
public class UserV2ServiceImpl implements UserV2Service {

private final MsCoreConnector msCoreConnector;
private final UserApiConnector userApiConnector;

@Override
public void updateUser(UUID id, String institutionId, MutableUserFieldsDto userDto) {
log.trace("updateUser start");
log.debug(LogUtils.CONFIDENTIAL_MARKER, "updateUser id = {}, institutionId = {}, userDto = {}", id, institutionId, userDto);
Assert.notNull(id, "UUID is required");
Assert.hasText(institutionId, "An institutionId is required");
Assert.notNull(userDto, "A userDto is required");
Institution institution = msCoreConnector.getInstitution(institutionId);
if (institution == null) {
throw new ResourceNotFoundException("There are no institution for given institutionId");
}
userApiConnector.updateUser(id.toString(), institutionId, userDto);
log.trace("updateUser end");
}

@Override
public Collection<InstitutionInfo> getInstitutions(String userId) {
log.trace("getInstitutions start");
Collection<InstitutionInfo> result = userApiConnector.getUserProducts(userId);
log.debug(LogUtils.CONFIDENTIAL_MARKER, "getInstitutions result = {}", result);
log.trace("getInstitutions end");
return result;
}

}
Loading
Loading