diff --git a/legalconsenthub-backend/api/legalconsenthub.yml b/legalconsenthub-backend/api/legalconsenthub.yml
index b40493e..273875c 100644
--- a/legalconsenthub-backend/api/legalconsenthub.yml
+++ b/legalconsenthub-backend/api/legalconsenthub.yml
@@ -240,48 +240,6 @@ paths:
"503":
$ref: "https://api.swaggerhub.com/domains/smartbear-public/ProblemDetails/1.0.0#/components/responses/ServiceUnavailable"
- /users:
- get:
- summary: Get all users
- operationId: getAllUsers
- tags:
- - user
- responses:
- "200":
- description: Paged list of users
- content:
- application/json:
- schema:
- $ref: "#/components/schemas/PagedUserDto"
- "500":
- description: Internal server error
- post:
- summary: Create a new user
- operationId: createUser
- tags:
- - user
- requestBody:
- required: true
- content:
- application/json:
- schema:
- $ref: "#/components/schemas/CreateUserDTO"
- responses:
- "201":
- description: Successfully created user
- content:
- application/json:
- schema:
- $ref: "#/components/schemas/UserDto"
- "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/{id}:
parameters:
- name: id
@@ -607,77 +565,12 @@ components:
type: object
required:
- id
- - username
- - firstname
- - lastname
- - email
- - password
- - roleId
- - createdAt
- - modifiedAt
+ - name
properties:
id:
type: string
- format: uuid
- username:
+ name:
type: string
- firstName:
- type: string
- lastName:
- type: string
- email:
- type: string
- format: email
- password:
- type: string
- roleId:
- type: string
- format: uuid
- createdAt:
- type: string
- format: date-time
- modifiedAt:
- type: string
- format: date-time
-
- CreateUserDTO:
- type: object
- required:
- - username
- - firstname
- - lastname
- - email
- - password
- - roleId
- - createdAt
- - modifiedAt
- properties:
- username:
- type: string
- firstName:
- type: string
- lastName:
- type: string
- email:
- type: string
- format: email
- password:
- type: string
- roleId:
- type: string
- format: uuid
-
- PagedUserDto:
- type: object
- allOf:
- - $ref: "#/components/schemas/Page"
- required:
- - content
- properties:
- content:
- type: array
- items:
- $ref: "#/components/schemas/UserDto"
####### ApplicationFormDto #######
ApplicationFormDto:
@@ -704,9 +597,9 @@ components:
isTemplate:
type: boolean
createdBy:
- type: string
+ $ref: "#/components/schemas/UserDto"
lastModifiedBy:
- type: string
+ $ref: "#/components/schemas/UserDto"
createdAt:
type: string
format: date-time
@@ -732,10 +625,6 @@ components:
isTemplate:
type: boolean
default: false
- createdBy:
- type: string
- lastModifiedBy:
- type: string
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 9fb9c37..b605875 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,9 @@
package com.betriebsratkanzlei.legalconsenthub.application_form
import com.betriebsratkanzlei.legalconsenthub.form_element.FormElement
+import com.betriebsratkanzlei.legalconsenthub.user.User
+import jakarta.persistence.AttributeOverride
+import jakarta.persistence.AttributeOverrides
import jakarta.persistence.CascadeType
import jakarta.persistence.Column
import jakarta.persistence.Entity
@@ -8,6 +11,7 @@ import jakarta.persistence.EntityListeners
import jakarta.persistence.GeneratedValue
import jakarta.persistence.Id
import jakarta.persistence.OneToMany
+import jakarta.persistence.Embedded
import org.springframework.data.annotation.CreatedDate
import org.springframework.data.annotation.LastModifiedDate
import org.springframework.data.jpa.domain.support.AuditingEntityListener
@@ -30,11 +34,19 @@ class ApplicationForm(
@Column(nullable = false)
var isTemplate: Boolean,
- @Column(nullable = false)
- var createdBy: String = "",
+ @Embedded
+ @AttributeOverrides(
+ AttributeOverride(name = "id", column = Column(name = "created_by_id", nullable = false)),
+ AttributeOverride(name = "name", column = Column(name = "created_by_name", nullable = false))
+ )
+ var createdBy: User,
- @Column(nullable = false)
- var lastModifiedBy: String = "",
+ @Embedded
+ @AttributeOverrides(
+ AttributeOverride(name = "id", column = Column(name = "last_modified_by_id", nullable = false)),
+ AttributeOverride(name = "name", column = Column(name = "last_modified_by_name", nullable = false))
+ )
+ var lastModifiedBy: User,
@CreatedDate
@Column(nullable = false)
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 21857c8..d962e52 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
@@ -1,20 +1,24 @@
package com.betriebsratkanzlei.legalconsenthub.application_form
+import com.betriebsratkanzlei.legalconsenthub.security.CustomJwtTokenPrincipal
+import com.betriebsratkanzlei.legalconsenthub.user.User
+import com.betriebsratkanzlei.legalconsenthub.user.UserMapper
import com.betriebsratkanzlei.legalconsenthub_api.model.ApplicationFormDto
import com.betriebsratkanzlei.legalconsenthub_api.model.CreateApplicationFormDto
+import org.springframework.security.core.context.SecurityContextHolder
import org.springframework.stereotype.Component
import java.time.LocalDateTime
@Component
-class ApplicationFormMapper(private val formElementMapper: FormElementMapper) {
+class ApplicationFormMapper(private val formElementMapper: FormElementMapper, private val userMapper: UserMapper) {
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,
- createdBy = applicationForm.createdBy,
- lastModifiedBy = applicationForm.lastModifiedBy,
+ createdBy = userMapper.toUserDto(applicationForm.createdBy),
+ lastModifiedBy = userMapper.toUserDto(applicationForm.lastModifiedBy),
createdAt = applicationForm.createdAt ?: LocalDateTime.now(),
modifiedAt = applicationForm.modifiedAt ?: LocalDateTime.now()
)
@@ -26,19 +30,23 @@ class ApplicationFormMapper(private val formElementMapper: FormElementMapper) {
name = applicationForm.name,
formElements = applicationForm.formElements.map { formElementMapper.toFormElement(it) }.toMutableList(),
isTemplate = applicationForm.isTemplate,
- createdBy = applicationForm.createdBy,
- lastModifiedBy = applicationForm.lastModifiedBy,
+ createdBy = userMapper.toUser(applicationForm.createdBy),
+ lastModifiedBy = userMapper.toUser(applicationForm.lastModifiedBy),
createdAt = applicationForm.createdAt,
modifiedAt = applicationForm.modifiedAt
)
}
fun toApplicationForm(createApplicationFormDto: CreateApplicationFormDto): ApplicationForm {
+ 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 ?: "")
+
val applicationForm = ApplicationForm(
name = createApplicationFormDto.name,
isTemplate = createApplicationFormDto.isTemplate,
- createdBy = createApplicationFormDto.createdBy,
- lastModifiedBy = createApplicationFormDto.lastModifiedBy
+ createdBy = createdBy,
+ lastModifiedBy = lastModifiedBy,
)
applicationForm.formElements = createApplicationFormDto.formElements
.map { formElementMapper.toFormElement(it, applicationForm) }
diff --git a/legalconsenthub-backend/src/main/kotlin/com/betriebsratkanzlei/legalconsenthub/config/CustomJwtAuthenticationConverter.kt b/legalconsenthub-backend/src/main/kotlin/com/betriebsratkanzlei/legalconsenthub/config/CustomJwtAuthenticationConverter.kt
new file mode 100644
index 0000000..90d437a
--- /dev/null
+++ b/legalconsenthub-backend/src/main/kotlin/com/betriebsratkanzlei/legalconsenthub/config/CustomJwtAuthenticationConverter.kt
@@ -0,0 +1,22 @@
+package com.betriebsratkanzlei.legalconsenthub.config
+
+import com.betriebsratkanzlei.legalconsenthub.security.CustomJwtAuthentication
+import com.betriebsratkanzlei.legalconsenthub.security.CustomJwtTokenPrincipal
+import org.springframework.core.convert.converter.Converter
+import org.springframework.security.authentication.AbstractAuthenticationToken
+import org.springframework.security.core.GrantedAuthority
+import org.springframework.security.oauth2.jwt.Jwt
+import org.springframework.stereotype.Component
+
+@Component
+class CustomJwtAuthenticationConverter : Converter
- Zuletzt bearbeitet von {{ applicationFormElem.lastModifiedBy }} am + Zuletzt bearbeitet von {{ applicationFormElem.lastModifiedBy.name }} am {{ formatDate(applicationFormElem.modifiedAt) }}
- Erstellt von {{ applicationFormElem.createdBy }} am {{ formatDate(applicationFormElem.createdAt) }} + Erstellt von {{ applicationFormElem.createdBy.name }} am {{ formatDate(applicationFormElem.createdAt) }}