diff --git a/legalconsenthub-backend/api/legalconsenthub.yml b/legalconsenthub-backend/api/legalconsenthub.yml index 30518ca..4fd507d 100644 --- a/legalconsenthub-backend/api/legalconsenthub.yml +++ b/legalconsenthub-backend/api/legalconsenthub.yml @@ -124,6 +124,119 @@ paths: "503": $ref: "https://api.swaggerhub.com/domains/smartbear-public/ProblemDetails/1.0.0#/components/responses/ServiceUnavailable" + /application-form-templates: + get: + summary: Get all ApplicationFormTemplates + operationId: getAllApplicationFormTemplates + tags: + - application-form-template + responses: + "200": + description: Paged list of application form templates + content: + application/json: + schema: + $ref: "#/components/schemas/PagedApplicationFormDto" + "500": + description: Internal server error + post: + summary: Create a new ApplicationFormTemplate + operationId: createApplicationFormTemplate + tags: + - application-form-template + requestBody: + required: true + content: + application/json: + schema: + $ref: "#/components/schemas/CreateApplicationFormDto" + responses: + "201": + description: Successfully created application form template + 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" + "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/{id}: + parameters: + - name: id + in: path + required: true + schema: + type: string + format: uuid + get: + summary: Get a specific ApplicationFormTemplate + operationId: getApplicationFormTemplateById + tags: + - application-form-template + responses: + "200": + description: Get application form template by ID + 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" + "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" + put: + summary: Updates a ApplicationFormTemplate + operationId: updateApplicationFormTemplate + tags: + - application-form-template + requestBody: + required: true + content: + application/json: + schema: + $ref: "#/components/schemas/ApplicationFormDto" + responses: + "200": + description: Successfully updated application form template + 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" + "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" + delete: + summary: Delete a ApplicationFormTemplate + operationId: deleteApplicationFormTemplate + tags: + - application-form-template + responses: + "204": + description: Application Form Template successfully deleted + "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" + "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" + /users: get: summary: Get all users @@ -563,6 +676,7 @@ components: required: - id - formElements + - isTemplate - createdAt - modifiedAt properties: @@ -573,6 +687,8 @@ components: type: array items: $ref: "#/components/schemas/FormElementDto" + isTemplate: + type: boolean createdAt: type: string format: date-time @@ -583,12 +699,16 @@ components: CreateApplicationFormDto: required: - formElements + - isTemplate type: object properties: formElements: type: array items: $ref: "#/components/schemas/CreateFormElementDto" + isTemplate: + type: boolean + default: false PagedApplicationFormDto: type: object diff --git a/legalconsenthub-backend/src/main/kotlin/com/betriebsratkanzlei/legalconsenthub/application_form/ApplicationForm.kt b/legalconsenthub-backend/src/main/kotlin/com/betriebsratkanzlei/legalconsenthub/application_form/ApplicationForm.kt index 35cc639..afaee54 100644 --- a/legalconsenthub-backend/src/main/kotlin/com/betriebsratkanzlei/legalconsenthub/application_form/ApplicationForm.kt +++ b/legalconsenthub-backend/src/main/kotlin/com/betriebsratkanzlei/legalconsenthub/application_form/ApplicationForm.kt @@ -1,6 +1,6 @@ package com.betriebsratkanzlei.legalconsenthub.application_form -import com.betriebsratkanzlei.legalconsenthub.formelement.FormElement +import com.betriebsratkanzlei.legalconsenthub.form_element.FormElement import jakarta.persistence.CascadeType import jakarta.persistence.Column import jakarta.persistence.Entity @@ -12,8 +12,6 @@ import org.springframework.data.annotation.CreatedDate import org.springframework.data.annotation.LastModifiedDate import org.springframework.data.jpa.domain.support.AuditingEntityListener import java.time.LocalDateTime -import java.time.OffsetDateTime -import java.util.Date import java.util.UUID @Entity @@ -26,6 +24,9 @@ class ApplicationForm( @OneToMany(mappedBy = "applicationForm", cascade = [CascadeType.ALL], orphanRemoval = true) var formElements: MutableList = mutableListOf(), + @Column(nullable = false) + var isTemplate: Boolean, + @CreatedDate @Column(nullable = false) var createdAt: LocalDateTime? = null, diff --git a/legalconsenthub-backend/src/main/kotlin/com/betriebsratkanzlei/legalconsenthub/application_form/ApplicationFormMapper.kt b/legalconsenthub-backend/src/main/kotlin/com/betriebsratkanzlei/legalconsenthub/application_form/ApplicationFormMapper.kt index 899aa79..7524b0c 100644 --- a/legalconsenthub-backend/src/main/kotlin/com/betriebsratkanzlei/legalconsenthub/application_form/ApplicationFormMapper.kt +++ b/legalconsenthub-backend/src/main/kotlin/com/betriebsratkanzlei/legalconsenthub/application_form/ApplicationFormMapper.kt @@ -11,6 +11,7 @@ class ApplicationFormMapper(private val formElementMapper: FormElementMapper) { return ApplicationFormDto( id = applicationForm.id ?: throw IllegalStateException("ApplicationForm ID must not be null!"), formElements = applicationForm.formElements.map { formElementMapper.toFormElementDto(it) }, + isTemplate = applicationForm.isTemplate, createdAt = applicationForm.createdAt ?: LocalDateTime.now(), modifiedAt = applicationForm.modifiedAt ?: LocalDateTime.now() ) @@ -20,13 +21,14 @@ class ApplicationFormMapper(private val formElementMapper: FormElementMapper) { return ApplicationForm( id = applicationForm.id, formElements = applicationForm.formElements.map { formElementMapper.toFormElement(it) }.toMutableList(), + isTemplate = applicationForm.isTemplate, createdAt = applicationForm.createdAt, modifiedAt = applicationForm.modifiedAt ) } fun toApplicationForm(createApplicationFormDto: CreateApplicationFormDto): ApplicationForm { - val applicationForm = ApplicationForm() + val applicationForm = ApplicationForm(isTemplate = createApplicationFormDto.isTemplate) applicationForm.formElements = createApplicationFormDto.formElements .map { formElementMapper.toFormElement(it, applicationForm) } .toMutableList() diff --git a/legalconsenthub-backend/src/main/kotlin/com/betriebsratkanzlei/legalconsenthub/application_form/ApplicationFormRepository.kt b/legalconsenthub-backend/src/main/kotlin/com/betriebsratkanzlei/legalconsenthub/application_form/ApplicationFormRepository.kt index 2f791b7..3d36f05 100644 --- a/legalconsenthub-backend/src/main/kotlin/com/betriebsratkanzlei/legalconsenthub/application_form/ApplicationFormRepository.kt +++ b/legalconsenthub-backend/src/main/kotlin/com/betriebsratkanzlei/legalconsenthub/application_form/ApplicationFormRepository.kt @@ -1,8 +1,13 @@ package com.betriebsratkanzlei.legalconsenthub.application_form +import org.springframework.data.domain.Page +import org.springframework.data.domain.Pageable import org.springframework.data.jpa.repository.JpaRepository import org.springframework.stereotype.Repository import java.util.UUID @Repository -interface ApplicationFormRepository : JpaRepository +interface ApplicationFormRepository : JpaRepository { + fun findAllByIsTemplateTrue(page: Pageable): Page + fun findAllByIsTemplateFalse(page: Pageable): Page +} diff --git a/legalconsenthub-backend/src/main/kotlin/com/betriebsratkanzlei/legalconsenthub/application_form/ApplicationFormService.kt b/legalconsenthub-backend/src/main/kotlin/com/betriebsratkanzlei/legalconsenthub/application_form/ApplicationFormService.kt index 2f7ec78..420654b 100644 --- a/legalconsenthub-backend/src/main/kotlin/com/betriebsratkanzlei/legalconsenthub/application_form/ApplicationFormService.kt +++ b/legalconsenthub-backend/src/main/kotlin/com/betriebsratkanzlei/legalconsenthub/application_form/ApplicationFormService.kt @@ -35,7 +35,7 @@ class ApplicationFormService( fun getApplicationForms(): Page { val pageable = PageRequest.of(0, 10) - return applicationFormRepository.findAll(pageable) + return applicationFormRepository.findAllByIsTemplateFalse(pageable) } fun updateApplicationForm(applicationFormDto: ApplicationFormDto): ApplicationForm { diff --git a/legalconsenthub-backend/src/main/kotlin/com/betriebsratkanzlei/legalconsenthub/application_form/FormElementMapper.kt b/legalconsenthub-backend/src/main/kotlin/com/betriebsratkanzlei/legalconsenthub/application_form/FormElementMapper.kt index 664693e..686bedd 100644 --- a/legalconsenthub-backend/src/main/kotlin/com/betriebsratkanzlei/legalconsenthub/application_form/FormElementMapper.kt +++ b/legalconsenthub-backend/src/main/kotlin/com/betriebsratkanzlei/legalconsenthub/application_form/FormElementMapper.kt @@ -1,7 +1,7 @@ package com.betriebsratkanzlei.legalconsenthub.application_form import com.betriebsratkanzlei.legalconsenthub.error.ApplicationFormNotFoundException -import com.betriebsratkanzlei.legalconsenthub.formelement.FormElement +import com.betriebsratkanzlei.legalconsenthub.form_element.FormElement import com.betriebsratkanzlei.legalconsenthub_api.model.CreateFormElementDto import com.betriebsratkanzlei.legalconsenthub_api.model.FormElementDto import org.springframework.stereotype.Component diff --git a/legalconsenthub-backend/src/main/kotlin/com/betriebsratkanzlei/legalconsenthub/application_form/FormOptionMapper.kt b/legalconsenthub-backend/src/main/kotlin/com/betriebsratkanzlei/legalconsenthub/application_form/FormOptionMapper.kt index 443e908..868f49b 100644 --- a/legalconsenthub-backend/src/main/kotlin/com/betriebsratkanzlei/legalconsenthub/application_form/FormOptionMapper.kt +++ b/legalconsenthub-backend/src/main/kotlin/com/betriebsratkanzlei/legalconsenthub/application_form/FormOptionMapper.kt @@ -1,6 +1,6 @@ package com.betriebsratkanzlei.legalconsenthub.application_form -import com.betriebsratkanzlei.legalconsenthub.formelement.FormOption +import com.betriebsratkanzlei.legalconsenthub.form_element.FormOption import com.betriebsratkanzlei.legalconsenthub_api.model.FormOptionDto import org.springframework.stereotype.Component diff --git a/legalconsenthub-backend/src/main/kotlin/com/betriebsratkanzlei/legalconsenthub/application_form_template/ApplicationFormTemplateController.kt b/legalconsenthub-backend/src/main/kotlin/com/betriebsratkanzlei/legalconsenthub/application_form_template/ApplicationFormTemplateController.kt new file mode 100644 index 0000000..9620623 --- /dev/null +++ b/legalconsenthub-backend/src/main/kotlin/com/betriebsratkanzlei/legalconsenthub/application_form_template/ApplicationFormTemplateController.kt @@ -0,0 +1,59 @@ +package com.betriebsratkanzlei.legalconsenthub.application_form_template + +import com.betriebsratkanzlei.legalconsenthub.application_form.ApplicationFormMapper +import com.betriebsratkanzlei.legalconsenthub.application_form.PagedApplicationFormMapper +import com.betriebsratkanzlei.legalconsenthub_api.api.ApplicationFormTemplateApi +import com.betriebsratkanzlei.legalconsenthub_api.model.ApplicationFormDto +import com.betriebsratkanzlei.legalconsenthub_api.model.CreateApplicationFormDto +import com.betriebsratkanzlei.legalconsenthub_api.model.PagedApplicationFormDto +import org.springframework.http.ResponseEntity +import org.springframework.web.bind.annotation.RestController +import java.util.UUID + +@RestController +class ApplicationFormTemplateController( + val applicationFormTemplateService: ApplicationFormTemplateService, + val pagedApplicationFormMapper: PagedApplicationFormMapper, + val applicationFormMapper: ApplicationFormMapper, +) : ApplicationFormTemplateApi { + + override fun createApplicationFormTemplate(createApplicationFormDto: CreateApplicationFormDto): ResponseEntity { + return ResponseEntity.ok( + applicationFormMapper.toApplicationFormDto( + applicationFormTemplateService.createApplicationFormTemplate(createApplicationFormDto) + ) + ) + } + + override fun getAllApplicationFormTemplates(): ResponseEntity { + return ResponseEntity.ok( + pagedApplicationFormMapper.toPagedApplicationFormDto( + applicationFormTemplateService.getApplicationFormTemplates() + ) + ) + } + + override fun getApplicationFormTemplateById(id: UUID): ResponseEntity { + return ResponseEntity.ok( + applicationFormMapper.toApplicationFormDto( + applicationFormTemplateService.getApplicationFormTemplateById(id) + ) + ) + } + + override fun updateApplicationFormTemplate( + id: UUID, + applicationFormDto: ApplicationFormDto + ): ResponseEntity { + return ResponseEntity.ok( + applicationFormMapper.toApplicationFormDto( + applicationFormTemplateService.updateApplicationFormTemplate(applicationFormDto) + ) + ) + } + + override fun deleteApplicationFormTemplate(id: UUID): ResponseEntity { + applicationFormTemplateService.deleteApplicationFormTemplateByID(id) + return ResponseEntity.noContent().build() + } +} diff --git a/legalconsenthub-backend/src/main/kotlin/com/betriebsratkanzlei/legalconsenthub/application_form_template/ApplicationFormTemplateService.kt b/legalconsenthub-backend/src/main/kotlin/com/betriebsratkanzlei/legalconsenthub/application_form_template/ApplicationFormTemplateService.kt new file mode 100644 index 0000000..dcd3b49 --- /dev/null +++ b/legalconsenthub-backend/src/main/kotlin/com/betriebsratkanzlei/legalconsenthub/application_form_template/ApplicationFormTemplateService.kt @@ -0,0 +1,64 @@ +package com.betriebsratkanzlei.legalconsenthub.application_form_template + +import com.betriebsratkanzlei.legalconsenthub.application_form.ApplicationForm +import com.betriebsratkanzlei.legalconsenthub.application_form.ApplicationFormMapper +import com.betriebsratkanzlei.legalconsenthub.application_form.ApplicationFormRepository +import com.betriebsratkanzlei.legalconsenthub.error.ApplicationFormNotCreatedException +import com.betriebsratkanzlei.legalconsenthub.error.ApplicationFormNotDeletedException +import com.betriebsratkanzlei.legalconsenthub.error.ApplicationFormNotFoundException +import com.betriebsratkanzlei.legalconsenthub.error.ApplicationFormNotUpdatedException +import com.betriebsratkanzlei.legalconsenthub_api.model.ApplicationFormDto +import com.betriebsratkanzlei.legalconsenthub_api.model.CreateApplicationFormDto +import org.springframework.data.domain.Page +import org.springframework.data.domain.PageRequest +import org.springframework.stereotype.Service +import java.util.UUID + +@Service +class ApplicationFormTemplateService( + private val applicationFormRepository: ApplicationFormRepository, + private val applicationFormMapper: ApplicationFormMapper +) { + + fun createApplicationFormTemplate(createApplicationFormDto: CreateApplicationFormDto): ApplicationForm { + val applicationForm = applicationFormMapper.toApplicationForm(createApplicationFormDto) + val savedApplicationForm: ApplicationForm + try { + savedApplicationForm = applicationFormRepository.save(applicationForm) + } catch (e: Exception) { + throw ApplicationFormNotCreatedException(e) + } + + return savedApplicationForm + } + + fun getApplicationFormTemplateById(id: UUID): ApplicationForm { + return applicationFormRepository.findById(id).orElseThrow { ApplicationFormNotFoundException(id) } + } + + fun getApplicationFormTemplates(): Page { + val pageable = PageRequest.of(0, 10) + return applicationFormRepository.findAllByIsTemplateTrue(pageable) + } + + fun updateApplicationFormTemplate(applicationFormDto: ApplicationFormDto): ApplicationForm { + val applicationForm = applicationFormMapper.toApplicationForm(applicationFormDto) + val updatedApplicationForm: ApplicationForm + + try { + updatedApplicationForm = applicationFormRepository.save(applicationForm) + } catch (e: Exception) { + throw ApplicationFormNotUpdatedException(e, applicationFormDto.id) + } + + return updatedApplicationForm + } + + fun deleteApplicationFormTemplateByID(id: UUID) { + try { + applicationFormRepository.deleteById(id) + } catch (e: Exception) { + throw ApplicationFormNotDeletedException(e) + } + } +} diff --git a/legalconsenthub-backend/src/main/kotlin/com/betriebsratkanzlei/legalconsenthub/formelement/FormElement.kt b/legalconsenthub-backend/src/main/kotlin/com/betriebsratkanzlei/legalconsenthub/form_element/FormElement.kt similarity index 93% rename from legalconsenthub-backend/src/main/kotlin/com/betriebsratkanzlei/legalconsenthub/formelement/FormElement.kt rename to legalconsenthub-backend/src/main/kotlin/com/betriebsratkanzlei/legalconsenthub/form_element/FormElement.kt index 1e7ba99..2790143 100644 --- a/legalconsenthub-backend/src/main/kotlin/com/betriebsratkanzlei/legalconsenthub/formelement/FormElement.kt +++ b/legalconsenthub-backend/src/main/kotlin/com/betriebsratkanzlei/legalconsenthub/form_element/FormElement.kt @@ -1,4 +1,4 @@ -package com.betriebsratkanzlei.legalconsenthub.formelement; +package com.betriebsratkanzlei.legalconsenthub.form_element; import com.betriebsratkanzlei.legalconsenthub.application_form.ApplicationForm import com.betriebsratkanzlei.legalconsenthub_api.model.FormElementType diff --git a/legalconsenthub-backend/src/main/kotlin/com/betriebsratkanzlei/legalconsenthub/formelement/FormOption.kt b/legalconsenthub-backend/src/main/kotlin/com/betriebsratkanzlei/legalconsenthub/form_element/FormOption.kt similarity index 89% rename from legalconsenthub-backend/src/main/kotlin/com/betriebsratkanzlei/legalconsenthub/formelement/FormOption.kt rename to legalconsenthub-backend/src/main/kotlin/com/betriebsratkanzlei/legalconsenthub/form_element/FormOption.kt index c220685..ff891bd 100644 --- a/legalconsenthub-backend/src/main/kotlin/com/betriebsratkanzlei/legalconsenthub/formelement/FormOption.kt +++ b/legalconsenthub-backend/src/main/kotlin/com/betriebsratkanzlei/legalconsenthub/form_element/FormOption.kt @@ -1,4 +1,4 @@ -package com.betriebsratkanzlei.legalconsenthub.formelement; +package com.betriebsratkanzlei.legalconsenthub.form_element; import com.betriebsratkanzlei.legalconsenthub_api.model.EmployeeDataCategory import com.betriebsratkanzlei.legalconsenthub_api.model.ProcessingPurpose; diff --git a/legalconsenthub-backend/src/main/resources/db/migrations/001-schema.sql b/legalconsenthub-backend/src/main/resources/db/migrations/001-schema.sql index 7757d11..9c02104 100644 --- a/legalconsenthub-backend/src/main/resources/db/migrations/001-schema.sql +++ b/legalconsenthub-backend/src/main/resources/db/migrations/001-schema.sql @@ -1,5 +1,6 @@ create table application_form ( + is_template boolean not null, created_at timestamp(6) not null, modified_at timestamp(6) not null, id uuid not null,