usedata.go 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. dates, err := model.GetAllQuotaDates(startTimestamp, endTimestamp)
  12. if err != nil {
  13. c.JSON(http.StatusOK, gin.H{
  14. "success": false,
  15. "message": err.Error(),
  16. })
  17. return
  18. }
  19. c.JSON(http.StatusOK, gin.H{
  20. "success": true,
  21. "message": "",
  22. "data": dates,
  23. })
  24. return
  25. }
  26. func GetUserQuotaDates(c *gin.Context) {
  27. userId := c.GetInt("id")
  28. startTimestamp, _ := strconv.ParseInt(c.Query("start_timestamp"), 10, 64)
  29. endTimestamp, _ := strconv.ParseInt(c.Query("end_timestamp"), 10, 64)
  30. dates, err := model.GetQuotaDataByUserId(userId, startTimestamp, endTimestamp)
  31. if err != nil {
  32. c.JSON(http.StatusOK, gin.H{
  33. "success": false,
  34. "message": err.Error(),
  35. })
  36. return
  37. }
  38. c.JSON(http.StatusOK, gin.H{
  39. "success": true,
  40. "message": "",
  41. "data": dates,
  42. })
  43. return
  44. }