refactor🎨 :统一格式
This commit is contained in:
1 parent
9a49700d09
commit
4dfd4e4647
14 files changed
+324
-414
No files matched your search
@@ -1,13 +1,11 @@
|
||||
package apis
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin/binding"
|
||||
"go-admin/app/admin/models"
|
||||
"net/http"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/gin-gonic/gin/binding"
|
||||
"github.com/go-admin-team/go-admin-core/sdk/api"
|
||||
"github.com/go-admin-team/go-admin-core/sdk/pkg/jwtauth/user"
|
||||
"go-admin/app/admin/models"
|
||||
|
||||
"go-admin/app/admin/service"
|
||||
"go-admin/app/admin/service/dto"
|
||||
@@ -17,78 +15,97 @@ type SysLoginLog struct {
|
||||
api.Api
|
||||
}
|
||||
|
||||
// GetSysLoginLogList 登录日志列表
|
||||
// @Summary 登录日志列表
|
||||
// @Description 获取JSON
|
||||
// @Tags 登录日志
|
||||
// @Param username query string false "用户名"
|
||||
// @Param ipaddr query string false "ip地址"
|
||||
// @Param loginLocation query string false "归属地"
|
||||
// @Param status query string false "状态"
|
||||
// @Param beginTime query string false "开始时间"
|
||||
// @Param endTime query string false "结束时间"
|
||||
// @Success 200 {object} response.Response "{"code": 200, "data": [...]}"
|
||||
// @Router /api/v1/sys-login-log [get]
|
||||
// @Security Bearer
|
||||
func (e SysLoginLog) GetSysLoginLogList(c *gin.Context) {
|
||||
s := new(service.SysLoginLog)
|
||||
d := new(dto.SysLoginLogSearch)
|
||||
s := service.SysLoginLog{}
|
||||
req := dto.SysLoginLogSearch {}
|
||||
err := e.MakeContext(c).
|
||||
MakeOrm().
|
||||
Bind(d, binding.Form).
|
||||
Bind(&req, binding.Form).
|
||||
MakeService(&s.Service).
|
||||
Errors
|
||||
if err != nil {
|
||||
e.Error(http.StatusInternalServerError, err, err.Error())
|
||||
e.Logger.Error(err)
|
||||
e.Error(500, err, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
list := make([]models.SysLoginLog, 0)
|
||||
var count int64
|
||||
|
||||
err = s.GetSysLoginLogPage(d, &list, &count)
|
||||
err = s.GetSysLoginLogPage(&req, &list, &count)
|
||||
if err != nil {
|
||||
e.Error(http.StatusUnprocessableEntity, err, "查询失败")
|
||||
e.Error(500, err, "查询失败")
|
||||
return
|
||||
}
|
||||
|
||||
e.PageOK(list, int(count), d.GetPageIndex(), d.GetPageSize(), "查询成功")
|
||||
e.PageOK(list, int(count), req.GetPageIndex(), req.GetPageSize(), "查询成功")
|
||||
}
|
||||
|
||||
// GetSysLoginLog 登录日志通过id获取
|
||||
// @Summary 登录日志通过id获取
|
||||
// @Description 获取JSON
|
||||
// @Tags 登录日志
|
||||
// @Param id path string false "id"
|
||||
// @Success 200 {object} response.Response "{"code": 200, "data": [...]}"
|
||||
// @Router /api/v1/sys-login-log/{id} [get]
|
||||
// @Security Bearer
|
||||
func (e SysLoginLog) GetSysLoginLog(c *gin.Context) {
|
||||
s := new(service.SysLoginLog)
|
||||
control := new(dto.SysLoginLogById)
|
||||
s := service.SysLoginLog{}
|
||||
req := dto.SysLoginLogById{}
|
||||
err := e.MakeContext(c).
|
||||
MakeOrm().
|
||||
Bind(control).
|
||||
Bind(&req, binding.JSON, nil).
|
||||
MakeService(&s.Service).
|
||||
Errors
|
||||
if err != nil {
|
||||
e.Error(http.StatusInternalServerError, err, err.Error())
|
||||
e.Logger.Error(err)
|
||||
e.Error(500, err, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
var object models.SysLoginLog
|
||||
err = s.GetSysLoginLog(control, &object)
|
||||
err = s.GetSysLoginLog(&req, &object)
|
||||
if err != nil {
|
||||
e.Error(http.StatusUnprocessableEntity, err, "查询失败")
|
||||
e.Error(500, err, "查询失败")
|
||||
return
|
||||
}
|
||||
|
||||
e.OK(object, "查看成功")
|
||||
}
|
||||
|
||||
// DeleteSysLoginLog 登录日志删除
|
||||
// @Summary 登录日志删除
|
||||
// @Description 登录日志删除
|
||||
// @Tags 登录日志
|
||||
// @Param data body dto.SysLoginLogById true "body"
|
||||
// @Success 200 {object} response.Response "{"code": 200, "data": [...]}"
|
||||
// @Router /api/v1/sys-login-log [delete]
|
||||
func (e SysLoginLog) DeleteSysLoginLog(c *gin.Context) {
|
||||
s := service.SysLoginLog{}
|
||||
control := new(dto.SysLoginLogById)
|
||||
req := dto.SysLoginLogById{}
|
||||
err := e.MakeContext(c).
|
||||
MakeOrm().
|
||||
Bind(control).
|
||||
Bind(&req, binding.JSON, nil).
|
||||
MakeService(&s.Service).
|
||||
Errors
|
||||
if err != nil {
|
||||
e.Error(http.StatusInternalServerError, err, err.Error())
|
||||
e.Logger.Error(err)
|
||||
e.Error(500, err, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
// 设置编辑人
|
||||
control.SetUpdateBy(user.GetUserId(c))
|
||||
|
||||
err = s.RemoveSysLoginLog(control)
|
||||
req.SetUpdateBy(user.GetUserId(c))
|
||||
err = s.RemoveSysLoginLog(&req)
|
||||
if err != nil {
|
||||
e.Logger.Errorf("RemoveSysLoginLog error, %s", err)
|
||||
e.Error(http.StatusInternalServerError, err, "删除失败")
|
||||
e.Error(500, err, "删除失败")
|
||||
return
|
||||
}
|
||||
e.OK(control.GetId(), "删除成功")
|
||||
}
|
||||
e.OK(req.GetId(), "删除成功")
|
||||
}
|
||||
Reference in new issue
Block a user