Skip to content

Commit

Permalink
[SELC-6102] feat: add mobilePhone in getUserDetailsById API (#232)
Browse files Browse the repository at this point in the history
  • Loading branch information
giulia-tremolada authored Nov 28, 2024
1 parent d890e99 commit 4d7e51f
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 18 deletions.
3 changes: 3 additions & 0 deletions apps/user-ms/src/main/docs/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -1713,6 +1713,9 @@
"email" : {
"$ref" : "#/components/schemas/CertifiableFieldResponseString"
},
"mobilePhone" : {
"$ref" : "#/components/schemas/CertifiableFieldResponseString"
},
"workContacts" : {
"type" : "object",
"additionalProperties" : {
Expand Down
2 changes: 2 additions & 0 deletions apps/user-ms/src/main/docs/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1248,6 +1248,8 @@ components:
$ref: "#/components/schemas/CertifiableFieldResponseString"
email:
$ref: "#/components/schemas/CertifiableFieldResponseString"
mobilePhone:
$ref: "#/components/schemas/CertifiableFieldResponseString"
workContacts:
type: object
additionalProperties:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@ public class UserDetailResponse {
private CertifiableFieldResponse<String> name;
private CertifiableFieldResponse<String> familyName;
private CertifiableFieldResponse<String> email;
private CertifiableFieldResponse<String> mobilePhone;
private Map<String, WorkContactResponse> workContacts;
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,7 @@
import org.mapstruct.Mapping;
import org.mapstruct.Named;
import org.mapstruct.factory.Mappers;
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 org.openapi.quarkus.user_registry_json.model.SaveUserDto;
import org.openapi.quarkus.user_registry_json.model.CertifiableFieldResourceOfLocalDate;
import org.openapi.quarkus.user_registry_json.model.*;

import java.time.LocalDate;
import java.util.*;
Expand All @@ -38,6 +33,7 @@ public interface UserMapper {
UserResponse toUserResponse(UserResource userResource, String userMailUuid);

@Mapping(target = "email", expression = "java(retrieveCertifiedMailFromWorkContacts(userResource, userMailUuid))")
@Mapping(target = "mobilePhone", expression = "java(retrieveCertifiedMobilePhoneFromWorkContacts(userResource, userMailUuid))")
@Mapping(source = "userResource.familyName", target = "familyName", qualifiedByName = "toCertifiableFieldResponse")
@Mapping(source = "userResource.name", target = "name", qualifiedByName = "toCertifiableFieldResponse")
@Mapping(target = "workContacts", expression = "java(toWorkContactResponse(userResource.getWorkContacts()))")
Expand Down Expand Up @@ -85,11 +81,22 @@ default String retrieveMailFromWorkContacts(Map<String, WorkContactResource> map


@Named("retrieveCertifiedMailFromWorkContacts")
default CertifiableFieldResponse<String> retrieveCertifiedMailFromWorkContacts(UserResource userResource, String userMailUuid){
if(userResource.getWorkContacts()!=null && !userResource.getWorkContacts().isEmpty() && userResource.getWorkContacts().containsKey(userMailUuid)){
return new CertifiableFieldResponse<>(userResource.getWorkContacts().get(userMailUuid).getEmail().getValue(), userResource.getWorkContacts().get(userMailUuid).getEmail().getCertification());
}
return null;
default CertifiableFieldResponse<String> retrieveCertifiedMailFromWorkContacts(UserResource userResource, String userMailUuid) {
return Optional.ofNullable(userResource)
.map(UserResource::getWorkContacts)
.map(workContacts -> workContacts.get(userMailUuid))
.map(WorkContactResource::getEmail)
.map(email -> new CertifiableFieldResponse<>(email.getValue(), email.getCertification()))
.orElse(null);
}

@Named("retrieveCertifiedMobilePhoneFromWorkContacts")
default CertifiableFieldResponse<String> retrieveCertifiedMobilePhoneFromWorkContacts(UserResource userResource, String userMailUuid) {
return Optional.ofNullable(userResource.getWorkContacts())
.map(workContacts -> workContacts.get(userMailUuid))
.map(WorkContactResource::getMobilePhone)
.map(mobilePhone -> new CertifiableFieldResponse<>(mobilePhone.getValue(), mobilePhone.getCertification()))
.orElse(null);
}

@Named("toCertifiableFieldResponse")
Expand Down
3 changes: 3 additions & 0 deletions apps/user-ms/src/main/openapi/user_registry.json
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,9 @@
"properties" : {
"email" : {
"$ref" : "#/components/schemas/CertifiableFieldResourceOfstring"
},
"mobilePhone" : {
"$ref" : "#/components/schemas/CertifiableFieldResourceOfstring"
}
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,15 @@ class UserControllerTest {
private static final UserDetailResponse userDetailResponse;

static {
CertifiableFieldResourceOfstring email = new CertifiableFieldResourceOfstring(CertifiableFieldResourceOfstring.CertificationEnum.NONE, "email");
CertifiableFieldResourceOfstring phone = new CertifiableFieldResourceOfstring(CertifiableFieldResourceOfstring.CertificationEnum.NONE, "mobilePhone");

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"))));
userResource.setWorkContacts(Map.of("userMailUuid", new WorkContactResource(email, phone)));

userDetailResponse = new UserDetailResponse();
userDetailResponse.setId(UUID.randomUUID().toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,33 @@ public class UserMapperTest {
void retrieveCertifiedEmailFromWorkContacts(){
final UserResource userResource = new UserResource();
final CertifiableFieldResourceOfstring email = new CertifiableFieldResourceOfstring(CertifiableFieldResourceOfstring.CertificationEnum.NONE, "email");
WorkContactResource workContactResource = new WorkContactResource(email);
Map<String, WorkContactResource> workContactResourceMap = Map.of("email", workContactResource);
final CertifiableFieldResourceOfstring phone = new CertifiableFieldResourceOfstring(CertifiableFieldResourceOfstring.CertificationEnum.NONE, "mobilePhone");
WorkContactResource workContactResource = new WorkContactResource(email, phone);
Map<String, WorkContactResource> workContactResourceMap = Map.of("contactsUuid", workContactResource);
userResource.setWorkContacts(workContactResourceMap);

CertifiableFieldResponse<String> certifiedMail = userMapper.retrieveCertifiedMailFromWorkContacts(userResource, "email");
CertifiableFieldResponse<String> certifiedMail = userMapper.retrieveCertifiedMailFromWorkContacts(userResource, "contactsUuid");

assertEquals(CertifiableFieldResourceOfstring.CertificationEnum.NONE,certifiedMail.getCertified());
assertEquals("email", certifiedMail.getValue());
}

@Test
void retrieveCertifiedMobilePhoneFromWorkContacts(){
final UserResource userResource = new UserResource();
final CertifiableFieldResourceOfstring email = new CertifiableFieldResourceOfstring(CertifiableFieldResourceOfstring.CertificationEnum.NONE, "email");
String mobilePhone = "mobilePhone";
final CertifiableFieldResourceOfstring phone = new CertifiableFieldResourceOfstring(CertifiableFieldResourceOfstring.CertificationEnum.NONE, mobilePhone);
WorkContactResource workContactResource = new WorkContactResource(email, phone);
Map<String, WorkContactResource> workContactResourceMap = Map.of("contactsUuid", workContactResource);
userResource.setWorkContacts(workContactResourceMap);

CertifiableFieldResponse<String> certifiedPhone = userMapper.retrieveCertifiedMobilePhoneFromWorkContacts(userResource, "contactsUuid");

assertEquals(CertifiableFieldResourceOfstring.CertificationEnum.NONE,certifiedPhone.getCertified());
assertEquals(mobilePhone, certifiedPhone.getValue());
}

@Test
void retrieveCertifiedEmailFromWorkContacts_nullWorkContacts(){
final UserResource userResource = new UserResource();
Expand All @@ -45,7 +62,8 @@ void retrieveCertifiedEmailFromWorkContacts_nullWorkContacts(){
void retrieveCertifiedEmailFromWorkContacts_notPresent(){
final UserResource userResource = new UserResource();
final CertifiableFieldResourceOfstring email = new CertifiableFieldResourceOfstring(CertifiableFieldResourceOfstring.CertificationEnum.NONE, "email");
WorkContactResource workContactResource = new WorkContactResource(email);
final CertifiableFieldResourceOfstring phone = new CertifiableFieldResourceOfstring(CertifiableFieldResourceOfstring.CertificationEnum.NONE, "mobilePhone");
WorkContactResource workContactResource = new WorkContactResource(email, phone);
Map<String, WorkContactResource> workContactResourceMap = Map.of("email", workContactResource);
userResource.setWorkContacts(workContactResourceMap);

Expand All @@ -58,7 +76,8 @@ void retrieveCertifiedEmailFromWorkContacts_notPresent(){
@Test
void retrieveMailFromWorkContacts(){
final CertifiableFieldResourceOfstring email = new CertifiableFieldResourceOfstring(CertifiableFieldResourceOfstring.CertificationEnum.NONE, "email");
WorkContactResource workContactResource = new WorkContactResource(email);
final CertifiableFieldResourceOfstring phone = new CertifiableFieldResourceOfstring(CertifiableFieldResourceOfstring.CertificationEnum.NONE, "mobilePhone");
WorkContactResource workContactResource = new WorkContactResource(email, phone);
Map<String, WorkContactResource> workContactResourceMap = Map.of("email", workContactResource);

String mailFromWorkContact = userMapper.retrieveMailFromWorkContacts(workContactResourceMap, "email");
Expand Down Expand Up @@ -87,7 +106,8 @@ void retrieveMailFromWorkContacts_nullMap(){
@Test
void retrieveMailFromWorkContacts_notPresent(){
final CertifiableFieldResourceOfstring email = new CertifiableFieldResourceOfstring(CertifiableFieldResourceOfstring.CertificationEnum.NONE, "email");
WorkContactResource workContactResource = new WorkContactResource(email);
final CertifiableFieldResourceOfstring phone = new CertifiableFieldResourceOfstring(CertifiableFieldResourceOfstring.CertificationEnum.NONE, "mobilePhone");
WorkContactResource workContactResource = new WorkContactResource(email, phone);
Map<String, WorkContactResource> workContactResourceMap = Map.of("email", workContactResource);

String mailFromWorkContact = userMapper.retrieveMailFromWorkContacts(workContactResourceMap, "notPresent");
Expand Down

0 comments on commit 4d7e51f

Please sign in to comment.