package v1 import ( "aps_crm/model/request" "aps_crm/model/response" "aps_crm/pkg/contextx" "aps_crm/pkg/ecode" "aps_crm/service" "github.com/gin-gonic/gin" "strconv" ) type TimeSpentApi struct{} // Add // @Tags 花费时间管理 // @Summary 添加花费时间 // @Produce application/json // @Param object body request.AddTimeSpent true "查询参数" // @Success 200 {object} contextx.Response{} // @Router /api/timeSpent/add [post] func (s *TimeSpentApi) Add(c *gin.Context) { var params request.AddTimeSpent ctx, ok := contextx.NewContext(c, ¶ms) if !ok { return } errCode := service.NewTimeSpentService().AddTimeSpent(¶ms.TimeSpent) if errCode != ecode.OK { ctx.Fail(errCode) return } ctx.Ok() } // Delete // @Tags 花费时间管理 // @Summary 删除花费时间 // @Produce application/json // @Param id path int true "查询参数" // @Success 200 {object} contextx.Response{} // @Router /api/timeSpent/delete/{id} [delete] func (s *TimeSpentApi) Delete(c *gin.Context) { ctx, ok := contextx.NewContext(c, nil) if !ok { return } id, _ := strconv.Atoi(c.Param("id")) errCode := service.NewTimeSpentService().DeleteTimeSpent(id) if errCode != ecode.OK { ctx.Fail(errCode) return } ctx.Ok() } // Update // @Tags 花费时间管理 // @Summary 更新花费时间 // @Produce application/json // @Param object body request.UpdateTimeSpent true "查询参数" // @Success 200 {object} contextx.Response{} // @Router /api/timeSpent/update [put] func (s *TimeSpentApi) Update(c *gin.Context) { var params request.UpdateTimeSpent ctx, ok := contextx.NewContext(c, ¶ms) if !ok { return } if params.Id == 0 { ctx.Fail(ecode.ParamsErr) } params.TimeSpent.Id = params.Id errCode := service.NewTimeSpentService().UpdateTimeSpent(¶ms.TimeSpent) if errCode != ecode.OK { ctx.Fail(errCode) return } ctx.Ok() } // List // @Tags 花费时间管理 // @Summary 获取花费时间列表 // @Produce application/json // @Success 200 {object} response.ListResponse{data=[]model.TimeSpent} // @Router /api/timeSpent/list [get] func (s *TimeSpentApi) List(c *gin.Context) { ctx, ok := contextx.NewContext(c, nil) if !ok { return } timeSpent, total, errCode := service.NewTimeSpentService().GetTimeSpentList() if errCode != ecode.OK { ctx.Fail(errCode) return } ctx.OkWithDetailed(response.ListResponse{ Data: timeSpent, Count: total, }) }