feat(#5): Add title-body control element that can be added dynamically, refactored sectionIndex/create

This commit is contained in:
2025-11-02 10:32:46 +01:00
parent 4d371be2e3
commit 736cd17789
12 changed files with 407 additions and 88 deletions

View File

@@ -224,6 +224,57 @@ paths:
"503":
$ref: "https://api.swaggerhub.com/domains/smartbear-public/ProblemDetails/1.0.0#/components/responses/ServiceUnavailable"
/application-forms/{applicationFormId}/sections/{sectionId}/form-elements:
post:
summary: Add a new form element to a specific section
operationId: addFormElementToSection
tags:
- application-form
parameters:
- name: applicationFormId
in: path
required: true
schema:
type: string
format: uuid
description: The ID of the application form
- name: sectionId
in: path
required: true
schema:
type: string
format: uuid
description: The ID of the form element section
- name: position
in: query
required: true
schema:
type: integer
description: The position to insert the form element
requestBody:
required: true
content:
application/json:
schema:
$ref: "#/components/schemas/CreateFormElementDto"
responses:
"201":
description: Form element successfully added
content:
application/json:
schema:
$ref: "#/components/schemas/ApplicationFormDto"
"400":
$ref: "https://api.swaggerhub.com/domains/smartbear-public/ProblemDetails/1.0.0#/components/responses/BadRequest"
"401":
$ref: "https://api.swaggerhub.com/domains/smartbear-public/ProblemDetails/1.0.0#/components/responses/Unauthorized"
"404":
$ref: "https://api.swaggerhub.com/domains/smartbear-public/ProblemDetails/1.0.0#/components/responses/NotFound"
"500":
$ref: "https://api.swaggerhub.com/domains/smartbear-public/ProblemDetails/1.0.0#/components/responses/ServerError"
"503":
$ref: "https://api.swaggerhub.com/domains/smartbear-public/ProblemDetails/1.0.0#/components/responses/ServiceUnavailable"
####### Application Form Templates #######
/application-form-templates:
get:
@@ -1080,6 +1131,7 @@ components:
- RADIOBUTTON
- TEXTFIELD
- SWITCH
- TITLE_BODY_TEXTFIELDS
####### UserDto #######
UserDto:

View File

@@ -3,6 +3,7 @@ package com.betriebsratkanzlei.legalconsenthub.application_form
import com.betriebsratkanzlei.legalconsenthub_api.api.ApplicationFormApi
import com.betriebsratkanzlei.legalconsenthub_api.model.ApplicationFormDto
import com.betriebsratkanzlei.legalconsenthub_api.model.CreateApplicationFormDto
import com.betriebsratkanzlei.legalconsenthub_api.model.CreateFormElementDto
import com.betriebsratkanzlei.legalconsenthub_api.model.PagedApplicationFormDto
import org.springframework.core.io.ByteArrayResource
import org.springframework.core.io.Resource
@@ -108,4 +109,24 @@ class ApplicationFormController(
applicationFormService.submitApplicationForm(id),
),
)
@PreAuthorize(
"hasAnyRole('CHIEF_EXECUTIVE_OFFICER', 'BUSINESS_DEPARTMENT', 'IT_DEPARTMENT', 'HUMAN_RESOURCES', 'HEAD_OF_WORKS_COUNCIL', 'WORKS_COUNCIL')",
)
override fun addFormElementToSection(
applicationFormId: UUID,
sectionId: UUID,
position: Int,
createFormElementDto: CreateFormElementDto,
): ResponseEntity<ApplicationFormDto> =
ResponseEntity.status(201).body(
applicationFormMapper.toApplicationFormDto(
applicationFormService.addFormElementToSection(
applicationFormId,
sectionId,
createFormElementDto,
position,
),
),
)
}

View File

@@ -5,10 +5,13 @@ import com.betriebsratkanzlei.legalconsenthub.error.ApplicationFormNotCreatedExc
import com.betriebsratkanzlei.legalconsenthub.error.ApplicationFormNotDeletedException
import com.betriebsratkanzlei.legalconsenthub.error.ApplicationFormNotFoundException
import com.betriebsratkanzlei.legalconsenthub.error.ApplicationFormNotUpdatedException
import com.betriebsratkanzlei.legalconsenthub.error.FormElementSectionNotFoundException
import com.betriebsratkanzlei.legalconsenthub.form_element.FormElementMapper
import com.betriebsratkanzlei.legalconsenthub.notification.NotificationService
import com.betriebsratkanzlei.legalconsenthub_api.model.ApplicationFormDto
import com.betriebsratkanzlei.legalconsenthub_api.model.ApplicationFormStatus
import com.betriebsratkanzlei.legalconsenthub_api.model.CreateApplicationFormDto
import com.betriebsratkanzlei.legalconsenthub_api.model.CreateFormElementDto
import com.betriebsratkanzlei.legalconsenthub_api.model.CreateNotificationDto
import com.betriebsratkanzlei.legalconsenthub_api.model.NotificationType
import org.springframework.data.domain.Page
@@ -20,6 +23,7 @@ import java.util.UUID
class ApplicationFormService(
private val applicationFormRepository: ApplicationFormRepository,
private val applicationFormMapper: ApplicationFormMapper,
private val formElementMapper: FormElementMapper,
private val notificationService: NotificationService,
) {
fun createApplicationForm(createApplicationFormDto: CreateApplicationFormDto): ApplicationForm {
@@ -45,7 +49,6 @@ class ApplicationFormService(
}
fun updateApplicationForm(applicationFormDto: ApplicationFormDto): ApplicationForm {
// TODO find statt mappen?
val applicationForm = applicationFormMapper.toApplicationForm(applicationFormDto)
val updatedApplicationForm: ApplicationForm
@@ -112,4 +115,35 @@ class ApplicationFormService(
notificationService.createNotificationForOrganization(createNotificationDto)
}
fun addFormElementToSection(
applicationFormId: UUID,
sectionId: UUID,
createFormElementDto: CreateFormElementDto,
position: Int,
): ApplicationForm {
val applicationForm = getApplicationFormById(applicationFormId)
val section =
applicationForm.formElementSections
.find { it.id == sectionId }
?: throw FormElementSectionNotFoundException(sectionId)
val newFormElement = formElementMapper.toFormElement(createFormElementDto, section)
if (position >= 0 && position < section.formElements.size) {
section.formElements.add(position, newFormElement)
} else {
section.formElements.add(newFormElement)
}
val updatedApplicationForm =
try {
applicationFormRepository.save(applicationForm)
} catch (e: Exception) {
throw ApplicationFormNotUpdatedException(e, applicationFormId)
}
return updatedApplicationForm
}
}