update updateAccount in AccountController for PublicEventService
This commit is contained in:
@@ -1,13 +1,15 @@
|
|||||||
package ltd.hlaeja.controller
|
package ltd.hlaeja.controller
|
||||||
|
|
||||||
import java.util.UUID
|
import java.util.UUID
|
||||||
import ltd.hlaeja.validator.ValidAccount
|
|
||||||
import ltd.hlaeja.entity.AccountEntity
|
import ltd.hlaeja.entity.AccountEntity
|
||||||
import ltd.hlaeja.library.accountRegistry.Account
|
import ltd.hlaeja.library.accountRegistry.Account
|
||||||
import ltd.hlaeja.service.AccountService
|
import ltd.hlaeja.service.AccountService
|
||||||
|
import ltd.hlaeja.service.PublicEventService
|
||||||
|
import ltd.hlaeja.util.detectChanges
|
||||||
import ltd.hlaeja.util.toAccountEntity
|
import ltd.hlaeja.util.toAccountEntity
|
||||||
import ltd.hlaeja.util.toAccountResponse
|
import ltd.hlaeja.util.toAccountResponse
|
||||||
import ltd.hlaeja.util.updateAccountEntity
|
import ltd.hlaeja.util.updateAccountEntity
|
||||||
|
import ltd.hlaeja.validator.ValidAccount
|
||||||
import org.springframework.http.HttpStatus.ACCEPTED
|
import org.springframework.http.HttpStatus.ACCEPTED
|
||||||
import org.springframework.http.HttpStatus.CREATED
|
import org.springframework.http.HttpStatus.CREATED
|
||||||
import org.springframework.security.crypto.password.PasswordEncoder
|
import org.springframework.security.crypto.password.PasswordEncoder
|
||||||
@@ -25,6 +27,7 @@ import reactor.core.publisher.Mono
|
|||||||
class AccountController(
|
class AccountController(
|
||||||
private val accountService: AccountService,
|
private val accountService: AccountService,
|
||||||
private val passwordEncoder: PasswordEncoder,
|
private val passwordEncoder: PasswordEncoder,
|
||||||
|
private val publicEventService: PublicEventService,
|
||||||
) {
|
) {
|
||||||
|
|
||||||
@GetMapping("/account-{uuid}")
|
@GetMapping("/account-{uuid}")
|
||||||
@@ -40,9 +43,13 @@ class AccountController(
|
|||||||
): Mono<Account.Response> = accountService.getUserById(uuid)
|
): Mono<Account.Response> = accountService.getUserById(uuid)
|
||||||
.map { user ->
|
.map { user ->
|
||||||
user.updateAccountEntity(request, passwordEncoder)
|
user.updateAccountEntity(request, passwordEncoder)
|
||||||
.also { if (hasChange(user, it)) throw ResponseStatusException(ACCEPTED) }
|
.let { it to it.detectChanges(user) }
|
||||||
|
.also { if (it.second.isEmpty()) throw ResponseStatusException(ACCEPTED) }
|
||||||
|
}
|
||||||
|
.flatMap { (updated: AccountEntity, changes: List<String>) ->
|
||||||
|
accountService.updateAccount(updated)
|
||||||
|
.flatMap { publicEventService.updateAccount(it, changes) }
|
||||||
}
|
}
|
||||||
.flatMap { accountService.updateAccount(it) }
|
|
||||||
.map { it.toAccountResponse() }
|
.map { it.toAccountResponse() }
|
||||||
|
|
||||||
@PostMapping("/account")
|
@PostMapping("/account")
|
||||||
@@ -51,12 +58,4 @@ class AccountController(
|
|||||||
@RequestBody @ValidAccount request: Account.Request,
|
@RequestBody @ValidAccount request: Account.Request,
|
||||||
): Mono<Account.Response> = accountService.addAccount(request.toAccountEntity(passwordEncoder))
|
): Mono<Account.Response> = accountService.addAccount(request.toAccountEntity(passwordEncoder))
|
||||||
.map { it.toAccountResponse() }
|
.map { it.toAccountResponse() }
|
||||||
|
|
||||||
private fun hasChange(
|
|
||||||
user: AccountEntity,
|
|
||||||
update: AccountEntity,
|
|
||||||
): Boolean = user.password == update.password &&
|
|
||||||
user.username == update.username &&
|
|
||||||
user.enabled == update.enabled &&
|
|
||||||
user.roles == update.roles
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user