package admin import ( "ulink-admin/frame" "ulink-admin/modules/system/models/model" "ulink-admin/modules/system/models/req" "ulink-admin/modules/system/models/response" "ulink-admin/modules/system/service" "ulink-admin/pkg/excels" "ulink-admin/pkg/file" "ulink-admin/pkg/page" "ulink-admin/utils" ) type TestApi struct { TestService *service.TestService `inject:""` } // List 查询测试管理分页数据 // @Summary 分页查询测试管理数据接口 // @Description 分页查询测试管理数据接口 // @Tags 测试管理相关接口 // @Accept application/json // @Produce application/json // @Param Authorization header string false "Bearer 令牌" // @Param object query req.TestQuery false "查询参数" // @Security ApiKeyAuth // @Success 200 {object} resp.Response{data=page.Page{list=model.Test},msg=string} "分页获取测试管理列表,返回包括列表,总数,页码,每页数量" // @Router /test/page [get] func (this TestApi) Page(c *frame.Context) { query := &req.TestQuery{} c.ValidteError(c.ShouldBind(query), query) var list = make([]response.TestResponse, 0) i := this.TestService.Page(query, &list) c.Ok(page.Page{List: list, Total: i, Size: query.PageSize}) } // List 查询测试管理所有数据 // @Summary 查询全部数据测试管理数据接口 // @Description 查询全部数据测试管理数据接口 // @Tags 测试管理相关接口 // @Accept application/json // @Produce application/json // @Param Authorization header string false "Bearer 令牌" // @Param object query req.TestQuery false "查询参数" // @Security ApiKeyAuth // @Success 200 {object} resp.Response{data=model.Test,msg=string} "分页获取测试管理列表,返回包括列表,总数,页码,每页数量" // @Router /test/list [get] func (this TestApi) List(c *frame.Context) { query := &req.TestQuery{} list := make([]response.TestResponse, 0) c.ValidteError(c.ShouldBind(query), query) this.TestService.List(query, &list) c.Ok(list) } // Get 根据测试管理Id获取详细信息 // @Summary 测试管理详情查询接口 // @Description 测试管理详情查询接口 // @Tags 测试管理相关接口 // @Accept application/json // @Produce application/json // @Param Authorization header string false "Bearer 令牌" // @Param id query int true "id" id // @Security ApiKeyAuth // @Success 200 {object} resp.Response{data=model.Test,msg=string} "返回测试管理详情查询" // @Router /test [get] func (this TestApi) Get(c *frame.Context) { var req struct { Id int64 `form:"id" binding:"required" msg:"id不存在" ` //id } c.ValidteError(c.ShouldBind(&req), &req) c.Ok(this.TestService.Get(req.Id)) } // Add 新增测试管理 // @Summary 新增测试管理接口 // @Description 新增测试管理接口 // @Tags 测试管理相关接口 // @Accept application/json // @Produce application/json // @Param Authorization header string false "Bearer 令牌" // @Param data body model.Test true "测试管理实体对象" // @Success 200 {object} resp.Response{msg=string} "操作状态" // @Router /test/add [post] func (this TestApi) Add(c *frame.Context) { params, test := &req.TestAdd{}, &model.Test{} c.ValidteError(c.ShouldBind(params), params) utils.CopyFields(test, params) this.TestService.Insert(test) } // Edit 修改测试管理数据接口 // @Summary 修改测试管理接口 // @Description 新增测试管理接口 // @Tags 测试管理相关接口 // @Accept application/json // @Produce application/json // @Param Authorization header string false "Bearer 令牌" // @Param data body model.Test true "测试管理实体对象" // @Success 200 {object} resp.Response{msg=string} "操作状态" // @Router /test/edit [put] func (this TestApi) Edit(c *frame.Context) { params, test := &req.TestEdit{}, &model.Test{} c.ValidteError(c.ShouldBind(params), params) utils.CopyFields(test, params) this.TestService.Edit(test, utils.GetFieldS(params)) } // Delete 删除测试管理数据 // @Summary 删除测试管理接口 // @Description 删除测试管理接口 // @Tags 测试管理相关接口 // @Accept application/json // @Produce application/json // @Param Authorization header string false "Bearer 令牌" // @Param id path int true "id" id // @Success 200 {object} resp.Response{msg=string} "操作状态" // @Router /test [delete] func (a TestApi) Delete(c *frame.Context) { var req struct { Ids []int64 `form:"ids" binding:"required" msg:"ids不存在"` //ids } c.ValidteError(c.ShouldBind(&req), &req) a.TestService.Delete(req.Ids) } // Export 导出excel func (this TestApi) Export(c *frame.Context) { query := &req.TestQuery{} list := make([]model.Test, 0) c.ValidteError(c.ShouldBind(query), query) this.TestService.List(query, list) excelList := make([]interface{}, 0) for _, test := range list { excelList = append(excelList, test) } _, files := excels.ExportExcel(excelList, "测试管理数据表") file.DownloadExcel(c, files) }