| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- package controller
- import (
- "github.com/gin-gonic/gin"
- "one-api/common"
- "one-api/model"
- "strconv"
- )
- func GetAllLogs(c *gin.Context) {
- p, _ := strconv.Atoi(c.Query("p"))
- if p < 0 {
- p = 0
- }
- logType, _ := strconv.Atoi(c.Query("type"))
- logs, err := model.GetAllLogs(logType, p*common.ItemsPerPage, common.ItemsPerPage)
- if err != nil {
- c.JSON(200, gin.H{
- "success": false,
- "message": err.Error(),
- })
- return
- }
- c.JSON(200, gin.H{
- "success": true,
- "message": "",
- "data": logs,
- })
- }
- func GetUserLogs(c *gin.Context) {
- p, _ := strconv.Atoi(c.Query("p"))
- if p < 0 {
- p = 0
- }
- userId := c.GetInt("id")
- logType, _ := strconv.Atoi(c.Query("type"))
- logs, err := model.GetUserLogs(userId, logType, p*common.ItemsPerPage, common.ItemsPerPage)
- if err != nil {
- c.JSON(200, gin.H{
- "success": false,
- "message": err.Error(),
- })
- return
- }
- c.JSON(200, gin.H{
- "success": true,
- "message": "",
- "data": logs,
- })
- }
- func SearchAllLogs(c *gin.Context) {
- keyword := c.Query("keyword")
- logs, err := model.SearchAllLogs(keyword)
- if err != nil {
- c.JSON(200, gin.H{
- "success": false,
- "message": err.Error(),
- })
- return
- }
- c.JSON(200, gin.H{
- "success": true,
- "message": "",
- "data": logs,
- })
- }
- func SearchUserLogs(c *gin.Context) {
- keyword := c.Query("keyword")
- userId := c.GetInt("id")
- logs, err := model.SearchUserLogs(userId, keyword)
- if err != nil {
- c.JSON(200, gin.H{
- "success": false,
- "message": err.Error(),
- })
- return
- }
- c.JSON(200, gin.H{
- "success": true,
- "message": "",
- "data": logs,
- })
- }
|