-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from groupeminaste/fix/validators
Using validators to check user payloads
- Loading branch information
Showing
12 changed files
with
72 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
...-backend/src/commonMain/kotlin/me/nathanfallet/extopy/usecases/users/UpdateUserUseCase.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package me.nathanfallet.extopy.usecases.users | ||
|
||
import io.ktor.http.* | ||
import me.nathanfallet.extopy.models.users.UpdateUserPayload | ||
import me.nathanfallet.extopy.models.users.User | ||
import me.nathanfallet.extopy.repositories.users.IUsersRepository | ||
import me.nathanfallet.extopy.usecases.auth.IHashPasswordUseCase | ||
import me.nathanfallet.ktorx.models.exceptions.ControllerException | ||
import me.nathanfallet.usecases.models.update.IUpdateModelSuspendUseCase | ||
|
||
class UpdateUserUseCase( | ||
private val repository: IUsersRepository, | ||
private val hashPasswordUseCase: IHashPasswordUseCase, | ||
) : IUpdateModelSuspendUseCase<User, String, UpdateUserPayload> { | ||
|
||
override suspend fun invoke(input1: String, input2: UpdateUserPayload): User? { | ||
input2.username?.let { | ||
repository.getForUsernameOrEmail(it, false)?.let { | ||
throw ControllerException( | ||
HttpStatusCode.BadRequest, | ||
"auth_register_username_taken" | ||
) | ||
} | ||
} | ||
val updatedUser = input2.password?.let { | ||
input2.copy(password = hashPasswordUseCase(it)) | ||
} ?: input2 | ||
return if (repository.update(input1, updatedUser)) repository.get(input1) | ||
else null | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 3 additions & 3 deletions
6
extopy-backend/src/commonMain/resources/i18n/Messages_fr.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
...py-commons/src/commonMain/kotlin/me/nathanfallet/extopy/models/users/UpdateUserPayload.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters