1Panel/backend/app/api/v1/logs.go

64 lines
1.6 KiB
Go
Raw Normal View History

2022-08-16 23:30:23 +08:00
package v1
import (
2022-11-15 18:44:50 +08:00
"errors"
"github.com/1Panel-dev/1Panel/backend/app/api/v1/helper"
"github.com/1Panel-dev/1Panel/backend/app/dto"
"github.com/1Panel-dev/1Panel/backend/constant"
2022-08-16 23:30:23 +08:00
"github.com/gin-gonic/gin"
)
2022-11-15 17:20:57 +08:00
func (b *BaseApi) GetLoginLogs(c *gin.Context) {
2022-08-16 23:30:23 +08:00
var req dto.PageInfo
if err := c.ShouldBindJSON(&req); err != nil {
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
return
}
2022-11-15 17:20:57 +08:00
total, list, err := logService.PageLoginLog(req)
2022-08-16 23:30:23 +08:00
if err != nil {
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
return
}
helper.SuccessWithData(c, dto.PageResult{
Items: list,
Total: total,
})
}
2022-11-15 17:20:57 +08:00
func (b *BaseApi) GetOperationLogs(c *gin.Context) {
var req dto.PageInfo
2022-08-16 23:30:23 +08:00
if err := c.ShouldBindJSON(&req); err != nil {
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
return
}
2022-11-15 17:20:57 +08:00
total, list, err := logService.PageOperationLog(req)
if err != nil {
2022-08-16 23:30:23 +08:00
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
return
}
2022-11-15 17:20:57 +08:00
helper.SuccessWithData(c, dto.PageResult{
Items: list,
Total: total,
})
2022-08-16 23:30:23 +08:00
}
2022-11-15 18:44:50 +08:00
func (b *BaseApi) CleanLogs(c *gin.Context) {
logtype, ok := c.Params.Get("logtype")
if !ok {
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, errors.New("error logtype in path"))
return
}
if err := logService.CleanLogs(logtype); err != nil {
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
return
}
helper.SuccessWithData(c, nil)
}