From 66dabc329d0706474b248d8ce8fb8200c8710236 Mon Sep 17 00:00:00 2001 From: Denis Lugowski Date: Sun, 9 Mar 2025 09:11:35 +0100 Subject: [PATCH] feat(frontend,backend): Add application form name --- .../api/legalconsenthub.yml | 6 +++++ .../application_form/ApplicationForm.kt | 3 +++ .../application_form/ApplicationFormMapper.kt | 7 +++++- .../resources/db/migrations/001-schema.sql | 1 + legalconsenthub/pages/create.vue | 22 ++++++++++++++----- legalconsenthub/pages/index.vue | 11 ++++++++-- 6 files changed, 42 insertions(+), 8 deletions(-) diff --git a/legalconsenthub-backend/api/legalconsenthub.yml b/legalconsenthub-backend/api/legalconsenthub.yml index 4fd507d..277a925 100644 --- a/legalconsenthub-backend/api/legalconsenthub.yml +++ b/legalconsenthub-backend/api/legalconsenthub.yml @@ -675,6 +675,7 @@ components: type: object required: - id + - name - formElements - isTemplate - createdAt @@ -683,6 +684,8 @@ components: id: type: string format: uuid + name: + type: string formElements: type: array items: @@ -698,10 +701,13 @@ components: CreateApplicationFormDto: required: + - name - formElements - isTemplate type: object properties: + name: + type: string formElements: type: array items: 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 afaee54..39ae07f 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 @@ -21,6 +21,9 @@ class ApplicationForm( @GeneratedValue var id: UUID? = null, + @Column(nullable = false) + var name: String = "", + @OneToMany(mappedBy = "applicationForm", cascade = [CascadeType.ALL], orphanRemoval = true) var formElements: MutableList = mutableListOf(), 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 7524b0c..3e880d6 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 @@ -10,6 +10,7 @@ class ApplicationFormMapper(private val formElementMapper: FormElementMapper) { fun toApplicationFormDto(applicationForm: ApplicationForm): ApplicationFormDto { return ApplicationFormDto( id = applicationForm.id ?: throw IllegalStateException("ApplicationForm ID must not be null!"), + name = applicationForm.name, formElements = applicationForm.formElements.map { formElementMapper.toFormElementDto(it) }, isTemplate = applicationForm.isTemplate, createdAt = applicationForm.createdAt ?: LocalDateTime.now(), @@ -20,6 +21,7 @@ class ApplicationFormMapper(private val formElementMapper: FormElementMapper) { fun toApplicationForm(applicationForm: ApplicationFormDto): ApplicationForm { return ApplicationForm( id = applicationForm.id, + name = applicationForm.name, formElements = applicationForm.formElements.map { formElementMapper.toFormElement(it) }.toMutableList(), isTemplate = applicationForm.isTemplate, createdAt = applicationForm.createdAt, @@ -28,7 +30,10 @@ class ApplicationFormMapper(private val formElementMapper: FormElementMapper) { } fun toApplicationForm(createApplicationFormDto: CreateApplicationFormDto): ApplicationForm { - val applicationForm = ApplicationForm(isTemplate = createApplicationFormDto.isTemplate) + val applicationForm = ApplicationForm( + name = createApplicationFormDto.name, + isTemplate = createApplicationFormDto.isTemplate + ) applicationForm.formElements = createApplicationFormDto.formElements .map { formElementMapper.toFormElement(it, applicationForm) } .toMutableList() 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 9c02104..c8844cf 100644 --- a/legalconsenthub-backend/src/main/resources/db/migrations/001-schema.sql +++ b/legalconsenthub-backend/src/main/resources/db/migrations/001-schema.sql @@ -4,6 +4,7 @@ create table application_form created_at timestamp(6) not null, modified_at timestamp(6) not null, id uuid not null, + name varchar(255) not null, primary key (id) ); diff --git a/legalconsenthub/pages/create.vue b/legalconsenthub/pages/create.vue index 95f0c2f..15ac200 100644 --- a/legalconsenthub/pages/create.vue +++ b/legalconsenthub/pages/create.vue @@ -22,6 +22,9 @@ + + + Submit @@ -44,11 +47,20 @@ const { data } = await useAsyncData(async () => { return await getAllApplicationFormTemplates() }) -const formElements = computed({ - get: () => data?.value?.content[0].formElements ?? [], +const applicationFormTemplate = computed({ + get: () => data?.value?.content[0] ?? undefined, set: (val) => { if (val && data.value) { - data.value.content[0].formElements = val + data.value.content[0] = val + } + } +}) + +const formElements = computed({ + get: () => applicationFormTemplate.value?.formElements ?? [], + set: (val) => { + if (val && applicationFormTemplate.value) { + applicationFormTemplate.value.formElements = val } } }) @@ -78,8 +90,8 @@ const ampelStatusEmoji = computed(() => { }) async function onSubmit() { - if (data?.value?.content[0]) { - await createApplicationForm(data.value.content[0]) + if (applicationFormTemplate.value) { + await createApplicationForm(applicationFormTemplate.value) await navigateTo('/') } else { console.error('Application form data is undefined') diff --git a/legalconsenthub/pages/index.vue b/legalconsenthub/pages/index.vue index b71e99a..3637db9 100644 --- a/legalconsenthub/pages/index.vue +++ b/legalconsenthub/pages/index.vue @@ -27,8 +27,15 @@ :to="`application-forms/${applicationFormElem.id}`" >