Add delete/put /user

This commit is contained in:
2020-04-21 20:31:17 +02:00
parent 94b20b98ad
commit ea2ff1e77b
4 changed files with 78 additions and 35 deletions
+15 -2
View File
@@ -52,7 +52,7 @@ class UserService(override val kodein: Kodein) : KodeinAware {
* create a new user
* password should already be hashed
*/
fun createUser(user: UserRegistrationDto) {
fun createUser(user: UserDto) {
db.useTransaction {
val newUser = User {
this.username = user.username
@@ -65,6 +65,19 @@ class UserService(override val kodein: Kodein) : KodeinAware {
}
}
fun updateUser(userId: Int, user: UserDto) {
db.useTransaction {
db.update(Users) {
it.username to user.username
it.email to user.email
it.password to user.password
where {
it.id eq userId
}
}
}
}
fun deleteUser(userId: Int) {
db.useTransaction {
db.delete(Users) { it.id eq userId }
@@ -72,4 +85,4 @@ class UserService(override val kodein: Kodein) : KodeinAware {
}
}
data class UserRegistrationDto(val username: String, val email: String, val password: String)
data class UserDto(val username: String, val email: String, val password: String)