Class ActorRestController

java.lang.Object
de.gustavblass.fsu.fmi.roombooking.controller.ActorRestController

@RestController public class ActorRestController extends Object
Defines the behaviour of the API server for the path /api/users.
  • Field Details

    • actorService

      @NonNull private final @NonNull ActorService actorService
      Used to retrieve and save Actors from the database.
    • actorMapper

      @NonNull private final @NonNull ActorMapper actorMapper
      Used to convert Actor objects to ActorDTO objects when returning them to the user.
  • Constructor Details

  • 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)
      Handles GET requests 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 using sortBy.
      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
      Handles GET requests to /api/v1/user/{userName} and fetches the Actor with the specified Actor.userName from the database, converts it to an ActorDTO object 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
      Handles POST requests to /api/v1/register/ldap and creates a new Actor based on the given LdapRegistrationActorDTO. The LdapRegistrationActorDTO.password is 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. The Actor.userName must not be taken already.
      Returns:
      Empty response. Only the status code indicates success. The response's location header 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.