feat: Add ktlint to backend and format all files

This commit is contained in:
2025-10-31 10:25:12 +01:00
parent be5017fcd4
commit 841341857d
53 changed files with 496 additions and 402 deletions

View File

@@ -1,7 +1,10 @@
package com.betriebsratkanzlei.legalconsenthub.user
import com.betriebsratkanzlei.legalconsenthub_api.model.UserStatus
import jakarta.persistence.*
import jakarta.persistence.Column
import jakarta.persistence.Entity
import jakarta.persistence.EntityListeners
import jakarta.persistence.Id
import jakarta.persistence.Table
import org.springframework.data.annotation.CreatedDate
import org.springframework.data.annotation.LastModifiedDate
import org.springframework.data.jpa.domain.support.AuditingEntityListener
@@ -14,18 +17,14 @@ class User(
@Id
@Column(nullable = false)
var keycloakId: String,
@Column(nullable = false)
var name: String,
@Column(nullable = true)
var organizationId: String? = null,
@CreatedDate
@Column(nullable = false)
var createdAt: LocalDateTime? = null,
@LastModifiedDate
@Column(nullable = false)
var modifiedAt: LocalDateTime? = null
var modifiedAt: LocalDateTime? = null,
)

View File

@@ -8,7 +8,7 @@ import org.springframework.web.bind.annotation.RestController
@RestController
class UserController(
private val userService: UserService,
private val userMapper: UserMapper
private val userMapper: UserMapper,
) : UserApi {
override fun getUserById(id: String): ResponseEntity<UserDto> {
val user = userService.getUserById(id)

View File

@@ -5,20 +5,20 @@ import org.springframework.stereotype.Component
@Component
class UserMapper {
fun toUserDto(user: User): UserDto {
return UserDto(
fun toUserDto(user: User): UserDto =
UserDto(
keycloakId = user.keycloakId,
name = user.name,
organizationId = user.organizationId
organizationId = user.organizationId,
)
}
fun toUser(userDto: UserDto): User {
val user = User(
keycloakId = userDto.keycloakId,
name = userDto.name,
organizationId = userDto.organizationId
)
val user =
User(
keycloakId = userDto.keycloakId,
name = userDto.name,
organizationId = userDto.organizationId,
)
return user
}

View File

@@ -4,4 +4,4 @@ import org.springframework.data.jpa.repository.JpaRepository
import org.springframework.stereotype.Repository
@Repository
interface UserRepository : JpaRepository<User, String>
interface UserRepository : JpaRepository<User, String>

View File

@@ -11,14 +11,14 @@ import org.springframework.stereotype.Service
@Service
class UserService(
private val userRepository: UserRepository,
private val userMapper: UserMapper
private val userMapper: UserMapper,
) {
fun getCurrentUser(): User {
val principal = SecurityContextHolder.getContext().authentication.principal as CustomJwtTokenPrincipal
val userId = principal.id ?: throw IllegalStateException("User ID not found")
return userRepository.findById(userId)
return userRepository
.findById(userId)
.orElseThrow { UserNotFoundException(userId) }
}
@@ -42,24 +42,27 @@ class UserService(
throw UserAlreadyExistsException(userDto.keycloakId)
}
val user = User(
keycloakId = userDto.keycloakId,
name = userDto.name,
organizationId = userDto.organizationId
)
val user =
User(
keycloakId = userDto.keycloakId,
name = userDto.name,
organizationId = userDto.organizationId,
)
return userRepository.save(user)
}
fun getUserById(userId: String): User {
return userRepository.findById(userId)
fun getUserById(userId: String): User =
userRepository
.findById(userId)
.orElseThrow { UserNotFoundException(userId) }
}
@Transactional
fun updateUser(userDto: UserDto): User {
val user = userRepository.findById(userDto.keycloakId)
.orElseThrow { UserNotFoundException(userDto.keycloakId) }
val user =
userRepository
.findById(userDto.keycloakId)
.orElseThrow { UserNotFoundException(userDto.keycloakId) }
user.name = userDto.name
// Only update organization if it's not already set