Add Account
- add addAccount to AccountController - add account request toAccountEntity to Mapping.kt - add addAccount to AccountService
This commit is contained in:
@@ -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(","),
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user