-
Notifications
You must be signed in to change notification settings - Fork 9
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 #61 from CaritasDeutschland/feature-admin-session-…
…interface Feature admin session interface
- Loading branch information
Showing
52 changed files
with
2,356 additions
and
254 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 |
---|---|---|
@@ -0,0 +1,167 @@ | ||
openapi: 3.0.1 | ||
info: | ||
title: will be replaced | ||
description: This information will be replaced by the SpringFox config information | ||
version: 0.0.1 | ||
servers: | ||
- url: / | ||
paths: | ||
/useradmin: | ||
get: | ||
tags: | ||
- root-controller | ||
summary: 'Returns the hal root entry point. [Authorization: Role: user-admin]' | ||
operationId: getRoot | ||
responses: | ||
200: | ||
description: OK - successfull operation | ||
content: | ||
application/hal+json: | ||
schema: | ||
$ref: '#/components/schemas/RootDTO' | ||
security: | ||
- Bearer: [ ] | ||
/useradmin/session: | ||
get: | ||
tags: | ||
- admin-user-controller | ||
summary: 'Returns the list of agencies by search query parameter. [Authorization: Role: | ||
user-admin]' | ||
operationId: getSessions | ||
parameters: | ||
- name: filter | ||
in: query | ||
description: 'The filter parameters to search for. If no filter is set all sessions are | ||
being returned. If more than one filter is set the first given filter is used only.' | ||
schema: | ||
type: object | ||
properties: | ||
agency: | ||
type: integer | ||
asker: | ||
type: string | ||
consultant: | ||
type: string | ||
consultingType: | ||
type: integer | ||
- name: page | ||
in: query | ||
description: Number of page where to start in the query (1 = first page) | ||
required: true | ||
schema: | ||
type: integer | ||
- name: perPage | ||
in: query | ||
description: Number of items which are being returned per page | ||
required: true | ||
schema: | ||
type: integer | ||
responses: | ||
200: | ||
description: OK - successfull operation | ||
content: | ||
'application/hal+json': | ||
schema: | ||
$ref: '#/components/schemas/SessionAdminResultDTO' | ||
400: | ||
description: BAD REQUEST - invalid/incomplete request or body object | ||
401: | ||
description: UNAUTHORIZED - no/invalid role/authorization | ||
500: | ||
description: INTERNAL SERVER ERROR - server encountered unexpected condition | ||
security: | ||
- Bearer: [ ] | ||
|
||
components: | ||
schemas: | ||
RootDTO: | ||
type: object | ||
required: | ||
- _links | ||
properties: | ||
_links: | ||
$ref: '#/components/schemas/RootLinks' | ||
|
||
RootLinks: | ||
type: object | ||
required: | ||
- self | ||
properties: | ||
self: | ||
$ref: '#/components/schemas/HalLink' | ||
sessions: | ||
$ref: '#/components/schemas/HalLink' | ||
|
||
HalLink: | ||
type: object | ||
required: | ||
- href | ||
properties: | ||
href: | ||
type: string | ||
method: | ||
type: string | ||
enum: [ GET, POST, DELETE, PUT ] | ||
templated: | ||
type: boolean | ||
|
||
SessionAdminResultDTO: | ||
type: object | ||
properties: | ||
_embedded: | ||
type: array | ||
items: | ||
$ref: '#/components/schemas/SessionAdminDTO' | ||
_links: | ||
$ref: '#/components/schemas/SessionAdminResultLinks' | ||
|
||
SessionAdminDTO: | ||
type: object | ||
properties: | ||
userId: | ||
type: string | ||
example: "1da238c6-cd46-4162-80f1-bff74eafe77f" | ||
consultantId: | ||
type: string | ||
example: "1da238c6-cd46-4162-80f1-bff74eafe77f" | ||
username: | ||
type: string | ||
example: "enc.OBSXEZTPOJWWC3TDMUWWC43LMVZC2NZS" | ||
email: | ||
type: string | ||
example: "[email protected]" | ||
consultingType: | ||
type: integer | ||
example: 1 | ||
postcode: | ||
type: string | ||
example: "12345" | ||
agencyId: | ||
type: integer | ||
example: 1 | ||
isTeamSession: | ||
type: boolean | ||
messageDate: | ||
type: string | ||
createDate: | ||
type: string | ||
updateDate: | ||
type: string | ||
|
||
SessionAdminResultLinks: | ||
type: object | ||
required: | ||
- self | ||
properties: | ||
self: | ||
$ref: '#/components/schemas/HalLink' | ||
next: | ||
$ref: '#/components/schemas/HalLink' | ||
previous: | ||
$ref: '#/components/schemas/HalLink' | ||
|
||
securitySchemes: | ||
Bearer: | ||
type: apiKey | ||
name: Authorization | ||
in: header |
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
53 changes: 53 additions & 0 deletions
53
src/main/java/de/caritas/cob/userservice/api/admin/controller/SessionAdminController.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,53 @@ | ||
package de.caritas.cob.userservice.api.admin.controller; | ||
|
||
import de.caritas.cob.userservice.api.admin.hallink.RootDTOBuilder; | ||
import de.caritas.cob.userservice.api.admin.service.SessionAdminService; | ||
import de.caritas.cob.userservice.api.model.Filter; | ||
import de.caritas.cob.userservice.api.model.RootDTO; | ||
import de.caritas.cob.userservice.api.model.SessionAdminResultDTO; | ||
import de.caritas.cob.userservice.generated.api.admin.controller.UseradminApi; | ||
import javax.validation.Valid; | ||
import javax.validation.constraints.NotNull; | ||
import lombok.NonNull; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
/** | ||
* Controller to handle all session admin requests. | ||
*/ | ||
@RestController | ||
@RequiredArgsConstructor | ||
public class SessionAdminController implements UseradminApi { | ||
|
||
private final @NonNull SessionAdminService sessionAdminService; | ||
|
||
/** | ||
* Creates the root hal based navigation entity. | ||
* | ||
* @return an entity containing the available navigation hal links | ||
*/ | ||
@Override | ||
public ResponseEntity<RootDTO> getRoot() { | ||
RootDTO rootDTO = new RootDTOBuilder().buildRootDTO(); | ||
return ResponseEntity.ok(rootDTO); | ||
} | ||
|
||
/** | ||
* Entry point to retrieve sessions. | ||
* | ||
* @param page Number of page where to start in the query (1 = first page) (required) | ||
* @param perPage Number of items which are being returned (required) | ||
* @param filter The filters to restrict results (optional) | ||
* @return an entity containing the filtered sessions | ||
*/ | ||
@Override | ||
public ResponseEntity<SessionAdminResultDTO> getSessions(@NotNull @Valid Integer page, | ||
@NotNull @Valid Integer perPage, @Valid Filter filter) { | ||
SessionAdminResultDTO sessionAdminResultDTO = this.sessionAdminService | ||
.findSessions(page, perPage, filter); | ||
return ResponseEntity.ok(sessionAdminResultDTO); | ||
} | ||
|
||
|
||
} |
21 changes: 21 additions & 0 deletions
21
src/main/java/de/caritas/cob/userservice/api/admin/hallink/HalLinkBuilder.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,21 @@ | ||
package de.caritas.cob.userservice.api.admin.hallink; | ||
|
||
import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.linkTo; | ||
|
||
import de.caritas.cob.userservice.api.model.HalLink; | ||
import de.caritas.cob.userservice.api.model.HalLink.MethodEnum; | ||
import org.springframework.hateoas.Link; | ||
import org.springframework.http.HttpEntity; | ||
|
||
public interface HalLinkBuilder { | ||
|
||
default HalLink buildHalLink(HttpEntity<?> httpEntity, MethodEnum method) { | ||
Link link = linkTo(httpEntity).withSelfRel(); | ||
HalLink halLink = new HalLink(); | ||
halLink.setHref(link.getHref()); | ||
halLink.setMethod(method); | ||
halLink.setTemplated(link.isTemplated()); | ||
return halLink; | ||
} | ||
|
||
} |
41 changes: 41 additions & 0 deletions
41
src/main/java/de/caritas/cob/userservice/api/admin/hallink/RootDTOBuilder.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,41 @@ | ||
package de.caritas.cob.userservice.api.admin.hallink; | ||
|
||
import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.methodOn; | ||
|
||
import de.caritas.cob.userservice.api.admin.controller.SessionAdminController; | ||
import de.caritas.cob.userservice.api.model.HalLink; | ||
import de.caritas.cob.userservice.api.model.HalLink.MethodEnum; | ||
import de.caritas.cob.userservice.api.model.RootDTO; | ||
import de.caritas.cob.userservice.api.model.RootLinks; | ||
|
||
/** | ||
* Builder to create the root navigation hal DTO. | ||
*/ | ||
public class RootDTOBuilder implements HalLinkBuilder { | ||
|
||
public static final Integer DEFAULT_PAGE = 1; | ||
public static final Integer DEFAULT_PER_PAGE = 20; | ||
|
||
/** | ||
* Builds the root navigation DTO. | ||
* | ||
* @return the {@link RootDTO} containing hal links | ||
*/ | ||
public RootDTO buildRootDTO() { | ||
return new RootDTO() | ||
.links(new RootLinks() | ||
.self(buildSelfLink()) | ||
.sessions(buildSessionsLink())); | ||
} | ||
|
||
private HalLink buildSelfLink() { | ||
return buildHalLink(methodOn(SessionAdminController.class).getRoot(), MethodEnum.GET); | ||
} | ||
|
||
private HalLink buildSessionsLink() { | ||
return buildHalLink( | ||
methodOn(SessionAdminController.class).getSessions(DEFAULT_PAGE, DEFAULT_PER_PAGE, null), | ||
MethodEnum.GET); | ||
} | ||
|
||
} |
42 changes: 42 additions & 0 deletions
42
...ain/java/de/caritas/cob/userservice/api/admin/pageprovider/AgencySessionPageProvider.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,42 @@ | ||
package de.caritas.cob.userservice.api.admin.pageprovider; | ||
|
||
import static java.util.Objects.nonNull; | ||
|
||
import de.caritas.cob.userservice.api.model.Filter; | ||
import de.caritas.cob.userservice.api.repository.session.Session; | ||
import de.caritas.cob.userservice.api.repository.session.SessionRepository; | ||
import lombok.NonNull; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.data.domain.Page; | ||
import org.springframework.data.domain.Pageable; | ||
|
||
/** | ||
* Page provider for {@link Session} filtered by agency. | ||
*/ | ||
@RequiredArgsConstructor | ||
public class AgencySessionPageProvider implements SessionPageProvider { | ||
|
||
private final @NonNull SessionRepository sessionRepository; | ||
private final @NonNull Filter filter; | ||
|
||
/** | ||
* Executes the search query on the repository. | ||
* | ||
* @param pageable the pageable to split the results | ||
* @return a {@link Page} object containing the results | ||
*/ | ||
@Override | ||
public Page<Session> executeQuery(Pageable pageable) { | ||
return this.sessionRepository.findByAgencyId(filter.getAgency().longValue(), pageable); | ||
} | ||
|
||
/** | ||
* Validates the agency filter. | ||
* | ||
* @return true if filter has agency set | ||
*/ | ||
@Override | ||
public boolean isSupported() { | ||
return nonNull(this.filter.getAgency()); | ||
} | ||
} |
Oops, something went wrong.