From 69e293a25fcfefdb67cee83c96fba8aabe00b97a Mon Sep 17 00:00:00 2001 From: Swordsteel Date: Tue, 12 Aug 2025 13:51:48 +0200 Subject: [PATCH] update updateAccount in AccountController for PublicEventService --- .../hlaeja/controller/AccountController.kt | 21 +++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/src/main/kotlin/ltd/hlaeja/controller/AccountController.kt b/src/main/kotlin/ltd/hlaeja/controller/AccountController.kt index 985481b..42664af 100644 --- a/src/main/kotlin/ltd/hlaeja/controller/AccountController.kt +++ b/src/main/kotlin/ltd/hlaeja/controller/AccountController.kt @@ -1,13 +1,15 @@ package ltd.hlaeja.controller import java.util.UUID -import ltd.hlaeja.validator.ValidAccount import ltd.hlaeja.entity.AccountEntity import ltd.hlaeja.library.accountRegistry.Account import ltd.hlaeja.service.AccountService +import ltd.hlaeja.service.PublicEventService +import ltd.hlaeja.util.detectChanges import ltd.hlaeja.util.toAccountEntity import ltd.hlaeja.util.toAccountResponse import ltd.hlaeja.util.updateAccountEntity +import ltd.hlaeja.validator.ValidAccount import org.springframework.http.HttpStatus.ACCEPTED import org.springframework.http.HttpStatus.CREATED import org.springframework.security.crypto.password.PasswordEncoder @@ -25,6 +27,7 @@ import reactor.core.publisher.Mono class AccountController( private val accountService: AccountService, private val passwordEncoder: PasswordEncoder, + private val publicEventService: PublicEventService, ) { @GetMapping("/account-{uuid}") @@ -40,9 +43,13 @@ class AccountController( ): Mono = accountService.getUserById(uuid) .map { user -> 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) -> + accountService.updateAccount(updated) + .flatMap { publicEventService.updateAccount(it, changes) } } - .flatMap { accountService.updateAccount(it) } .map { it.toAccountResponse() } @PostMapping("/account") @@ -51,12 +58,4 @@ class AccountController( @RequestBody @ValidAccount request: Account.Request, ): Mono = accountService.addAccount(request.toAccountEntity(passwordEncoder)) .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 }