Class ActorRestController
java.lang.Object
de.gustavblass.fsu.fmi.roombooking.controller.ActorRestController
Defines the behaviour of the API server for the path
/api/users.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static enumPre-compiled UriTemplates for HATEOAS-compliant API responses. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final @NonNull ActorMapperprivate final @NonNull ActorServiceUsed to retrieve and save Actors from the database. -
Constructor Summary
ConstructorsConstructorDescriptionActorRestController(@NonNull ActorService actorService, @NonNull ActorMapper actorMapper) Constructs a newActorRestControllerwith the givenactorService. -
Method Summary
Modifier and TypeMethodDescription@NonNull org.springframework.hateoas.EntityModel<ActorDTO> HandlesGETrequests to/api/v1/user/{userName}and fetches theActorwith the specifiedActor.userNamefrom the database, converts it to anActorDTOobject and returns that.@NonNull org.springframework.hateoas.PagedModel<org.springframework.hateoas.EntityModel<ActorDTO>> getActors(int page, @Max(20L) int size, @Pattern(regexp="^(?!password).+$",message="{users.sort-by.error.password}") @NonNull String sortBy, boolean ascending) HandlesGETrequests to/api/v1/users.@NonNull org.springframework.http.ResponseEntity<Void> registerViaLdap(@NonNull @Valid LdapRegistrationActorDTO actorDTO) HandlesPOSTrequests to/api/v1/register/ldapand creates a newActorbased on the givenLdapRegistrationActorDTO.
-
Field Details
-
actorService
Used to retrieve and save Actors from the database. -
actorMapper
-
-
Constructor Details
-
ActorRestController
public ActorRestController(@NonNull @NonNull ActorService actorService, @NonNull @NonNull ActorMapper actorMapper) Constructs a newActorRestControllerwith the givenactorService.- Parameters:
actorService- TheactorServiceto use for database access.actorMapper- TheactorMapperfor conversion to/from data-transfer objects.
-
-
Method Details
-
getActors
@GetMapping("/api/v1/users") @PreAuthorize("hasRole('FACULTY_ADMINISTRATION')") @NonNull public @NonNull org.springframework.hateoas.PagedModel<org.springframework.hateoas.EntityModel<ActorDTO>> getActors(@RequestParam(name="page",defaultValue="0") int page, @Max(20L) @RequestParam(name="size",defaultValue="2") @Max(20L) int size, @Pattern(regexp="^(?!password).+$",message="{users.sort-by.error.password}") @RequestParam(name="sortBy",defaultValue="id") @NonNull @Pattern(regexp="^(?!password).+$",message="{users.sort-by.error.password}") @NonNull String sortBy, @RequestParam(name="ascending",defaultValue="true") boolean ascending) HandlesGETrequests to/api/v1/users. Retrieves a paginated subset of all Actors according to the URL parameters given.- Parameters:
page- The index of the page requested.size- How many Actor items each page in the pagination has.sortBy- Which of the Actors' fields shall be used to sort the items. Determines the order of the items and thereby also which items are present on the requested page. Must not be the password.ascending- Whether to count from the start or from the end of the list sorted usingsortBy.- Returns:
- The specified subset of all Actors as data-transfer objects.
-
getActor
@GetMapping("/api/v1/users/{userName}") @PreAuthorize("#userName == authentication.principal.getUsername() or hasRole('FACULTY_ADMINISTRATION')") @NonNull public @NonNull org.springframework.hateoas.EntityModel<ActorDTO> getActor(@NonNull @PathVariable @NonNull String userName) throws NotFoundException HandlesGETrequests to/api/v1/user/{userName}and fetches theActorwith the specifiedActor.userNamefrom the database, converts it to anActorDTOobject and returns that.- Parameters:
userName- The user name of the Actor that shall be returned.- Returns:
- The requested user, represented as a data-transfer object.
- Throws:
NotFoundException- If there is no user with the given user name.
-
registerViaLdap
@PostMapping("/api/v1/register/ldap") @NonNull public @NonNull org.springframework.http.ResponseEntity<Void> registerViaLdap(@NonNull @RequestBody @Valid @NonNull @Valid LdapRegistrationActorDTO actorDTO) throws IllegalStateException, AlreadyExistsException, de.gustavblass.commons.exceptions.IllegalArgumentException HandlesPOSTrequests to/api/v1/register/ldapand creates a newActorbased on the givenLdapRegistrationActorDTO. TheLdapRegistrationActorDTO.passwordis not stored in the database; it will be verified against an LDAP server during every login process.- Parameters:
actorDTO- The new Actor. Must exist at the LDAP server configured. TheActor.userNamemust not be taken already.- Returns:
- Empty response. Only the status code indicates success. The response's
locationheader will point to the URI of the new Actor. - Throws:
IllegalStateException- If LDAP is not configured.AlreadyExistsException- If the user name is already taken.de.gustavblass.commons.exceptions.IllegalArgumentException- If the login credentials are invalid.
-