Enha: state to hold room_id instead of whole room
This commit is contained in:
@ -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
|
||||
}
|
||||
|
Reference in New Issue
Block a user