session handling for players and hosts
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
import gleam/dynamic/decode
|
||||
import gleam/json
|
||||
|
||||
pub type PlayerSession {
|
||||
PlayerSession(id: Int, token_hash: String, username: String)
|
||||
}
|
||||
|
||||
pub fn encode_player_session(player_session: PlayerSession) -> json.Json {
|
||||
json.object([
|
||||
#("id", json.int(player_session.id)),
|
||||
#("token_hash", json.string(player_session.token_hash)),
|
||||
#("username", json.string(player_session.username)),
|
||||
])
|
||||
}
|
||||
|
||||
pub fn player_session_decoder() -> decode.Decoder(PlayerSession) {
|
||||
use id <- decode.field("id", decode.int)
|
||||
use token_hash <- decode.field("token_hash", decode.string)
|
||||
use username <- decode.field("username", decode.string)
|
||||
decode.success(PlayerSession(id:, token_hash:, username:))
|
||||
}
|
||||
Reference in New Issue
Block a user