Skip to content
This repository has been archived by the owner on Feb 10, 2025. It is now read-only.

Commit

Permalink
feat: add profile update process
Browse files Browse the repository at this point in the history
  • Loading branch information
testusuke committed Mar 27, 2024
1 parent a76cdc3 commit 6c8a9e0
Showing 1 changed file with 30 additions and 20 deletions.
50 changes: 30 additions & 20 deletions src/main/kotlin/net/sportsday/services/AuthenticationService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import kotlinx.serialization.decodeFromString
import kotlinx.serialization.json.Json
import net.sportsday.models.User
import net.sportsday.models.UserEntity
import net.sportsday.models.Users
import net.sportsday.models.*
import org.jetbrains.exposed.sql.transactions.transaction
import java.net.URL
import java.security.interfaces.RSAPublicKey
Expand Down Expand Up @@ -160,37 +158,49 @@ object AuthenticationService {

// create user if not found
if (user == null) {
val pictureEntity = if (picture != null) {
// create picture entity
val createdPictureEntity = ImageEntity.new {
this.data = picture
this.createdAt = LocalDateTime.now()
}
createdPictureEntity
} else {
null
}

// create user
val createdUserEntity = UserEntity.new {
this.name = userinfo.name
this.email = userinfo.email
this.picture = null
this.picture = pictureEntity
this.createdAt = LocalDateTime.now()
this.updatedAt = LocalDateTime.now()
}
createdUserEntity.serializableModel()
} else {
// if there is changes in userinfo, update it
var updated = false
if (user.name != userinfo.name) {
user.name = userinfo.name
updated = true
// update username
user.name = userinfo.name

// if there is changes in picture, update it
if (picture != null) {
if (user.picture == null) {
val createdPictureEntity = ImageEntity.new {
this.data = picture
this.createdAt = LocalDateTime.now()
}
user.picture = createdPictureEntity
} else {
user.picture!!.data = picture
}
}

// update timestamp
if (updated) {
user.updatedAt = LocalDateTime.now()
}
user.updatedAt = LocalDateTime.now()

user.serializableModel()
}
}

ProfileUpdateScope.launch {
// todo: asynchronously update picture
transaction {

}
}

return userModel
}

Expand Down

0 comments on commit 6c8a9e0

Please sign in to comment.