-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #81 from CaritasDeutschland/update-consultant-admi…
…n-api Update consultant admin api
- Loading branch information
Showing
51 changed files
with
1,322 additions
and
419 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -126,7 +126,7 @@ paths: | |
operationId: updateConsultant | ||
requestBody: | ||
content: | ||
'application/hal+json': | ||
'application/json': | ||
schema: | ||
$ref: '#/components/schemas/UpdateConsultantDTO' | ||
required: true | ||
|
@@ -141,7 +141,7 @@ paths: | |
200: | ||
description: OK - consultant was updated successfully | ||
content: | ||
'application/json': | ||
'application/hal+json': | ||
schema: | ||
$ref: '#/components/schemas/ConsultantAdminResponseDTO' | ||
400: | ||
|
@@ -549,15 +549,23 @@ components: | |
username: | ||
type: string | ||
example: "max.mustermann" | ||
minLength: 1 | ||
maxLength: 255 | ||
firstname: | ||
type: string | ||
example: "Max" | ||
minLength: 1 | ||
maxLength: 255 | ||
lastname: | ||
type: string | ||
example: "Mustermann" | ||
minLength: 1 | ||
maxLength: 255 | ||
email: | ||
type: string | ||
example: "[email protected]" | ||
minLength: 1 | ||
maxLength: 255 | ||
formalLanguage: | ||
type: boolean | ||
example: true | ||
|
@@ -567,6 +575,8 @@ components: | |
absenceMessage: | ||
type: string | ||
example: "I am absent until..." | ||
minLength: 1 | ||
maxLength: 10000 | ||
|
||
UpdateConsultantDTO: | ||
type: object | ||
|
@@ -580,12 +590,18 @@ components: | |
firstname: | ||
type: string | ||
example: "Max" | ||
minLength: 1 | ||
maxLength: 255 | ||
lastname: | ||
type: string | ||
example: "Mustermann" | ||
minLength: 1 | ||
maxLength: 255 | ||
email: | ||
type: string | ||
example: "[email protected]" | ||
minLength: 1 | ||
maxLength: 255 | ||
formalLanguage: | ||
type: boolean | ||
example: true | ||
|
@@ -595,6 +611,8 @@ components: | |
absenceMessage: | ||
type: string | ||
example: "I am absent until..." | ||
minLength: 1 | ||
maxLength: 10000 | ||
|
||
ConsultantDTO: | ||
type: object | ||
|
@@ -737,6 +755,8 @@ components: | |
example: 15 | ||
role: | ||
type: string | ||
minLength: 1 | ||
maxLength: 255 | ||
|
||
ViolationDTO: | ||
type: object | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
.../caritas/cob/userservice/api/admin/service/consultant/update/ConsultantUpdateService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package de.caritas.cob.userservice.api.admin.service.consultant.update; | ||
|
||
import de.caritas.cob.userservice.api.admin.service.consultant.validation.ConsultantInputValidator; | ||
import de.caritas.cob.userservice.api.admin.service.consultant.validation.UpdateConsultantDTOAbsenceInputAdapter; | ||
import de.caritas.cob.userservice.api.exception.httpresponses.BadRequestException; | ||
import de.caritas.cob.userservice.api.model.UpdateConsultantDTO; | ||
import de.caritas.cob.userservice.api.model.registration.UserDTO; | ||
import de.caritas.cob.userservice.api.repository.consultant.Consultant; | ||
import de.caritas.cob.userservice.api.service.ConsultantService; | ||
import de.caritas.cob.userservice.api.service.RocketChatService; | ||
import de.caritas.cob.userservice.api.service.helper.KeycloakAdminClientService; | ||
import java.time.LocalDateTime; | ||
import java.time.ZoneOffset; | ||
import lombok.NonNull; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
|
||
/** | ||
* Service class to provide update functionality for consultants. | ||
*/ | ||
@Service | ||
@RequiredArgsConstructor | ||
public class ConsultantUpdateService { | ||
|
||
private final @NonNull KeycloakAdminClientService keycloakAdminClientService; | ||
private final @NonNull ConsultantService consultantService; | ||
private final @NonNull ConsultantInputValidator consultantInputValidator; | ||
private final @NonNull RocketChatService rocketChatService; | ||
|
||
/** | ||
* Updates the basic data of consultant with given id. | ||
* | ||
* @param consultantId the id of the consultant to update | ||
* @param updateConsultantDTO the update input data | ||
* @return the updated persisted {@link Consultant} | ||
*/ | ||
public Consultant updateConsultant(String consultantId, UpdateConsultantDTO updateConsultantDTO) { | ||
this.consultantInputValidator | ||
.validateAbsence(new UpdateConsultantDTOAbsenceInputAdapter(updateConsultantDTO)); | ||
|
||
Consultant consultant = | ||
this.consultantService.getConsultant(consultantId) | ||
.orElseThrow(() -> new BadRequestException( | ||
String.format("Consultant with id %s does not exist", consultantId))); | ||
|
||
UserDTO userDTO = buildValidatedUserDTO(updateConsultantDTO, consultant); | ||
this.keycloakAdminClientService.updateUserData(consultant.getId(), userDTO, | ||
updateConsultantDTO.getFirstname(), updateConsultantDTO.getLastname()); | ||
|
||
this.rocketChatService.updateUser(consultant.getRocketChatId(), updateConsultantDTO); | ||
|
||
return updateDatabaseConsultant(updateConsultantDTO, consultant); | ||
} | ||
|
||
private UserDTO buildValidatedUserDTO(UpdateConsultantDTO updateConsultantDTO, | ||
Consultant consultant) { | ||
UserDTO userDTO = new UserDTO(); | ||
userDTO.setEmail(updateConsultantDTO.getEmail()); | ||
userDTO.setUsername(consultant.getUsername()); | ||
|
||
this.consultantInputValidator.validateUserDTO(userDTO); | ||
return userDTO; | ||
} | ||
|
||
private Consultant updateDatabaseConsultant(UpdateConsultantDTO updateConsultantDTO, | ||
Consultant consultant) { | ||
consultant.setFirstName(updateConsultantDTO.getFirstname()); | ||
consultant.setLastName(updateConsultantDTO.getLastname()); | ||
consultant.setEmail(updateConsultantDTO.getEmail()); | ||
consultant.setLanguageFormal(updateConsultantDTO.getFormalLanguage()); | ||
consultant.setAbsent(updateConsultantDTO.getAbsent()); | ||
consultant.setAbsenceMessage(updateConsultantDTO.getAbsenceMessage()); | ||
consultant.setUpdateDate(LocalDateTime.now(ZoneOffset.UTC)); | ||
|
||
return this.consultantService.saveConsultant(consultant); | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
...ritas/cob/userservice/api/admin/service/consultant/validation/AbsenceInputValidation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package de.caritas.cob.userservice.api.admin.service.consultant.validation; | ||
|
||
public interface AbsenceInputValidation { | ||
|
||
boolean isAbsent(); | ||
|
||
String absenceMessage(); | ||
|
||
} |
Oops, something went wrong.