diff --git a/api/ServerStatistics.api b/api/ServerStatistics.api index 2c057a8..d7eee7d 100644 --- a/api/ServerStatistics.api +++ b/api/ServerStatistics.api @@ -95,6 +95,7 @@ type ( RecentJoinPlayerReq { TimeRangeStart int64 `json:"timeRangeStart"` // Unix timestamp in milliseconds TimeRangeEnd int64 `json:"timeRangeEnd"` // Unix timestamp in milliseconds + Limit int `json:"limit,range=[1:10],example=10,default=10"` // Maximum number of players to return } RecentJoinPlayerResp { Players []RecentJoinPlayerRespPlayer `json:"players"` // List of player SteamID64s who joined in the time range @@ -111,6 +112,7 @@ type ( RecentChatMessageReq { TimeRangeStart int64 `json:"timeRangeStart"` // Unix timestamp in milliseconds TimeRangeEnd int64 `json:"timeRangeEnd"` // Unix timestamp in milliseconds + Limit int `json:"limit,range=[1:10],example=10,default=10"` // Maximum number of messages to return } RecentChatMessageResp { Messages []RecentChatMessageRespMessage `json:"messages"` // List of recent chat messages @@ -132,6 +134,7 @@ type ( TimeRangeStart int64 `json:"timeRangeStart"` // Unix timestamp in milliseconds TimeRangeEnd int64 `json:"timeRangeEnd"` // Unix timestamp in milliseconds LeastPlayTime int64 `json:"leastPlayTime"` // Least playtime in seconds to filter by + Limit int `json:"limit,range=[1:10],example=10,default=10"` // Maximum number of players to return } RecentPlayResp { Players []RecentPlayRespPlayer `json:"players"` // List of players who played in the time range @@ -148,6 +151,7 @@ type ( TopPlayTimeReq { TimeRangeStart int64 `json:"timeRangeStart"` // Unix timestamp in milliseconds TimeRangeEnd int64 `json:"timeRangeEnd"` // Unix timestamp in milliseconds + Limit int `json:"limit,range=[1:10],example=10,default=10"` // Maximum number of players to return } TopPlayTimeResp { Players []TopPlayTimeRespPlayer `json:"players"` // List of top players by playtime @@ -163,6 +167,7 @@ type ( TopKillerReq { TimeRangeStart int64 `json:"timeRangeStart"` // Unix timestamp in milliseconds TimeRangeEnd int64 `json:"timeRangeEnd"` // Unix timestamp in milliseconds + Limit int `json:"limit,range=[1:10],example=10,default=10"` // Maximum number of players to return } TopKillerResp { Players []TopKillerRespPlayer `json:"players"` // List of top players by kill count diff --git a/src/internal/logic/recentchatmessagelogic.go b/src/internal/logic/recentchatmessagelogic.go index 3a82688..0bd2aa2 100644 --- a/src/internal/logic/recentchatmessagelogic.go +++ b/src/internal/logic/recentchatmessagelogic.go @@ -33,9 +33,10 @@ func (l *RecentChatMessageLogic) RecentChatMessage(req *types.RecentChatMessageR WHERE message_time >= TO_TIMESTAMP($1 / 1000.0) AND message_time <= TO_TIMESTAMP($2 / 1000.0) ORDER BY message_time DESC + LIMIT $3 ` - rows, err := l.svcCtx.DB.QueryContext(l.ctx, query, req.TimeRangeStart, req.TimeRangeEnd) + rows, err := l.svcCtx.DB.QueryContext(l.ctx, query, req.TimeRangeStart, req.TimeRangeEnd, req.Limit) if err != nil { l.Errorf("Failed to query recent chat messages: %v", err) return nil, err diff --git a/src/internal/logic/recentjoinplayerlogic.go b/src/internal/logic/recentjoinplayerlogic.go index 4a7ff08..1e35b0e 100644 --- a/src/internal/logic/recentjoinplayerlogic.go +++ b/src/internal/logic/recentjoinplayerlogic.go @@ -37,9 +37,10 @@ func (l *RecentJoinPlayerLogic) RecentJoinPlayer(req *types.RecentJoinPlayerReq) AND c.log_time <= TO_TIMESTAMP($2 / 1000.0) AND c.steamid64 > 1 ORDER BY c.log_time DESC + LIMIT $3 ` - rows, err := l.svcCtx.DB.QueryContext(l.ctx, query, req.TimeRangeStart, req.TimeRangeEnd) + rows, err := l.svcCtx.DB.QueryContext(l.ctx, query, req.TimeRangeStart, req.TimeRangeEnd, req.Limit) if err != nil { l.Errorf("Failed to query recent join players: %v", err) return nil, err diff --git a/src/internal/logic/recentplaylogic.go b/src/internal/logic/recentplaylogic.go index 70c5328..32e304d 100644 --- a/src/internal/logic/recentplaylogic.go +++ b/src/internal/logic/recentplaylogic.go @@ -34,9 +34,10 @@ func (l *RecentPlayLogic) RecentPlay(req *types.RecentPlayReq) (resp *types.Rece AND duration >= $3 AND steamid64 > 1 ORDER BY duration DESC + LIMIT $4 ` - rows, err := l.svcCtx.DB.QueryContext(l.ctx, query, req.TimeRangeStart, req.TimeRangeEnd, req.LeastPlayTime) + rows, err := l.svcCtx.DB.QueryContext(l.ctx, query, req.TimeRangeStart, req.TimeRangeEnd, req.LeastPlayTime, req.Limit) if err != nil { l.Errorf("Failed to query recent play: %v", err) return nil, err diff --git a/src/internal/logic/topkillerlogic.go b/src/internal/logic/topkillerlogic.go index abf9d40..7f0709c 100644 --- a/src/internal/logic/topkillerlogic.go +++ b/src/internal/logic/topkillerlogic.go @@ -34,10 +34,10 @@ func (l *TopKillerLogic) TopKiller(req *types.TopKillerReq) (resp *types.TopKill AND attacker_steamid64 > 1 GROUP BY attacker_steamid64, attacker_name ORDER BY kill_count DESC - LIMIT 100 + LIMIT $3 ` - rows, err := l.svcCtx.DB.QueryContext(l.ctx, query, req.TimeRangeStart, req.TimeRangeEnd) + rows, err := l.svcCtx.DB.QueryContext(l.ctx, query, req.TimeRangeStart, req.TimeRangeEnd, req.Limit) if err != nil { l.Errorf("Failed to query top killers: %v", err) return nil, err diff --git a/src/internal/logic/topplaytimelogic.go b/src/internal/logic/topplaytimelogic.go index 2bf7fb4..f81724c 100644 --- a/src/internal/logic/topplaytimelogic.go +++ b/src/internal/logic/topplaytimelogic.go @@ -35,10 +35,10 @@ func (l *TopPlayTimeLogic) TopPlayTime(req *types.TopPlayTimeReq) (resp *types.T AND c.steamid64 > 1 GROUP BY c.steamid64, c.player_name ORDER BY total_playtime DESC - LIMIT 100 + LIMIT $3 ` - rows, err := l.svcCtx.DB.QueryContext(l.ctx, query, req.TimeRangeStart, req.TimeRangeEnd) + rows, err := l.svcCtx.DB.QueryContext(l.ctx, query, req.TimeRangeStart, req.TimeRangeEnd, req.Limit) if err != nil { l.Errorf("Failed to query top playtime: %v", err) return nil, err diff --git a/src/internal/types/types.go b/src/internal/types/types.go index c988b6f..e770070 100644 --- a/src/internal/types/types.go +++ b/src/internal/types/types.go @@ -11,8 +11,9 @@ type PingResp struct { } type RecentChatMessageReq struct { - TimeRangeStart int64 `json:"timeRangeStart"` // Unix timestamp in milliseconds - TimeRangeEnd int64 `json:"timeRangeEnd"` // Unix timestamp in milliseconds + TimeRangeStart int64 `json:"timeRangeStart"` // Unix timestamp in milliseconds + TimeRangeEnd int64 `json:"timeRangeEnd"` // Unix timestamp in milliseconds + Limit int `json:"limit,range=[1:10],example=10,default=10"` // Maximum number of messages to return } type RecentChatMessageResp struct { @@ -31,8 +32,9 @@ type RecentChatMessageRespMessage struct { } type RecentJoinPlayerReq struct { - TimeRangeStart int64 `json:"timeRangeStart"` // Unix timestamp in milliseconds - TimeRangeEnd int64 `json:"timeRangeEnd"` // Unix timestamp in milliseconds + TimeRangeStart int64 `json:"timeRangeStart"` // Unix timestamp in milliseconds + TimeRangeEnd int64 `json:"timeRangeEnd"` // Unix timestamp in milliseconds + Limit int `json:"limit,range=[1:10],example=10,default=10"` // Maximum number of players to return } type RecentJoinPlayerResp struct { @@ -47,9 +49,10 @@ type RecentJoinPlayerRespPlayer struct { } type RecentPlayReq struct { - TimeRangeStart int64 `json:"timeRangeStart"` // Unix timestamp in milliseconds - TimeRangeEnd int64 `json:"timeRangeEnd"` // Unix timestamp in milliseconds - LeastPlayTime int64 `json:"leastPlayTime"` // Least playtime in seconds to filter by + TimeRangeStart int64 `json:"timeRangeStart"` // Unix timestamp in milliseconds + TimeRangeEnd int64 `json:"timeRangeEnd"` // Unix timestamp in milliseconds + LeastPlayTime int64 `json:"leastPlayTime"` // Least playtime in seconds to filter by + Limit int `json:"limit,range=[1:10],example=10,default=10"` // Maximum number of players to return } type RecentPlayResp struct { @@ -64,8 +67,9 @@ type RecentPlayRespPlayer struct { } type TopKillerReq struct { - TimeRangeStart int64 `json:"timeRangeStart"` // Unix timestamp in milliseconds - TimeRangeEnd int64 `json:"timeRangeEnd"` // Unix timestamp in milliseconds + TimeRangeStart int64 `json:"timeRangeStart"` // Unix timestamp in milliseconds + TimeRangeEnd int64 `json:"timeRangeEnd"` // Unix timestamp in milliseconds + Limit int `json:"limit,range=[1:10],example=10,default=10"` // Maximum number of players to return } type TopKillerResp struct { @@ -79,8 +83,9 @@ type TopKillerRespPlayer struct { } type TopPlayTimeReq struct { - TimeRangeStart int64 `json:"timeRangeStart"` // Unix timestamp in milliseconds - TimeRangeEnd int64 `json:"timeRangeEnd"` // Unix timestamp in milliseconds + TimeRangeStart int64 `json:"timeRangeStart"` // Unix timestamp in milliseconds + TimeRangeEnd int64 `json:"timeRangeEnd"` // Unix timestamp in milliseconds + Limit int `json:"limit,range=[1:10],example=10,default=10"` // Maximum number of players to return } type TopPlayTimeResp struct {