package admin import ( "github.com/gin-gonic/gin" "github.com/lejianwen/rustdesk-api/global" "github.com/lejianwen/rustdesk-api/http/request/admin" "github.com/lejianwen/rustdesk-api/http/response" "github.com/lejianwen/rustdesk-api/model" "github.com/lejianwen/rustdesk-api/service" "gorm.io/gorm" "strconv" ) type LoginLog struct { } // Detail 登录日志 // @Tags 登录日志 // @Summary 登录日志详情 // @Description 登录日志详情 // @Accept json // @Produce json // @Param id path int true "ID" // @Success 200 {object} response.Response{data=model.LoginLog} // @Failure 500 {object} response.Response // @Router /admin/login_log/detail/{id} [get] // @Security token func (ct *LoginLog) Detail(c *gin.Context) { id := c.Param("id") iid, _ := strconv.Atoi(id) u := service.AllService.LoginLogService.InfoById(uint(iid)) if u.Id > 0 { response.Success(c, u) return } response.Fail(c, 101, response.TranslateMsg(c, "ItemNotFound")) return } // List 列表 // @Tags 登录日志 // @Summary 登录日志列表 // @Description 登录日志列表 // @Accept json // @Produce json // @Param page query int false "页码" // @Param page_size query int false "页大小" // @Param user_id query int false "用户ID" // @Success 200 {object} response.Response{data=model.LoginLogList} // @Failure 500 {object} response.Response // @Router /admin/login_log/list [get] // @Security token func (ct *LoginLog) List(c *gin.Context) { query := &admin.LoginLogQuery{} if err := c.ShouldBindQuery(query); err != nil { response.Fail(c, 101, response.TranslateMsg(c, "ParamsError")+err.Error()) return } res := service.AllService.LoginLogService.List(query.Page, query.PageSize, func(tx *gorm.DB) { if query.UserId > 0 { tx.Where("user_id = ?", query.UserId) } tx.Order("id desc") }) response.Success(c, res) } // Delete 删除 // @Tags 登录日志 // @Summary 登录日志删除 // @Description 登录日志删除 // @Accept json // @Produce json // @Param body body model.LoginLog true "登录日志信息" // @Success 200 {object} response.Response // @Failure 500 {object} response.Response // @Router /admin/login_log/delete [post] // @Security token func (ct *LoginLog) Delete(c *gin.Context) { f := &model.LoginLog{} if err := c.ShouldBindJSON(f); err != nil { response.Fail(c, 101, response.TranslateMsg(c, "ParamsError")+err.Error()) return } id := f.Id errList := global.Validator.ValidVar(c, id, "required,gt=0") if len(errList) > 0 { response.Fail(c, 101, errList[0]) return } l := service.AllService.LoginLogService.InfoById(f.Id) if l.Id == 0 { response.Fail(c, 101, response.TranslateMsg(c, "ItemNotFound")) return } err := service.AllService.LoginLogService.Delete(l) if err == nil { response.Success(c, nil) return } response.Fail(c, 101, err.Error()) } // BatchDelete 删除 // @Tags 登录日志 // @Summary 登录日志批量删除 // @Description 登录日志批量删除 // @Accept json // @Produce json // @Param body body admin.LoginLogIds true "登录日志" // @Success 200 {object} response.Response // @Failure 500 {object} response.Response // @Router /admin/login_log/batchDelete [post] // @Security token func (ct *LoginLog) BatchDelete(c *gin.Context) { f := &admin.LoginLogIds{} if err := c.ShouldBindJSON(f); err != nil { response.Fail(c, 101, response.TranslateMsg(c, "ParamsError")+err.Error()) return } if len(f.Ids) == 0 { response.Fail(c, 101, response.TranslateMsg(c, "ParamsError")) return } err := service.AllService.LoginLogService.BatchDelete(f.Ids) if err == nil { response.Success(c, nil) return } response.Fail(c, 101, err.Error()) return }