update:user endpoint (#17)

This commit is contained in:
Sakurasan
2023-06-11 20:12:53 +08:00
parent f4e947b377
commit 06bd5e048b
3 changed files with 57 additions and 1 deletions

View File

@@ -68,6 +68,21 @@ func QueryUsage(from, to string) ([]CalcUsage, error) {
return results, nil
}
func QueryUserUsage(userid, from, to string) (*CalcUsage, error) {
var results = new(CalcUsage)
err := usage.Model(&DailyUsage{}).Select(`user_id,
--SUM(prompt_units) AS prompt_units,
-- SUM(completion_units) AS completion_units,
SUM(total_unit) AS total_unit,
printf('%.6f', SUM(cost)) AS cost`).
Where("user_id = ? AND date >= ? AND date < ?", userid, from, to).
Find(&results).Error
if err != nil {
return nil, err
}
return results, nil
}
type Tokens struct {
UserID int
PromptCount int