Skip to content

Commit

Permalink
Merge pull request #79 from CaritasDeutschland/create-consultant-admi…
Browse files Browse the repository at this point in the history
…n-api

Create consultant admin api
  • Loading branch information
mobo4b authored Dec 16, 2020
2 parents 3c749e4 + 6a9dcf1 commit a1d8ac6
Show file tree
Hide file tree
Showing 31 changed files with 1,317 additions and 303 deletions.
56 changes: 11 additions & 45 deletions api/useradminservice.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ paths:
content:
'application/hal+json':
schema:
$ref: '#/components/schemas/CreateConsultantResponseDTO'
$ref: '#/components/schemas/ConsultantAdminResponseDTO'
400:
description: BAD REQUEST - invalid/incomplete request or body object
401:
Expand Down Expand Up @@ -108,7 +108,7 @@ paths:
content:
'application/json':
schema:
$ref: '#/components/schemas/GetConsultantResponseDTO'
$ref: '#/components/schemas/ConsultantAdminResponseDTO'
204:
description: NO CONTENT - consultant with the specific id was not found
400:
Expand Down Expand Up @@ -143,7 +143,7 @@ paths:
content:
'application/json':
schema:
$ref: '#/components/schemas/UpdateConsultantResponseDTO'
$ref: '#/components/schemas/ConsultantAdminResponseDTO'
400:
description: BAD REQUEST - invalid/incomplete request
401:
Expand Down Expand Up @@ -386,6 +386,8 @@ components:
$ref: '#/components/schemas/HalLink'
consultants:
$ref: '#/components/schemas/HalLink'
createConsultant:
$ref: '#/components/schemas/HalLink'

HalLink:
type: object
Expand Down Expand Up @@ -631,41 +633,25 @@ components:
deleteDate:
type: string

CreateConsultantResponseDTO:
ConsultantAdminResponseDTO:
type: object
properties:
_embedded:
$ref: '#/components/schemas/ConsultantDTO'
_links:
$ref: '#/components/schemas/CreateLinks'

GetConsultantResponseDTO:
type: object
properties:
_embedded:
$ref: '#/components/schemas/ConsultantDTO'
_links:
$ref: '#/components/schemas/GetLinks'

UpdateConsultantResponseDTO:
type: object
properties:
_embedded:
$ref: '#/components/schemas/ConsultantDTO'
_links:
$ref: '#/components/schemas/UpdateLinks'
$ref: '#/components/schemas/ConsultantLinks'

ConsultantSearchResultDTO:
type: object
properties:
_embedded:
type: array
items:
$ref: '#/components/schemas/ConsultantDTO'
$ref: '#/components/schemas/ConsultantAdminResponseDTO'
_links:
$ref: '#/components/schemas/PaginationLinks'

CreateLinks:
ConsultantLinks:
type: object
required:
- self
Expand All @@ -676,29 +662,9 @@ components:
$ref: '#/components/schemas/HalLink'
delete:
$ref: '#/components/schemas/HalLink'

GetLinks:
type: object
required:
- self
properties:
self:
$ref: '#/components/schemas/HalLink'
update:
$ref: '#/components/schemas/HalLink'
delete:
$ref: '#/components/schemas/HalLink'

UpdateLinks:
type: object
required:
- self
properties:
self:
$ref: '#/components/schemas/HalLink'
consultant:
agencies:
$ref: '#/components/schemas/HalLink'
delete:
addAgency:
$ref: '#/components/schemas/HalLink'

SessionFilter:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import de.caritas.cob.userservice.api.exception.NoMasterKeyException;
import de.caritas.cob.userservice.api.exception.httpresponses.BadRequestException;
import de.caritas.cob.userservice.api.exception.httpresponses.ConflictException;
import de.caritas.cob.userservice.api.exception.httpresponses.CustomValidationHttpStatusException;
import de.caritas.cob.userservice.api.exception.httpresponses.ForbiddenException;
import de.caritas.cob.userservice.api.exception.httpresponses.InternalServerErrorException;
import de.caritas.cob.userservice.api.exception.httpresponses.NoContentException;
Expand Down Expand Up @@ -38,7 +39,10 @@
public class ApiResponseEntityExceptionHandler extends ResponseEntityExceptionHandler {

/**
* Custom BadRequest exception
* Custom BadRequest exception.
*
* @param request the invoking request
* @param ex the thrown exception
*/
@ExceptionHandler({BadRequestException.class})
public ResponseEntity<Object> handleCustomBadRequest(final BadRequestException ex,
Expand All @@ -49,7 +53,25 @@ public ResponseEntity<Object> handleCustomBadRequest(final BadRequestException e
}

/**
* Constraint violations
* Custom BadRequest exception with header reason.
*
* @param request the invoking request
* @param ex the thrown exception
*/
@ExceptionHandler({CustomValidationHttpStatusException.class})
public ResponseEntity<Object> handleCustomBadRequest(final CustomValidationHttpStatusException ex,
final WebRequest request) {
ex.executeLogging();

return handleExceptionInternal(ex, null, ex.getCustomHttpHeader(), HttpStatus.BAD_REQUEST,
request);
}

/**
* Constraint violations.
*
* @param request the invoking request
* @param ex the thrown exception
*/
@ExceptionHandler(ConstraintViolationException.class)
public ResponseEntity<Object> handleBadRequest(final RuntimeException ex,
Expand All @@ -60,7 +82,10 @@ public ResponseEntity<Object> handleBadRequest(final RuntimeException ex,
}

/**
* Incoming request body could not be deserialized
* Incoming request body could not be deserialized.
*
* @param request the invoking request
* @param ex the thrown exception
*/
@Override
protected ResponseEntity<Object> handleHttpMessageNotReadable(
Expand All @@ -72,7 +97,10 @@ protected ResponseEntity<Object> handleHttpMessageNotReadable(
}

/**
* @Valid on object fails validation
* On object fails validation.
*
* @param request the invoking request
* @param ex the thrown exception
*/
@Override
protected ResponseEntity<Object> handleMethodArgumentNotValid(
Expand All @@ -84,7 +112,7 @@ protected ResponseEntity<Object> handleMethodArgumentNotValid(
}

/**
* 401 - Unauthorized
* 401 - Unauthorized.
*
* @param ex {@link UnauthorizedException}
* @param request {@link WebRequest}
Expand All @@ -99,7 +127,10 @@ public ResponseEntity<Object> handleUnauthorized(final UnauthorizedException ex,
}

/**
* 409 - Conflict
* 409 - Conflict.
*
* @param request the invoking request
* @param ex the thrown exception
*/
@ExceptionHandler({InvalidDataAccessApiUsageException.class, DataAccessException.class})
protected ResponseEntity<Object> handleConflict(final RuntimeException ex,
Expand All @@ -110,7 +141,10 @@ protected ResponseEntity<Object> handleConflict(final RuntimeException ex,
}

/**
* 409 - Conflict
* 409 - Conflict.
*
* @param request the invoking request
* @param ex the thrown exception
*/
@ExceptionHandler({ConflictException.class})
protected ResponseEntity<Object> handleCustomConflict(final ConflictException ex,
Expand All @@ -121,7 +155,10 @@ protected ResponseEntity<Object> handleCustomConflict(final ConflictException ex
}

/**
* 403 - Forbidden
* 403 - Forbidden.
*
* @param request the invoking request
* @param ex the thrown exception
*/
@ExceptionHandler({ForbiddenException.class})
public ResponseEntity<Object> handleForbidden(final ForbiddenException ex,
Expand All @@ -132,7 +169,10 @@ public ResponseEntity<Object> handleForbidden(final ForbiddenException ex,
}

/**
* 404 - Not Found
* 404 - Not Found.
*
* @param request the invoking request
* @param ex the thrown exception
*/
@ExceptionHandler({NotFoundException.class})
public ResponseEntity<Object> handleForbidden(final NotFoundException ex,
Expand All @@ -143,7 +183,10 @@ public ResponseEntity<Object> handleForbidden(final NotFoundException ex,
}

/**
* 500 - Internal Server Error
* 500 - Internal Server Error.
*
* @param request the invoking request
* @param ex the thrown exception
*/
@ExceptionHandler({NullPointerException.class, IllegalArgumentException.class,
IllegalStateException.class, KeycloakException.class,
Expand All @@ -157,7 +200,10 @@ public ResponseEntity<Object> handleInternal(final RuntimeException ex,
}

/**
* 500 - Custom Internal Server Error
* 500 - Custom Internal Server Error.
*
* @param request the invoking request
* @param ex the thrown exception
*/
@ExceptionHandler({InternalServerErrorException.class})
public ResponseEntity<Object> handleInternal(final InternalServerErrorException ex,
Expand All @@ -169,7 +215,10 @@ public ResponseEntity<Object> handleInternal(final InternalServerErrorException
}

/**
* 204 - No Content
* 204 - No Content.
*
* @param request the invoking request
* @param ex the thrown exception
*/
@ExceptionHandler({NoContentException.class})
public ResponseEntity<Object> handleInternal(final NoContentException ex,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,16 @@
import de.caritas.cob.userservice.api.admin.report.service.ViolationReportGenerator;
import de.caritas.cob.userservice.api.admin.service.ConsultingTypeAdminService;
import de.caritas.cob.userservice.api.admin.service.session.SessionAdminService;
import de.caritas.cob.userservice.api.model.ConsultantAdminResponseDTO;
import de.caritas.cob.userservice.api.model.ConsultantAgencyAdminResultDTO;
import de.caritas.cob.userservice.api.model.ConsultantFilter;
import de.caritas.cob.userservice.api.model.ConsultantSearchResultDTO;
import de.caritas.cob.userservice.api.model.ConsultingTypeAdminResultDTO;
import de.caritas.cob.userservice.api.model.CreateConsultantDTO;
import de.caritas.cob.userservice.api.model.CreateConsultantResponseDTO;
import de.caritas.cob.userservice.api.model.GetConsultantResponseDTO;
import de.caritas.cob.userservice.api.model.RootDTO;
import de.caritas.cob.userservice.api.model.SessionAdminResultDTO;
import de.caritas.cob.userservice.api.model.SessionFilter;
import de.caritas.cob.userservice.api.model.UpdateConsultantDTO;
import de.caritas.cob.userservice.api.model.UpdateConsultantResponseDTO;
import de.caritas.cob.userservice.api.model.ViolationDTO;
import de.caritas.cob.userservice.generated.api.admin.controller.UseradminApi;
import io.swagger.annotations.Api;
Expand Down Expand Up @@ -89,12 +87,12 @@ public ResponseEntity<ConsultingTypeAdminResultDTO> getConsultingTypes(
* Entry point to create a new consultant.
*
* @param createConsultantDTO (required)
* @return {@link CreateConsultantResponseDTO}
* @return {@link ConsultantAdminResponseDTO}
*/
@Override
public ResponseEntity<CreateConsultantResponseDTO> createConsultant(
public ResponseEntity<ConsultantAdminResponseDTO> createConsultant(
@Valid CreateConsultantDTO createConsultantDTO) {
return null;
return ResponseEntity.ok(this.consultantAdminFacade.createNewConsultant(createConsultantDTO));
}

/**
Expand Down Expand Up @@ -125,10 +123,10 @@ public ResponseEntity<Void> markConsultantForDeletion(@PathVariable String consu
*
* @param consultantId consultant id (required)
* @param updateConsultantDTO (required)
* @return {@link UpdateConsultantResponseDTO}
* @return {@link ConsultantAdminResponseDTO}
*/
@Override
public ResponseEntity<UpdateConsultantResponseDTO> updateConsultant(
public ResponseEntity<ConsultantAdminResponseDTO> updateConsultant(
@PathVariable String consultantId, @Valid UpdateConsultantDTO updateConsultantDTO) {
return null;
}
Expand All @@ -137,11 +135,11 @@ public ResponseEntity<UpdateConsultantResponseDTO> updateConsultant(
* Entry point to get a specific consultant.
*
* @param consultantId consultant id (required)
* @return {@link GetConsultantResponseDTO}
* @return {@link ConsultantAdminResponseDTO}
*/
@Override
public ResponseEntity<GetConsultantResponseDTO> getConsultant(String consultantId) {
GetConsultantResponseDTO responseDTO = this.consultantAdminFacade.findConsultant(consultantId);
public ResponseEntity<ConsultantAdminResponseDTO> getConsultant(String consultantId) {
ConsultantAdminResponseDTO responseDTO = this.consultantAdminFacade.findConsultant(consultantId);
return ResponseEntity.ok(responseDTO);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@
import de.caritas.cob.userservice.api.admin.service.consultant.ConsultantAdminFilterService;
import de.caritas.cob.userservice.api.admin.service.consultant.ConsultantAdminService;
import de.caritas.cob.userservice.api.model.ConsultantAgencyAdminResultDTO;
import de.caritas.cob.userservice.api.model.ConsultantAdminResponseDTO;
import de.caritas.cob.userservice.api.model.ConsultantFilter;
import de.caritas.cob.userservice.api.model.ConsultantResponseDTO;
import de.caritas.cob.userservice.api.model.ConsultantSearchResultDTO;
import de.caritas.cob.userservice.api.model.GetConsultantResponseDTO;
import de.caritas.cob.userservice.api.model.CreateConsultantDTO;
import de.caritas.cob.userservice.api.repository.consultant.Consultant;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
Expand All @@ -26,9 +29,9 @@ public class ConsultantAdminFacade {
* Finds a consultant by given consultant id.
*
* @param consultantId the id of the consultant to search for
* @return the generated {@link GetConsultantResponseDTO}
* @return the generated {@link ConsultantResponseDTO}
*/
public GetConsultantResponseDTO findConsultant(String consultantId) {
public ConsultantAdminResponseDTO findConsultant(String consultantId) {
return this.consultantAdminService.findConsultantById(consultantId);
}

Expand All @@ -47,6 +50,17 @@ public ConsultantSearchResultDTO findFilteredConsultants(Integer page, Integer p
consultantFilter);
}

/**
* Creates a new {@link Consultant} based on the {@link CreateConsultantDTO} input.
*
* @param createConsultantDTO the input data used for {@link Consultant} creation
* @return the generated and persisted {@link Consultant} representation as {@link
* ConsultantAdminResponseDTO}
*/
public ConsultantAdminResponseDTO createNewConsultant(CreateConsultantDTO createConsultantDTO) {
return this.consultantAdminService.createNewConsultant(createConsultantDTO);
}

/**
* Returns all Agencies for the given consultantId.
*
Expand Down
Loading

0 comments on commit a1d8ac6

Please sign in to comment.