Add Account

- add addAccount to AccountController
- add account request toAccountEntity to Mapping.kt
- add addAccount to AccountService
This commit is contained in:
2025-01-01 05:50:13 +01:00
parent 0681e367e7
commit dbadfcf731
4 changed files with 51 additions and 0 deletions

View File

@@ -1,8 +1,10 @@
package ltd.hlaeja.util
import java.time.ZonedDateTime
import ltd.hlaeja.entity.AccountEntity
import ltd.hlaeja.library.accountRegistry.Account
import org.springframework.http.HttpStatus.EXPECTATION_FAILED
import org.springframework.security.crypto.password.PasswordEncoder
import org.springframework.web.server.ResponseStatusException
fun AccountEntity.toAccountResponse(): Account.Response = Account.Response(
@@ -13,3 +15,14 @@ fun AccountEntity.toAccountResponse(): Account.Response = Account.Response(
roles.split(","),
)
fun Account.Request.toAccountEntity(
passwordEncoder: PasswordEncoder,
): AccountEntity = AccountEntity(
id = null,
createdAt = ZonedDateTime.now(),
updatedAt = ZonedDateTime.now(),
enabled = enabled,
username = username,
password = passwordEncoder.encode(password),
roles = roles.joinToString(","),
)