feat: toggling Create/Join room button

This commit is contained in:
efim
2023-10-30 03:49:48 +00:00
parent bd99eaa54d
commit 201b3760da
4 changed files with 52 additions and 13 deletions

View File

@@ -40,7 +40,7 @@ func (r *Room) UnmarshalBinary(data []byte) error {
var ctx = context.Background()
type RoomManager interface {
Get(roomName string) (Room, error) // but we need Get by name
Get(roomName string) (Room, bool, error)
Save(room Room) error
}
const roomRedisPrefix = "room"
@@ -53,15 +53,18 @@ type RedisRM struct {
Rdb *redis.Client
}
func (redisRM RedisRM) Get(roomName string) (Room, error) {
func (redisRM RedisRM) Get(roomName string) (Room, bool, error) {
var readRoom Room
err := redisRM.Rdb.Get(ctx, roomNameToRedisId(roomName)).Scan(&readRoom)
if err == redis.Nil {
return Room{}, false, nil
}
if err != nil {
log.Printf("error reading room with id %s : %s", roomName, err)
return Room{}, err
return Room{}, false, err
}
return readRoom, nil
return readRoom, true, nil
}
func (redisRM RedisRM) Save(room Room) error {