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
|
||||
fullcombo bool
|
||||
mods int
|
||||
date common.OsuTime
|
||||
date common.UnixTimestamp
|
||||
accuracy float64
|
||||
)
|
||||
err := rows.Scan(
|
||||
|
|
|
@ -3,7 +3,6 @@ package peppy
|
|||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"git.zxq.co/ripple/rippleapi/common"
|
||||
"git.zxq.co/x/getrank"
|
||||
|
@ -55,7 +54,7 @@ func getUserX(c *gin.Context, db *sqlx.DB, orderBy string, limit int) {
|
|||
for rows.Next() {
|
||||
var (
|
||||
curscore osuapi.GUSScore
|
||||
rawTime string
|
||||
rawTime common.UnixTimestamp
|
||||
acc float64
|
||||
fc bool
|
||||
mods int
|
||||
|
@ -80,16 +79,7 @@ func getUserX(c *gin.Context, db *sqlx.DB, orderBy string, limit int) {
|
|||
}
|
||||
curscore.FullCombo = osuapi.OsuBool(fc)
|
||||
curscore.Mods = osuapi.Mods(mods)
|
||||
t, err := time.Parse(common.OsuTimeFormat, 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.Date = osuapi.MySQLDate(rawTime)
|
||||
curscore.Rank = strings.ToUpper(getrank.GetRank(
|
||||
osuapi.Mode(m),
|
||||
curscore.Mods,
|
||||
|
|
|
@ -9,23 +9,23 @@ import (
|
|||
)
|
||||
|
||||
type score struct {
|
||||
ID int `json:"id"`
|
||||
BeatmapMD5 string `json:"beatmap_md5"`
|
||||
Score int64 `json:"score"`
|
||||
MaxCombo int `json:"max_combo"`
|
||||
FullCombo bool `json:"full_combo"`
|
||||
Mods int `json:"mods"`
|
||||
Count300 int `json:"count_300"`
|
||||
Count100 int `json:"count_100"`
|
||||
Count50 int `json:"count_50"`
|
||||
CountGeki int `json:"count_geki"`
|
||||
CountKatu int `json:"count_katu"`
|
||||
CountMiss int `json:"count_miss"`
|
||||
Time common.OsuTime `json:"time"`
|
||||
PlayMode int `json:"play_mode"`
|
||||
Accuracy float64 `json:"accuracy"`
|
||||
PP float32 `json:"pp"`
|
||||
Completed int `json:"completed"`
|
||||
ID int `json:"id"`
|
||||
BeatmapMD5 string `json:"beatmap_md5"`
|
||||
Score int64 `json:"score"`
|
||||
MaxCombo int `json:"max_combo"`
|
||||
FullCombo bool `json:"full_combo"`
|
||||
Mods int `json:"mods"`
|
||||
Count300 int `json:"count_300"`
|
||||
Count100 int `json:"count_100"`
|
||||
Count50 int `json:"count_50"`
|
||||
CountGeki int `json:"count_geki"`
|
||||
CountKatu int `json:"count_katu"`
|
||||
CountMiss int `json:"count_miss"`
|
||||
Time common.UnixTimestamp `json:"time"`
|
||||
PlayMode int `json:"play_mode"`
|
||||
Accuracy float64 `json:"accuracy"`
|
||||
PP float32 `json:"pp"`
|
||||
Completed int `json:"completed"`
|
||||
}
|
||||
|
||||
// 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