Initial sanitized code sync
This commit is contained in:
40
internal/handler/email_record.go
Normal file
40
internal/handler/email_record.go
Normal file
@@ -0,0 +1,40 @@
|
||||
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()))
|
||||
}
|
||||
Reference in New Issue
Block a user