package apis import ( "fmt" "github.com/gin-gonic/gin" "github.com/go-admin-team/go-admin-core/sdk/api" "github.com/go-admin-team/go-admin-core/sdk/pkg/jwtauth/user" _ "github.com/go-admin-team/go-admin-core/sdk/pkg/response" "go-admin/app/admin/models" "go-admin/app/admin/service" "go-admin/app/admin/service/dto" "go-admin/common/actions" ) type OtAppDashboard struct { api.Api } // GetPage 获取OtAppDashboard列表 // @Summary 获取OtAppDashboard列表 // @Description 获取OtAppDashboard列表 // @Tags OtAppDashboard // @Param pageSize query int false "页条数" // @Param pageIndex query int false "页码" // @Success 200 {object} response.Response{data=response.Page{list=[]models.OtAppDashboard}} "{"code": 200, "data": [...]}" // @Router /api/v1/ot-app-dashboard [get] // @Security Bearer func (e OtAppDashboard) GetPage(c *gin.Context) { req := dto.OtAppDashboardGetPageReq{} s := service.OtAppDashboard{} err := e.MakeContext(c). MakeOrm(). Bind(&req). MakeService(&s.Service). Errors if err != nil { e.Logger.Error(err) e.Error(500, err, err.Error()) return } p := actions.GetPermissionFromContext(c) list := make([]models.OtAppDashboard, 0) var count int64 err = s.GetPage(&req, p, &list, &count) if err != nil { e.Error(500, err, fmt.Sprintf("获取OtAppDashboard失败,\r\n失败信息 %s", err.Error())) return } e.PageOK(list, int(count), req.GetPageIndex(), req.GetPageSize(), "查询成功") } // Get 获取OtAppDashboard // @Summary 获取OtAppDashboard // @Description 获取OtAppDashboard // @Tags OtAppDashboard // @Param id path int false "id" // @Success 200 {object} response.Response{data=models.OtAppDashboard} "{"code": 200, "data": [...]}" // @Router /api/v1/ot-app-dashboard/{id} [get] // @Security Bearer func (e OtAppDashboard) Get(c *gin.Context) { req := dto.OtAppDashboardGetReq{} s := service.OtAppDashboard{} err := e.MakeContext(c). MakeOrm(). Bind(&req). MakeService(&s.Service). Errors if err != nil { e.Logger.Error(err) e.Error(500, err, err.Error()) return } var object models.OtAppDashboard p := actions.GetPermissionFromContext(c) err = s.Get(&req, p, &object) if err != nil { e.Error(500, err, fmt.Sprintf("获取OtAppDashboard失败,\r\n失败信息 %s", err.Error())) return } e.OK(object, "查询成功") } // Insert 创建OtAppDashboard // @Summary 创建OtAppDashboard // @Description 创建OtAppDashboard // @Tags OtAppDashboard // @Accept application/json // @Product application/json // @Param data body dto.OtAppDashboardInsertReq true "data" // @Success 200 {object} response.Response "{"code": 200, "message": "添加成功"}" // @Router /api/v1/ot-app-dashboard [post] // @Security Bearer func (e OtAppDashboard) Insert(c *gin.Context) { req := dto.OtAppDashboardInsertReq{} s := service.OtAppDashboard{} err := e.MakeContext(c). MakeOrm(). Bind(&req). MakeService(&s.Service). Errors if err != nil { e.Logger.Error(err) e.Error(500, err, err.Error()) return } // 设置创建人 req.SetCreateBy(user.GetUserId(c)) err = s.Insert(&req) if err != nil { e.Error(500, err, fmt.Sprintf("创建OtAppDashboard失败,\r\n失败信息 %s", err.Error())) return } e.OK(req.GetId(), "创建成功") } // Update 修改OtAppDashboard // @Summary 修改OtAppDashboard // @Description 修改OtAppDashboard // @Tags OtAppDashboard // @Accept application/json // @Product application/json // @Param id path int true "id" // @Param data body dto.OtAppDashboardUpdateReq true "body" // @Success 200 {object} response.Response "{"code": 200, "message": "修改成功"}" // @Router /api/v1/ot-app-dashboard/{id} [put] // @Security Bearer func (e OtAppDashboard) Update(c *gin.Context) { req := dto.OtAppDashboardUpdateReq{} s := service.OtAppDashboard{} err := e.MakeContext(c). MakeOrm(). Bind(&req). MakeService(&s.Service). Errors if err != nil { e.Logger.Error(err) e.Error(500, err, err.Error()) return } req.SetUpdateBy(user.GetUserId(c)) p := actions.GetPermissionFromContext(c) err = s.Update(&req, p) if err != nil { e.Error(500, err, fmt.Sprintf("修改OtAppDashboard失败,\r\n失败信息 %s", err.Error())) return } e.OK(req.GetId(), "修改成功") } // Delete 删除OtAppDashboard // @Summary 删除OtAppDashboard // @Description 删除OtAppDashboard // @Tags OtAppDashboard // @Param data body dto.OtAppDashboardDeleteReq true "body" // @Success 200 {object} response.Response "{"code": 200, "message": "删除成功"}" // @Router /api/v1/ot-app-dashboard [delete] // @Security Bearer func (e OtAppDashboard) Delete(c *gin.Context) { s := service.OtAppDashboard{} req := dto.OtAppDashboardDeleteReq{} err := e.MakeContext(c). MakeOrm(). Bind(&req). MakeService(&s.Service). Errors if err != nil { e.Logger.Error(err) e.Error(500, err, err.Error()) return } // req.SetUpdateBy(user.GetUserId(c)) p := actions.GetPermissionFromContext(c) err = s.Remove(&req, p) if err != nil { e.Error(500, err, fmt.Sprintf("删除OtAppDashboard失败,\r\n失败信息 %s", err.Error())) return } e.OK(req.GetId(), "删除成功") } func (e OtAppDashboard) GetDashBoardByAppId(c *gin.Context) { req := dto.OtAppDashboardGetByAppReq{} s := service.OtAppDashboard{} err := e.MakeContext(c). MakeOrm(). Bind(&req). MakeService(&s.Service). Errors if err != nil { e.Logger.Error(err) e.Error(500, err, err.Error()) return } var object models.OtAppDashboard object.AppId = req.AppId err = s.GetByAppId(&object) if err != nil { e.Error(500, err, fmt.Sprintf("获取OtAppDashboard失败,\r\n失败信息 %s", err.Error())) return } e.OK(object, "查询成功") }