usedata.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. package controller
  2. import (
  3. "github.com/gin-gonic/gin"
  4. "net/http"
  5. "one-api/model"
  6. "strconv"
  7. )
  8. func GetAllQuotaDates(c *gin.Context) {
  9. startTimestamp, _ := strconv.ParseInt(c.Query("start_timestamp"), 10, 64)
  10. endTimestamp, _ := strconv.ParseInt(c.Query("end_timestamp"), 10, 64)
  11. username := c.Query("username")
  12. dates, err := model.GetAllQuotaDates(startTimestamp, endTimestamp, username)
  13. if err != nil {
  14. c.JSON(http.StatusOK, gin.H{
  15. "success": false,
  16. "message": err.Error(),
  17. })
  18. return
  19. }
  20. c.JSON(http.StatusOK, gin.H{
  21. "success": true,
  22. "message": "",
  23. "data": dates,
  24. })
  25. return
  26. }
  27. func GetUserQuotaDates(c *gin.Context) {
  28. userId := c.GetInt("id")
  29. startTimestamp, _ := strconv.ParseInt(c.Query("start_timestamp"), 10, 64)
  30. endTimestamp, _ := strconv.ParseInt(c.Query("end_timestamp"), 10, 64)
  31. dates, err := model.GetQuotaDataByUserId(userId, startTimestamp, endTimestamp)
  32. if err != nil {
  33. c.JSON(http.StatusOK, gin.H{
  34. "success": false,
  35. "message": err.Error(),
  36. })
  37. return
  38. }
  39. c.JSON(http.StatusOK, gin.H{
  40. "success": true,
  41. "message": "",
  42. "data": dates,
  43. })
  44. return
  45. }