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" ) type CountryApi struct{} // Add // @Tags Country // @Summary 添加国家 // @Produce application/json // @Param object body request.AddCountry true "查询参数" // @Success 200 {object} contextx.Response{} // @Router /api/country/add [post] func (co *CountryApi) Add(c *gin.Context) { var params request.AddCountry ctx, ok := contextx.NewContext(c, ¶ms) if !ok { return } country := new(model.Country) country.Name = params.Name errCode := countryService.AddCountry(country) if errCode != ecode.OK { ctx.Fail(errCode) return } ctx.Ok() } // Delete // @Tags Country // @Summary 删除国家 // @Produce application/json // @Param object body request.DeleteCountry true "查询参数" // @Success 200 {object} contextx.Response{} // @Router /api/country/delete [delete] func (co *CountryApi) Delete(c *gin.Context) { var params request.DeleteCountry ctx, ok := contextx.NewContext(c, ¶ms) if !ok { return } errCode := countryService.DeleteCountry(params.Id) if errCode != ecode.OK { ctx.Fail(errCode) return } ctx.Ok() } // Update // @Tags Country // @Summary 更新国家 // @Produce application/json // @Param object body request.UpdateCountry true "查询参数" // @Success 200 {object} contextx.Response{} // @Router /api/country/update [put] func (co *CountryApi) Update(c *gin.Context) { var params request.UpdateCountry ctx, ok := contextx.NewContext(c, ¶ms) if !ok { return } errCode := countryService.UpdateCountry(&model.Country{ Id: params.Id, Name: params.Name, }) if errCode != ecode.OK { ctx.Fail(errCode) return } ctx.Ok() } // List // @Tags Country // @Summary 获取国家列表 // @Produce application/json // @Success 200 {object} contextx.Response{data=response.CountryResponse} "成功" // @Router /api/country/list [get] func (co *CountryApi) List(c *gin.Context) { ctx, ok := contextx.NewContext(c, nil) if !ok { return } countryList, errCode := countryService.GetCountryList() if errCode != ecode.OK { ctx.Fail(errCode) return } ctx.OkWithDetailed(response.CountryResponse{ List: countryList, }) }