85 lines
1.8 KiB
Go
85 lines
1.8 KiB
Go
package dto
|
|
|
|
import (
|
|
"strconv"
|
|
"time"
|
|
|
|
"git.itzana.me/strafesnet/go-grpc/times"
|
|
)
|
|
|
|
type TimePlacement struct {
|
|
ID string `json:"id"`
|
|
Placement int64 `json:"placement"`
|
|
} // @name TimePlacement
|
|
|
|
func (r TimePlacement) FromGRPC(rank *times.RankResponse) *TimePlacement {
|
|
if rank == nil {
|
|
return nil
|
|
}
|
|
return &TimePlacement{
|
|
ID: strconv.FormatInt(rank.ID, 10),
|
|
Placement: rank.Rank,
|
|
}
|
|
}
|
|
|
|
type TimeFilter struct {
|
|
UserID *int64 `json:"user_id" form:"user_id"`
|
|
MapID *int64 `json:"map_id" form:"map_id"`
|
|
StyleID *int32 `json:"style_id" form:"style_id"`
|
|
ModeID *int32 `json:"mode_id" form:"mode_id"`
|
|
GameID *int32 `json:"game_id" form:"game_id"`
|
|
} // @TimeFilter
|
|
|
|
type TimeData struct {
|
|
ID string `json:"id"`
|
|
Time int64 `json:"time"`
|
|
User User `json:"user"`
|
|
Map Map `json:"map"`
|
|
HasBot bool `json:"has_bot"`
|
|
Date time.Time `json:"date"`
|
|
StyleID int32 `json:"style_id"`
|
|
ModeID int32 `json:"mode_id"`
|
|
GameID int32 `json:"game_id"`
|
|
} // @name Time
|
|
|
|
type BotDownloadUrl struct {
|
|
Url string `json:"url"`
|
|
} // @name BotDownloadUrl
|
|
|
|
type FileInfo struct {
|
|
ID string `json:"ID"`
|
|
Created int64 `json:"Created"`
|
|
Url string `json:"Url"`
|
|
} // @name FileInfo
|
|
|
|
// FromGRPC converts a TimeResponse protobuf message to a TimeData domain object
|
|
func (t *TimeData) FromGRPC(resp *times.TimeResponse) *TimeData {
|
|
if resp == nil {
|
|
return nil
|
|
}
|
|
|
|
t.ID = strconv.FormatInt(resp.ID, 10)
|
|
t.Time = resp.Time
|
|
t.Date = time.Unix(resp.Date, 0)
|
|
t.StyleID = resp.StyleID
|
|
t.ModeID = resp.ModeID
|
|
t.GameID = resp.GameID
|
|
|
|
// Handle User field
|
|
if resp.User != nil {
|
|
var user User
|
|
t.User = *user.FromGRPC(resp.User)
|
|
}
|
|
|
|
// Handle Map field
|
|
if resp.Map != nil {
|
|
var m Map
|
|
t.Map = *m.FromGRPC(resp.Map)
|
|
}
|
|
|
|
// Handle Bot field
|
|
t.HasBot = resp.Bot != nil
|
|
|
|
return t
|
|
}
|