Remove common.OsuTime, change all occurencies to common.UnixTimestamp
This commit is contained in:
parent
67ae6ab3b8
commit
817592e736
|
@ -69,7 +69,7 @@ ORDER BY `+sb+` DESC LIMIT `+strconv.Itoa(common.InString(1, c.Query("limit"), 1
|
||||||
s osuapi.GSScore
|
s osuapi.GSScore
|
||||||
fullcombo bool
|
fullcombo bool
|
||||||
mods int
|
mods int
|
||||||
date common.OsuTime
|
date common.UnixTimestamp
|
||||||
accuracy float64
|
accuracy float64
|
||||||
)
|
)
|
||||||
err := rows.Scan(
|
err := rows.Scan(
|
||||||
|
|
|
@ -3,7 +3,6 @@ package peppy
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
|
||||||
|
|
||||||
"git.zxq.co/ripple/rippleapi/common"
|
"git.zxq.co/ripple/rippleapi/common"
|
||||||
"git.zxq.co/x/getrank"
|
"git.zxq.co/x/getrank"
|
||||||
|
@ -55,7 +54,7 @@ func getUserX(c *gin.Context, db *sqlx.DB, orderBy string, limit int) {
|
||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
var (
|
var (
|
||||||
curscore osuapi.GUSScore
|
curscore osuapi.GUSScore
|
||||||
rawTime string
|
rawTime common.UnixTimestamp
|
||||||
acc float64
|
acc float64
|
||||||
fc bool
|
fc bool
|
||||||
mods int
|
mods int
|
||||||
|
@ -80,16 +79,7 @@ func getUserX(c *gin.Context, db *sqlx.DB, orderBy string, limit int) {
|
||||||
}
|
}
|
||||||
curscore.FullCombo = osuapi.OsuBool(fc)
|
curscore.FullCombo = osuapi.OsuBool(fc)
|
||||||
curscore.Mods = osuapi.Mods(mods)
|
curscore.Mods = osuapi.Mods(mods)
|
||||||
t, err := time.Parse(common.OsuTimeFormat, rawTime)
|
curscore.Date = osuapi.MySQLDate(rawTime)
|
||||||
// silently ignore ParseErrors. should probably put something in the
|
|
||||||
// cron to restrict all users who have an "unusual" time format in
|
|
||||||
// their scores.
|
|
||||||
if _, ok := err.(*time.ParseError); !ok && err != nil {
|
|
||||||
c.JSON(200, defaultResponse)
|
|
||||||
c.Error(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
curscore.Date = osuapi.MySQLDate(t)
|
|
||||||
curscore.Rank = strings.ToUpper(getrank.GetRank(
|
curscore.Rank = strings.ToUpper(getrank.GetRank(
|
||||||
osuapi.Mode(m),
|
osuapi.Mode(m),
|
||||||
curscore.Mods,
|
curscore.Mods,
|
||||||
|
|
|
@ -9,23 +9,23 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type score struct {
|
type score struct {
|
||||||
ID int `json:"id"`
|
ID int `json:"id"`
|
||||||
BeatmapMD5 string `json:"beatmap_md5"`
|
BeatmapMD5 string `json:"beatmap_md5"`
|
||||||
Score int64 `json:"score"`
|
Score int64 `json:"score"`
|
||||||
MaxCombo int `json:"max_combo"`
|
MaxCombo int `json:"max_combo"`
|
||||||
FullCombo bool `json:"full_combo"`
|
FullCombo bool `json:"full_combo"`
|
||||||
Mods int `json:"mods"`
|
Mods int `json:"mods"`
|
||||||
Count300 int `json:"count_300"`
|
Count300 int `json:"count_300"`
|
||||||
Count100 int `json:"count_100"`
|
Count100 int `json:"count_100"`
|
||||||
Count50 int `json:"count_50"`
|
Count50 int `json:"count_50"`
|
||||||
CountGeki int `json:"count_geki"`
|
CountGeki int `json:"count_geki"`
|
||||||
CountKatu int `json:"count_katu"`
|
CountKatu int `json:"count_katu"`
|
||||||
CountMiss int `json:"count_miss"`
|
CountMiss int `json:"count_miss"`
|
||||||
Time common.OsuTime `json:"time"`
|
Time common.UnixTimestamp `json:"time"`
|
||||||
PlayMode int `json:"play_mode"`
|
PlayMode int `json:"play_mode"`
|
||||||
Accuracy float64 `json:"accuracy"`
|
Accuracy float64 `json:"accuracy"`
|
||||||
PP float32 `json:"pp"`
|
PP float32 `json:"pp"`
|
||||||
Completed int `json:"completed"`
|
Completed int `json:"completed"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// beatmapScore is to differentiate from userScore, as beatmapScore contains
|
// beatmapScore is to differentiate from userScore, as beatmapScore contains
|
||||||
|
|
|
@ -1,60 +0,0 @@
|
||||||
package common
|
|
||||||
|
|
||||||
import (
|
|
||||||
"errors"
|
|
||||||
"strconv"
|
|
||||||
"time"
|
|
||||||
)
|
|
||||||
|
|
||||||
// OsuTimeFormat is the time format for scores in the DB. Can be used with time.Parse etc.
|
|
||||||
const OsuTimeFormat = "060102150405"
|
|
||||||
|
|
||||||
// OsuTime is simply a time.Time, but can be used to convert an
|
|
||||||
// osu timestamp in the database into a native time.Time.
|
|
||||||
type OsuTime time.Time
|
|
||||||
|
|
||||||
func (s *OsuTime) setTime(t string) error {
|
|
||||||
newTime, err := time.Parse(OsuTimeFormat, t)
|
|
||||||
if _, ok := err.(*time.ParseError); err != nil && !ok {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if err == nil {
|
|
||||||
*s = OsuTime(newTime)
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Scan decodes src into an OsuTime.
|
|
||||||
func (s *OsuTime) Scan(src interface{}) error {
|
|
||||||
if s == nil {
|
|
||||||
return errors.New("rippleapi/common: OsuTime is nil")
|
|
||||||
}
|
|
||||||
switch src := src.(type) {
|
|
||||||
case int64:
|
|
||||||
return s.setTime(strconv.FormatInt(src, 64))
|
|
||||||
case float64:
|
|
||||||
return s.setTime(strconv.FormatInt(int64(src), 64))
|
|
||||||
case string:
|
|
||||||
return s.setTime(src)
|
|
||||||
case []byte:
|
|
||||||
return s.setTime(string(src))
|
|
||||||
case nil:
|
|
||||||
// Nothing, leave zero value on timestamp
|
|
||||||
default:
|
|
||||||
return errors.New("rippleapi/common: unhandleable type")
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// MarshalJSON -> time.Time.MarshalJSON
|
|
||||||
func (s OsuTime) MarshalJSON() ([]byte, error) {
|
|
||||||
return time.Time(s).MarshalJSON()
|
|
||||||
}
|
|
||||||
|
|
||||||
// UnmarshalJSON -> time.Time.UnmarshalJSON
|
|
||||||
func (s *OsuTime) UnmarshalJSON(x []byte) error {
|
|
||||||
t := new(time.Time)
|
|
||||||
err := t.UnmarshalJSON(x)
|
|
||||||
*s = OsuTime(*t)
|
|
||||||
return err
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user