feat(fullstack): Add organization scoping for application form
This commit is contained in:
@@ -20,6 +20,12 @@ paths:
|
||||
operationId: getAllApplicationForms
|
||||
tags:
|
||||
- application-form
|
||||
parameters:
|
||||
- in: query
|
||||
name: organizationId
|
||||
schema:
|
||||
type: string
|
||||
description: Filter application forms by organization ID
|
||||
responses:
|
||||
"200":
|
||||
description: Paged list of application forms
|
||||
@@ -580,6 +586,7 @@ components:
|
||||
- name
|
||||
- formElements
|
||||
- isTemplate
|
||||
- organizationId
|
||||
- createdBy
|
||||
- lastModifiedBy
|
||||
- createdAt
|
||||
@@ -596,6 +603,8 @@ components:
|
||||
$ref: "#/components/schemas/FormElementDto"
|
||||
isTemplate:
|
||||
type: boolean
|
||||
organizationId:
|
||||
type: string
|
||||
createdBy:
|
||||
$ref: "#/components/schemas/UserDto"
|
||||
lastModifiedBy:
|
||||
@@ -612,8 +621,6 @@ components:
|
||||
- name
|
||||
- formElements
|
||||
- isTemplate
|
||||
- createdBy
|
||||
- lastModifiedBy
|
||||
type: object
|
||||
properties:
|
||||
name:
|
||||
@@ -625,6 +632,8 @@ components:
|
||||
isTemplate:
|
||||
type: boolean
|
||||
default: false
|
||||
organizationId:
|
||||
type: string
|
||||
|
||||
PagedApplicationFormDto:
|
||||
type: object
|
||||
|
||||
@@ -34,6 +34,8 @@ class ApplicationForm(
|
||||
@Column(nullable = false)
|
||||
var isTemplate: Boolean,
|
||||
|
||||
var organizationId: String = "",
|
||||
|
||||
@Embedded
|
||||
@AttributeOverrides(
|
||||
AttributeOverride(name = "id", column = Column(name = "created_by_id", nullable = false)),
|
||||
|
||||
@@ -24,10 +24,10 @@ class ApplicationFormController(
|
||||
)
|
||||
}
|
||||
|
||||
override fun getAllApplicationForms(): ResponseEntity<PagedApplicationFormDto> {
|
||||
override fun getAllApplicationForms(organizationId: String?): ResponseEntity<PagedApplicationFormDto> {
|
||||
return ResponseEntity.ok(
|
||||
pagedApplicationFormMapper.toPagedApplicationFormDto(
|
||||
applicationFormService.getApplicationForms()
|
||||
applicationFormService.getApplicationForms(organizationId)
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ class ApplicationFormMapper(private val formElementMapper: FormElementMapper, pr
|
||||
name = applicationForm.name,
|
||||
formElements = applicationForm.formElements.map { formElementMapper.toFormElementDto(it) },
|
||||
isTemplate = applicationForm.isTemplate,
|
||||
organizationId = applicationForm.organizationId,
|
||||
createdBy = userMapper.toUserDto(applicationForm.createdBy),
|
||||
lastModifiedBy = userMapper.toUserDto(applicationForm.lastModifiedBy),
|
||||
createdAt = applicationForm.createdAt ?: LocalDateTime.now(),
|
||||
@@ -30,6 +31,7 @@ class ApplicationFormMapper(private val formElementMapper: FormElementMapper, pr
|
||||
name = applicationForm.name,
|
||||
formElements = applicationForm.formElements.map { formElementMapper.toFormElement(it) }.toMutableList(),
|
||||
isTemplate = applicationForm.isTemplate,
|
||||
organizationId = applicationForm.organizationId,
|
||||
createdBy = userMapper.toUser(applicationForm.createdBy),
|
||||
lastModifiedBy = userMapper.toUser(applicationForm.lastModifiedBy),
|
||||
createdAt = applicationForm.createdAt,
|
||||
@@ -38,6 +40,7 @@ class ApplicationFormMapper(private val formElementMapper: FormElementMapper, pr
|
||||
}
|
||||
|
||||
fun toApplicationForm(createApplicationFormDto: CreateApplicationFormDto): ApplicationForm {
|
||||
// TODO: Move this in upper layer
|
||||
val principal = SecurityContextHolder.getContext().authentication.principal as CustomJwtTokenPrincipal
|
||||
val createdBy = User(principal.name ?: "UNKNOWN USER", principal.id ?: "")
|
||||
val lastModifiedBy = User(principal.name ?: "UNKNOWN USER", principal.id ?: "")
|
||||
@@ -45,6 +48,7 @@ class ApplicationFormMapper(private val formElementMapper: FormElementMapper, pr
|
||||
val applicationForm = ApplicationForm(
|
||||
name = createApplicationFormDto.name,
|
||||
isTemplate = createApplicationFormDto.isTemplate,
|
||||
organizationId = createApplicationFormDto.organizationId ?: "",
|
||||
createdBy = createdBy,
|
||||
lastModifiedBy = lastModifiedBy,
|
||||
)
|
||||
|
||||
@@ -3,11 +3,14 @@ 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.data.jpa.repository.Query
|
||||
import org.springframework.stereotype.Repository
|
||||
import java.util.UUID
|
||||
|
||||
@Repository
|
||||
interface ApplicationFormRepository : JpaRepository<ApplicationForm, UUID> {
|
||||
fun findAllByIsTemplateTrue(page: Pageable): Page<ApplicationForm>
|
||||
fun findAllByIsTemplateFalse(page: Pageable): Page<ApplicationForm>
|
||||
|
||||
@Query("SELECT c FROM ApplicationForm c WHERE (c.isTemplate IS false) AND (:organizationId is null or c.organizationId = :organizationId)")
|
||||
fun findAllByIsTemplateFalseAndOrganizationId(organizationId: String?, page: Pageable): Page<ApplicationForm>
|
||||
}
|
||||
|
||||
@@ -33,12 +33,13 @@ class ApplicationFormService(
|
||||
return applicationFormRepository.findById(id).orElseThrow { ApplicationFormNotFoundException(id) }
|
||||
}
|
||||
|
||||
fun getApplicationForms(): Page<ApplicationForm> {
|
||||
fun getApplicationForms(organizationId: String?): Page<ApplicationForm> {
|
||||
val pageable = PageRequest.of(0, 10)
|
||||
return applicationFormRepository.findAllByIsTemplateFalse(pageable)
|
||||
return applicationFormRepository.findAllByIsTemplateFalseAndOrganizationId(organizationId, pageable)
|
||||
}
|
||||
|
||||
fun updateApplicationForm(applicationFormDto: ApplicationFormDto): ApplicationForm {
|
||||
// TODO find statt mappen?
|
||||
val applicationForm = applicationFormMapper.toApplicationForm(applicationFormDto)
|
||||
val updatedApplicationForm: ApplicationForm
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ create table application_form
|
||||
last_modified_by_id varchar(255) not null,
|
||||
last_modified_by_name varchar(255) not null,
|
||||
name varchar(255) not null,
|
||||
organization_id varchar(255),
|
||||
primary key (id)
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user