feat: game order api methods
This commit is contained in:
+17
-11
@@ -29,7 +29,9 @@ const (
|
||||
)
|
||||
|
||||
type storedOrder struct {
|
||||
Commands []json.RawMessage `json:"cmd"`
|
||||
GameID uuid.UUID `json:"game_id"`
|
||||
UpdatedAt int64 `json:"updatedAt"`
|
||||
Commands []json.RawMessage `json:"cmd"`
|
||||
}
|
||||
|
||||
func (o storedOrder) MarshalBinary() (data []byte, err error) {
|
||||
@@ -201,11 +203,11 @@ func loadReport(s Storage, t uint, id uuid.UUID) (*report.Report, error) {
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (r *repo) SaveOrder(t uint, id uuid.UUID, o *order.Order) error {
|
||||
func (r *repo) SaveOrder(t uint, id uuid.UUID, o *order.UserGamesOrder) error {
|
||||
return saveOrder(r.s, t, id, o)
|
||||
}
|
||||
|
||||
func saveOrder(s Storage, t uint, id uuid.UUID, o *order.Order) error {
|
||||
func saveOrder(s Storage, t uint, id uuid.UUID, o *order.UserGamesOrder) error {
|
||||
path := OrderDir(t, id)
|
||||
if err := s.WriteSafe(path, o); err != nil {
|
||||
return NewStorageError(err)
|
||||
@@ -213,11 +215,11 @@ func saveOrder(s Storage, t uint, id uuid.UUID, o *order.Order) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *repo) LoadOrder(t uint, id uuid.UUID) (*order.Order, bool, error) {
|
||||
func (r *repo) LoadOrder(t uint, id uuid.UUID) (*order.UserGamesOrder, bool, error) {
|
||||
return loadOrder(r.s, t, id)
|
||||
}
|
||||
|
||||
func loadOrder(s Storage, t uint, id uuid.UUID) (*order.Order, bool, error) {
|
||||
func loadOrder(s Storage, t uint, id uuid.UUID) (*order.UserGamesOrder, bool, error) {
|
||||
path := OrderDir(t, id)
|
||||
|
||||
exist, err := s.Exists(path)
|
||||
@@ -228,17 +230,21 @@ func loadOrder(s Storage, t uint, id uuid.UUID) (*order.Order, bool, error) {
|
||||
return nil, false, nil
|
||||
}
|
||||
|
||||
cmd := new(storedOrder)
|
||||
if err := s.ReadSafe(path, cmd); err != nil {
|
||||
stored := new(storedOrder)
|
||||
if err := s.ReadSafe(path, stored); err != nil {
|
||||
return nil, false, NewStorageError(err)
|
||||
}
|
||||
result := &order.Order{Commands: make([]order.DecodableCommand, len(cmd.Commands))}
|
||||
if len(cmd.Commands) == 0 {
|
||||
result := &order.UserGamesOrder{
|
||||
GameID: stored.GameID,
|
||||
UpdatedAt: stored.UpdatedAt,
|
||||
Commands: make([]order.DecodableCommand, len(stored.Commands)),
|
||||
}
|
||||
if len(stored.Commands) == 0 {
|
||||
return nil, false, errors.New("no commands were stored")
|
||||
}
|
||||
|
||||
for i := range cmd.Commands {
|
||||
command, err := ParseOrder(cmd.Commands[i], nil)
|
||||
for i := range stored.Commands {
|
||||
command, err := ParseOrder(stored.Commands[i], nil)
|
||||
if err != nil {
|
||||
return nil, false, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user