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 CurrencyApi struct{} // Add // // @Tags Currency // @Summary 添加币种 // @Produce application/json // @Param object body request.AddCurrency true "查询参数" // @Success 200 {object} contextx.Response{} // @Router /api/currency/add [post] func (s *CurrencyApi) Add(c *gin.Context) { var params request.AddCurrency ctx, ok := contextx.NewContext(c, ¶ms) if !ok { return } currency := new(model.Currency) currency.Name = params.Name errCode := currencyService.AddCurrency(currency) if errCode != ecode.OK { ctx.Fail(errCode) return } ctx.Ok() } // Delete // // @Tags Currency // @Summary 删除币种 // @Produce application/json // @Param id path int true "查询参数" // @Success 200 {object} contextx.Response{} // @Router /api/currency/delete/{id} [delete] func (s *CurrencyApi) Delete(c *gin.Context) { ctx, ok := contextx.NewContext(c, nil) if !ok { return } id, _ := strconv.Atoi(c.Param("id")) errCode := currencyService.DeleteCurrency(id) if errCode != ecode.OK { ctx.Fail(errCode) return } ctx.Ok() } // Update // // @Tags Currency // @Summary 更新币种 // @Produce application/json // @Param object body request.UpdateCurrencys true "查询参数" // @Success 200 {object} contextx.Response{} // @Router /api/currency/update [put] func (s *CurrencyApi) Update(c *gin.Context) { var params request.UpdateCurrencys ctx, ok := contextx.NewContext(c, ¶ms) if !ok { return } errCode := currencyService.UpdateCurrency(params.Currencys) if errCode != ecode.OK { ctx.Fail(errCode) return } ctx.Ok() } // List // // @Tags Currency // @Summary 获取币种列表 // @Produce application/json // @Success 200 {object} contextx.Response{data=response.CurrencyResponse} // @Router /api/currency/list [get] func (s *CurrencyApi) List(c *gin.Context) { ctx, ok := contextx.NewContext(c, nil) if !ok { return } currencys, errCode := currencyService.GetCurrencyList() if errCode != ecode.OK { ctx.Fail(errCode) return } ctx.OkWithDetailed(response.CurrencyResponse{ List: currencys, }) }