Skip to content

Commit

Permalink
fixing first access
Browse files Browse the repository at this point in the history
  • Loading branch information
LuciaM1 committed Jul 19, 2024
1 parent ae96902 commit e9717a1
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,7 @@ public enum AppErrorCodeEnum {
PROFILE_NOT_FOUND("ATMLM_4000058", "Non esiste un profilo con l'id indicato", CONSTRAINT_VIOLATION),
PROFILE_OR_USER_NOT_FOUND("ATMLM_4000059","Utente o profilo non trovato", CONSTRAINT_VIOLATION),
NO_ASSOCIATION_FOUND("ATMLM_4000060","Nessuna associazione trovata", CONSTRAINT_VIOLATION),
ALL_FIELDS_ARE_BLANK("ATMLM_4000061", "Tutti i campi sono vuoti", BLANK_FIELDS),
USERS_ALREADY_ACCESSED("ATMLM_4000062", "Impossibile registrare l'utente come primo accesso: almeno un utente è già presente nel database", NOT_FIRST_ACCESS);
ALL_FIELDS_ARE_BLANK("ATMLM_4000061", "Tutti i campi sono vuoti", BLANK_FIELDS);
private final String errorCode;
private final String errorMessage;
private final AppErrorType type;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,5 @@ public enum AppErrorType {
CANNOT_ASSOCIATE,
NOT_EXISTING_USER_ID,
NOT_EXISTING_USER_PROFILE, CANNOT_REPLACE_ASSOCIATION,
BLANK_FIELDS,
NOT_FIRST_ACCESS
BLANK_FIELDS
}
Original file line number Diff line number Diff line change
Expand Up @@ -134,17 +134,19 @@ public Uni<Void> checkFirstAccess(String userId) {
return countUsers()
.onItem()
.transformToUni(count -> {
if (count != 0){
throw new AtmLayerException("Sono già presenti degli utenti nel sistema", Response.Status.BAD_REQUEST, AppErrorCodeEnum.USERS_ALREADY_ACCESSED);
}
UserInsertionWithProfilesDTO userInsertionWithProfilesDTO = new UserInsertionWithProfilesDTO();
List<Integer> profile = new ArrayList<>();
profile.add(5);
userInsertionWithProfilesDTO.setUserId(userId);
userInsertionWithProfilesDTO.setProfileIds(profile);
return insertUserWithProfiles(userInsertionWithProfilesDTO)
.onItem()
.transformToUni(list -> Uni.createFrom().voidItem());
if (count == 0) {
UserInsertionWithProfilesDTO userInsertionWithProfilesDTO = new UserInsertionWithProfilesDTO();
List<Integer> profile = new ArrayList<>();
profile.add(5);
userInsertionWithProfilesDTO.setUserId(userId);
userInsertionWithProfilesDTO.setProfileIds(profile);
userInsertionWithProfilesDTO.setName("");
userInsertionWithProfilesDTO.setSurname("");
return insertUserWithProfiles(userInsertionWithProfilesDTO)
.onItem()
.transformToUni(list -> Uni.createFrom().voidItem());
}
return Uni.createFrom().voidItem();
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,8 @@ void testCheckFirstAccessWhenUsersExist() {
userServiceImpl.checkFirstAccess(userId)
.subscribe()
.withSubscriber(UniAssertSubscriber.create())
.assertFailedWith(AtmLayerException.class);
.assertCompleted()
.assertItem(null);

verify(userRepository, times(1)).count();
verify(userProfilesService, never()).insertUserProfiles(any(UserProfilesInsertionDTO.class));
Expand Down

0 comments on commit e9717a1

Please sign in to comment.