add POST /user endpoints.

- POST /user {"chzzkUrl": String} to add chzzk account to bots.
- and it post event UserRegisterEvent
This commit is contained in:
dalbodeule
2024-08-08 19:36:58 +09:00
parent d0840ad6a7
commit 80fa2d5029
4 changed files with 97 additions and 7 deletions

View File

@@ -0,0 +1,7 @@
package space.mori.chzzk_bot.common.events
data class UserRegisterEvent(
val chzzkId: String
): Event {
val TAG = javaClass.simpleName
}

View File

@@ -7,16 +7,31 @@ import space.mori.chzzk_bot.common.models.User
import space.mori.chzzk_bot.common.models.Users
object UserService {
fun saveUser(username: String, token: String, discordID: Long): User {
fun saveUser(username: String, naverId: String): User {
return transaction {
User.new {
this.username = username
this.token = token
this.discord = discordID
this.naverId = naverId
}
}
}
fun updateUser(user: User, chzzkId: String, username: String): User {
return transaction {
user.token = chzzkId
user.username = username
user
}
}
fun updateUser(user: User, discordID: Long): User {
return transaction {
user.discord = discordID
user
}
}
fun getUser(id: Int): User? {
return transaction {
User.findById(id)