Class EquipmentAdminController
java.lang.Object
de.gustavblass.fsu.fmi.roombooking.controller.admin.EquipmentAdminController
Defines the behaviour of the API server for the path
/admin/equipment.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static enumRepresents templates in the resources, allowing one or several EquipmentTypes to be rendered as HTML. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final EquipmentServiceUsed to fetch existing EquipmentTypes from the database.private final @NonNull EquipmentTypeMapperConverts data-transfer objects to EquipmentTypes.private final @NonNull PathLocaliserUsed to resolve the URL paths in the correctLocale. -
Constructor Summary
ConstructorsConstructorDescriptionEquipmentAdminController(@NonNull EquipmentService equipmentService, @NonNull EquipmentTypeMapper equipmentTypeMapper, @NonNull PathLocaliser pathLocaliser) Constructs a newEquipmentAdminController. -
Method Summary
Modifier and TypeMethodDescription@NonNull StringcreateEquipmentType(@Valid @NonNull EquipmentTypeDTO dto, @NonNull org.springframework.validation.BindingResult bindingResult, @NonNull org.springframework.ui.Model model, @NonNull jakarta.servlet.http.HttpServletResponse response) HandlesPOSTrequests to/admin/equipment/newand adds the givenEquipmentTypeDTOas a newEquipmentTypeto the database.@NonNull StringdeleteEquipmentType(@NonNull String name, @NonNull Locale locale) Removes theEquipmentTypewith the givenEquipmentType.namefrom the database if existent.@NonNull StringgetCreateEquipmentTypeForm(@NonNull EquipmentTypeDTO equipmentTypeDTO, @NonNull org.springframework.ui.Model model) HandlesGETrequests to/admin/equipment.@NonNull StringgetDeleteTypeConfirmationPage(@NonNull String name, @NonNull org.springframework.ui.Model model) HandlesGETrequests to/admin/equipment/{name}/deleteand asks the user whether they really wish to delete theEquipmentTypewith the givenEquipmentType.namefrom the database.@NonNull StringgetEquipmentTypes(@NonNull EquipmentTypeDTO equipmentTypeDTO, @NonNull org.springframework.ui.Model model) HandlesGETrequests to/admin/equipment.
-
Field Details
-
equipmentService
Used to fetch existing EquipmentTypes from the database. -
equipmentTypeMapper
Converts data-transfer objects to EquipmentTypes. -
pathLocaliser
Used to resolve the URL paths in the correctLocale.
-
-
Constructor Details
-
EquipmentAdminController
public EquipmentAdminController(@NonNull @NonNull EquipmentService equipmentService, @NonNull @NonNull EquipmentTypeMapper equipmentTypeMapper, @NonNull @NonNull PathLocaliser pathLocaliser) Constructs a newEquipmentAdminController.- Parameters:
equipmentService- TheequipmentService.equipmentTypeMapper- TheequipmentTypeMapper.pathLocaliser- ThepathLocaliserto use for localising paths.
-
-
Method Details
-
getEquipmentTypes
@GetMapping({"/admin/ausstattung","/en/admin/equipment"}) @NonNull public @NonNull String getEquipmentTypes(@NonNull @NonNull EquipmentTypeDTO equipmentTypeDTO, @NonNull @NonNull org.springframework.ui.Model model) HandlesGETrequests to/admin/equipment.- Parameters:
equipmentTypeDTO- An emptyEquipmentTypeDTOonly used for binding in the Thymeleaf template.model- Used to add the existing EquipmentTypes to the form.- Returns:
- The admins' equipment page.
-
getCreateEquipmentTypeForm
@GetMapping({"/admin/ausstattung/neu","/en/admin/equipment/new"}) @NonNull public @NonNull String getCreateEquipmentTypeForm(@NonNull @NonNull EquipmentTypeDTO equipmentTypeDTO, @NonNull @NonNull org.springframework.ui.Model model) HandlesGETrequests to/admin/equipment.- Parameters:
equipmentTypeDTO- An emptyEquipmentTypeDTOonly used for binding in the Thymeleaf template.model- Used to add the existing EquipmentTypes to the form.- Returns:
- The admins' equipment page.
-
createEquipmentType
@PostMapping({"/admin/ausstattung/neu","/en/admin/equipment/new"}) @NonNull public @NonNull String createEquipmentType(@Valid @NonNull @Valid @NonNull EquipmentTypeDTO dto, @NonNull @NonNull org.springframework.validation.BindingResult bindingResult, @NonNull @NonNull org.springframework.ui.Model model, @NonNull @NonNull jakarta.servlet.http.HttpServletResponse response) throws IllegalStateException, InvalidEquipmentException HandlesPOSTrequests to/admin/equipment/newand adds the givenEquipmentTypeDTOas a newEquipmentTypeto the database.- Parameters:
dto- The data-transfer object that represents the new EquipmentType. Must be valid according to the annotations on the class fieldsbindingResult- The result of the DTO validation.model- Used to add the existing EquipmentTypes to the form.response- The web server's response to the admin's HTTP request.- Returns:
- In case of success: The equipment page. Otherwise: The form, with the original input preserved and with error messages shown.
- Throws:
InvalidEquipmentException- If theEquipmentTypeDTO.typeis invalid.IllegalStateException- If the equipment path is malformed.
-
getDeleteTypeConfirmationPage
@GetMapping({"/admin/ausstattung/{name}/l\u00f6schen","/en/admin/equipment/{name}/delete"}) @NonNull public @NonNull String getDeleteTypeConfirmationPage(@NonNull @PathVariable @NonNull String name, @NonNull @NonNull org.springframework.ui.Model model) throws NotFoundException, de.gustavblass.commons.exceptions.IllegalArgumentException HandlesGETrequests to/admin/equipment/{name}/deleteand asks the user whether they really wish to delete theEquipmentTypewith the givenEquipmentType.namefrom the database.- Parameters:
name- The title of the EquipmentType to be deleted.model- Used to display the details of the EquipmentType.- Returns:
- A confirmation form.
- Throws:
NotFoundException- If the given EquipmentType does not exist.de.gustavblass.commons.exceptions.IllegalArgumentException- SeeEquipmentTypeMapper.toDto(EquipmentType).
-
deleteEquipmentType
@PostMapping({"/admin/ausstattung/{name}/l\u00f6schen","/en/admin/equipment/delete"}) @NonNull public @NonNull String deleteEquipmentType(@NonNull @PathVariable @NonNull String name, @NonNull @NonNull Locale locale) throws NotFoundException, IllegalStateException Removes theEquipmentTypewith the givenEquipmentType.namefrom the database if existent. Also removes allRoomEquipmentthat has theRoomEquipment.typethat shall be deleted.- Parameters:
name- The title of the EquipmentType to delete.locale- The language of the request.- Returns:
- Redirects to the list of all equipment types.
- Throws:
NotFoundException- If no EquipmentType with the given name exists.IllegalStateException- If the equipment URL is malformed.
-