Skip to content

Commit

Permalink
[SELC-5193] feat: Modify Endpoint Response for Existing ACTIVE User-I…
Browse files Browse the repository at this point in the history
…nstitution Association (#163)
  • Loading branch information
manuraf authored Jul 2, 2024
1 parent dc8771d commit d0be865
Show file tree
Hide file tree
Showing 9 changed files with 194 additions and 101 deletions.
16 changes: 9 additions & 7 deletions apps/user-ms/src/main/docs/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -433,15 +433,14 @@
},
"responses" : {
"200" : {
"description" : "OK",
"description" : "User created or updated!",
"content" : {
"application/json" : {
"schema" : {
"type" : "string"
}
}
"application/json" : { }
}
},
"201" : {
"description" : "User already has the active role for that product!"
},
"401" : {
"description" : "Not Authorized"
},
Expand Down Expand Up @@ -911,11 +910,14 @@
},
"responses" : {
"200" : {
"description" : "OK",
"description" : "User created or updated!",
"content" : {
"application/json" : { }
}
},
"201" : {
"description" : "User already has the active role for that product!"
},
"401" : {
"description" : "Not Authorized"
},
Expand Down
12 changes: 7 additions & 5 deletions apps/user-ms/src/main/docs/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -304,11 +304,11 @@ paths:
$ref: "#/components/schemas/CreateUserDto"
responses:
"200":
description: OK
description: User created or updated!
content:
application/json:
schema:
type: string
application/json: {}
"201":
description: User already has the active role for that product!
"401":
description: Not Authorized
"403":
Expand Down Expand Up @@ -636,9 +636,11 @@ paths:
$ref: "#/components/schemas/AddUserRoleDto"
responses:
"200":
description: OK
description: User created or updated!
content:
application/json: {}
"201":
description: User already has the active role for that product!
"401":
description: Not Authorized
"403":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import it.pagopa.selfcare.user.model.constants.OnboardedProductState;
import it.pagopa.selfcare.user.service.UserRegistryService;
import it.pagopa.selfcare.user.service.UserService;
import it.pagopa.selfcare.user.service.utils.OPERATION_TYPE;
import jakarta.inject.Inject;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotNull;
Expand All @@ -29,6 +30,8 @@
import org.apache.http.HttpStatus;
import org.eclipse.microprofile.openapi.annotations.Operation;
import org.eclipse.microprofile.openapi.annotations.parameters.RequestBody;
import org.eclipse.microprofile.openapi.annotations.responses.APIResponse;
import org.eclipse.microprofile.openapi.annotations.responses.APIResponses;
import org.eclipse.microprofile.openapi.annotations.tags.Tag;
import org.jboss.resteasy.reactive.ResponseStatus;

Expand Down Expand Up @@ -268,7 +271,10 @@ public Uni<Void> updateUserProductStatus(@PathParam("id") String userId,
* @param userDto CreateUserDto
*/
@Operation(summary = "The createOrUpdateByUserId function is used to update existing user adding userRole.")
@ResponseStatus(HttpStatus.SC_NO_CONTENT)
@APIResponses({
@APIResponse(responseCode = "200", description = "User created or updated!"),
@APIResponse(responseCode = "201", description = "User already has the active role for that product!"),
})
@POST
@Path("/{userId}")
@Consumes(MediaType.APPLICATION_JSON)
Expand All @@ -278,7 +284,8 @@ public Uni<Response> createOrUpdateByUserId(@PathParam("userId") String userId,
@Context SecurityContext ctx) {
return readUserIdFromToken(ctx)
.onItem().transformToUni(loggedUser -> userService.createOrUpdateUserByUserId(userDto, userId, loggedUser))
.map(ignore -> Response.status(HttpStatus.SC_NO_CONTENT).build());
.onItem().ifNotNull().transform(ignore -> Response.status(HttpStatus.SC_CREATED).build())
.onItem().ifNull().continueWith(Response.status(HttpStatus.SC_OK).build());

}

Expand All @@ -291,15 +298,21 @@ public Uni<Response> createOrUpdateByUserId(@PathParam("userId") String userId,
*
* @param userDto CreateUserDto
*/
@APIResponses({
@APIResponse(responseCode = "200", description = "User created or updated!"),
@APIResponse(responseCode = "201", description = "User already has the active role for that product!"),
})
@Operation(summary = "The createOrUpdateByFiscalCode function is used to create a new user or update an existing one.")
@ResponseStatus(HttpStatus.SC_OK)
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Uni<String> createOrUpdateByFiscalCode(@Valid CreateUserDto userDto,
public Uni<Response> createOrUpdateByFiscalCode(@Valid CreateUserDto userDto,
@Context SecurityContext ctx) {
return readUserIdFromToken(ctx)
.onItem().transformToUni(loggedUser -> userService.createOrUpdateUserByFiscalCode(userDto, loggedUser));
.onItem().transformToUni(loggedUser -> userService.createOrUpdateUserByFiscalCode(userDto, loggedUser))
.map(response -> Response
.status(OPERATION_TYPE.CREATED_OR_UPDATED.equals(response.getOperationType()) ? HttpStatus.SC_CREATED : HttpStatus.SC_OK)
.entity(response.getUserId()).build());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import it.pagopa.selfcare.user.model.LoggedUser;
import it.pagopa.selfcare.user.model.UserNotificationToSend;
import it.pagopa.selfcare.user.model.constants.OnboardedProductState;
import it.pagopa.selfcare.user.service.utils.CreateOrUpdateUserByFiscalCodeResponse;
import org.openapi.quarkus.user_registry_json.model.UserResource;

import java.time.LocalDateTime;
Expand Down Expand Up @@ -49,9 +50,9 @@ public interface UserService {

Uni<Void> updateUserProductStatus(String userId, String institutionId, String productId, OnboardedProductState status, String productRole, LoggedUser loggedUser);

Uni<String> createOrUpdateUserByFiscalCode(CreateUserDto userDto, LoggedUser loggedUser);
Uni<CreateOrUpdateUserByFiscalCodeResponse> createOrUpdateUserByFiscalCode(CreateUserDto userDto, LoggedUser loggedUser);

Uni<Void> createOrUpdateUserByUserId(AddUserRoleDto userDto, String userId, LoggedUser loggedUser);
Uni<String> createOrUpdateUserByUserId(AddUserRoleDto userDto, String userId, LoggedUser loggedUser);

Multi<UserDataResponse> retrieveUsersData(String institutionId, String personId, List<String> roles, List<String> states, List<String> products, List<String> productRoles, String userId);

Expand Down
Loading

0 comments on commit d0be865

Please sign in to comment.