Enha: state to hold room_id instead of whole room

This commit is contained in:
Grail Finder
2025-05-08 10:25:38 +03:00
parent 3ade7310a7
commit b20f7ac6b7
12 changed files with 110 additions and 35 deletions

View File

@ -8,7 +8,25 @@ import (
)
func createRoom(ctx context.Context, req *models.RoomReq) (*models.Room, error) {
return nil, nil
creator, ok := ctx.Value(models.CtxUsernameKey).(string)
if !ok {
err := errors.New("failed to extract user from ctx")
return nil, err
}
room := req.CreateRoom(creator)
if err := saveRoom(room); err != nil {
return nil, err
}
return room, nil
}
func saveRoom(room *models.Room) error {
data, err := json.Marshal(room)
if err != nil {
return err
}
memcache.Set(models.CacheRoomPrefix+room.ID, data)
return nil
}
func getRoomByID(roomID string) (*models.Room, error) {
@ -86,3 +104,19 @@ func getAllNames() []string {
}
return names
}
func getFullInfoByCtx(ctx context.Context) (*models.FullInfo, error) {
state, err := getStateByCtx(ctx)
if err != nil {
return nil, err
}
room, err := getRoomByID(state.RoomID)
if err != nil {
return nil, err
}
resp := &models.FullInfo{
State: state,
Room: room,
}
return resp, nil
}