package v1 import ( "aps_crm/model" "aps_crm/model/request" "aps_crm/model/response" "aps_crm/pkg/contextx" "aps_crm/pkg/ecode" "github.com/gin-gonic/gin" "strconv" ) type ReportSourceApi struct{} // Add // // @Tags ReportSource // @Summary 添加报表来源 // @Produce application/json // @Param object body request.AddReportSource true "查询参数" // @Success 200 {object} contextx.Response{} // @Router /api/reportSource/add [post] func (s *ReportSourceApi) Add(c *gin.Context) { var params request.AddReportSource ctx, ok := contextx.NewContext(c, ¶ms) if !ok { return } reportSource := new(model.ReportSource) reportSource.Name = params.Name errCode := reportSourceService.AddReportSource(reportSource) if errCode != ecode.OK { ctx.Fail(errCode) return } ctx.Ok() } // Delete // // @Tags ReportSource // @Summary 删除报表来源 // @Produce application/json // @Param id path int true "查询参数" // @Success 200 {object} contextx.Response{} // @Router /api/reportSource/delete/{id} [delete] func (s *ReportSourceApi) Delete(c *gin.Context) { ctx, ok := contextx.NewContext(c, nil) if !ok { return } id, _ := strconv.Atoi(c.Param("id")) errCode := reportSourceService.DeleteReportSource(id) if errCode != ecode.OK { ctx.Fail(errCode) return } ctx.Ok() } // Update // // @Tags ReportSource // @Summary 更新报表来源 // @Produce application/json // @Param object body request.UpdateReportSources true "查询参数" // @Success 200 {object} contextx.Response{} // @Router /api/reportSource/update [put] func (s *ReportSourceApi) Update(c *gin.Context) { var params request.UpdateReportSources ctx, ok := contextx.NewContext(c, ¶ms) if !ok { return } errCode := reportSourceService.UpdateReportSource(params.ReportSources) if errCode != ecode.OK { ctx.Fail(errCode) return } ctx.Ok() } // List // // @Tags ReportSource // @Summary 获取报表来源列表 // @Produce application/json // @Success 200 {object} contextx.Response{data=response.ReportSourceResponse} // @Router /api/reportSource/list [get] func (s *ReportSourceApi) List(c *gin.Context) { ctx, ok := contextx.NewContext(c, nil) if !ok { return } reportSources, errCode := reportSourceService.GetReportSourceList() if errCode != ecode.OK { ctx.Fail(errCode) return } ctx.OkWithDetailed(response.ReportSourceResponse{ List: reportSources, }) }