41 lines
879 B
Go
41 lines
879 B
Go
package handler
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"gpt-plus/internal/db"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
func RegisterEmailRecordRoutes(api *gin.RouterGroup) {
|
|
api.GET("/email-records", ListEmailRecords)
|
|
api.GET("/email-records/stats", GetEmailRecordStats)
|
|
}
|
|
|
|
func ListEmailRecords(c *gin.Context) {
|
|
d := db.GetDB()
|
|
query := d.Model(&db.EmailRecord{}).Order("created_at DESC")
|
|
|
|
if status := c.Query("status"); status != "" {
|
|
query = query.Where("status = ?", status)
|
|
}
|
|
|
|
p := db.PaginationParams{
|
|
Page: intQuery(c, "page", 1),
|
|
Size: intQuery(c, "size", 20),
|
|
}
|
|
|
|
var records []db.EmailRecord
|
|
result, err := db.Paginate(query, p, &records)
|
|
if err != nil {
|
|
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
|
return
|
|
}
|
|
c.JSON(http.StatusOK, result)
|
|
}
|
|
|
|
func GetEmailRecordStats(c *gin.Context) {
|
|
c.JSON(http.StatusOK, db.GetEmailRecordStats(db.GetDB()))
|
|
}
|