package pet import ( "github.com/flipped-aurora/gin-vue-admin/server/global" "github.com/flipped-aurora/gin-vue-admin/server/model/common/response" "github.com/flipped-aurora/gin-vue-admin/server/model/pet" petReq "github.com/flipped-aurora/gin-vue-admin/server/model/pet/request" "github.com/gin-gonic/gin" "go.uber.org/zap" ) type PetRecordsApi struct{} // CreatePetRecords 创建petRecords表 // @Tags PetRecords // @Summary 创建petRecords表 // @Security ApiKeyAuth // @Accept application/json // @Produce application/json // @Param data body pet.PetRecords true "创建petRecords表" // @Success 200 {object} response.Response{msg=string} "创建成功" // @Router /petRecords/createPetRecords [post] func (petRecordsApi *PetRecordsApi) CreatePetRecords(c *gin.Context) { // 创建业务用Context ctx := c.Request.Context() var petRecords pet.PetRecords err := c.ShouldBindJSON(&petRecords) if err != nil { response.FailWithMessage(err.Error(), c) return } err = petRecordsService.CreatePetRecords(ctx, &petRecords) if err != nil { global.GVA_LOG.Error("创建失败!", zap.Error(err)) response.FailWithMessage("创建失败:"+err.Error(), c) return } response.OkWithMessage("创建成功", c) } // DeletePetRecords 删除petRecords表 // @Tags PetRecords // @Summary 删除petRecords表 // @Security ApiKeyAuth // @Accept application/json // @Produce application/json // @Param data body pet.PetRecords true "删除petRecords表" // @Success 200 {object} response.Response{msg=string} "删除成功" // @Router /petRecords/deletePetRecords [delete] func (petRecordsApi *PetRecordsApi) DeletePetRecords(c *gin.Context) { // 创建业务用Context ctx := c.Request.Context() ID := c.Query("ID") err := petRecordsService.DeletePetRecords(ctx, ID) if err != nil { global.GVA_LOG.Error("删除失败!", zap.Error(err)) response.FailWithMessage("删除失败:"+err.Error(), c) return } response.OkWithMessage("删除成功", c) } // DeletePetRecordsByIds 批量删除petRecords表 // @Tags PetRecords // @Summary 批量删除petRecords表 // @Security ApiKeyAuth // @Accept application/json // @Produce application/json // @Success 200 {object} response.Response{msg=string} "批量删除成功" // @Router /petRecords/deletePetRecordsByIds [delete] func (petRecordsApi *PetRecordsApi) DeletePetRecordsByIds(c *gin.Context) { // 创建业务用Context ctx := c.Request.Context() IDs := c.QueryArray("IDs[]") err := petRecordsService.DeletePetRecordsByIds(ctx, IDs) if err != nil { global.GVA_LOG.Error("批量删除失败!", zap.Error(err)) response.FailWithMessage("批量删除失败:"+err.Error(), c) return } response.OkWithMessage("批量删除成功", c) } // UpdatePetRecords 更新petRecords表 // @Tags PetRecords // @Summary 更新petRecords表 // @Security ApiKeyAuth // @Accept application/json // @Produce application/json // @Param data body pet.PetRecords true "更新petRecords表" // @Success 200 {object} response.Response{msg=string} "更新成功" // @Router /petRecords/updatePetRecords [put] func (petRecordsApi *PetRecordsApi) UpdatePetRecords(c *gin.Context) { // 从ctx获取标准context进行业务行为 ctx := c.Request.Context() var petRecords pet.PetRecords err := c.ShouldBindJSON(&petRecords) if err != nil { response.FailWithMessage(err.Error(), c) return } err = petRecordsService.UpdatePetRecords(ctx, petRecords) if err != nil { global.GVA_LOG.Error("更新失败!", zap.Error(err)) response.FailWithMessage("更新失败:"+err.Error(), c) return } response.OkWithMessage("更新成功", c) } // FindPetRecords 用id查询petRecords表 // @Tags PetRecords // @Summary 用id查询petRecords表 // @Security ApiKeyAuth // @Accept application/json // @Produce application/json // @Param ID query uint true "用id查询petRecords表" // @Success 200 {object} response.Response{data=pet.PetRecords,msg=string} "查询成功" // @Router /petRecords/findPetRecords [get] func (petRecordsApi *PetRecordsApi) FindPetRecords(c *gin.Context) { // 创建业务用Context ctx := c.Request.Context() ID := c.Query("ID") repetRecords, err := petRecordsService.GetPetRecords(ctx, ID) if err != nil { global.GVA_LOG.Error("查询失败!", zap.Error(err)) response.FailWithMessage("查询失败:"+err.Error(), c) return } response.OkWithData(repetRecords, c) } // GetPetRecordsList 分页获取petRecords表列表 // @Tags PetRecords // @Summary 分页获取petRecords表列表 // @Security ApiKeyAuth // @Accept application/json // @Produce application/json // @Param data query petReq.PetRecordsSearch true "分页获取petRecords表列表" // @Success 200 {object} response.Response{data=response.PageResult,msg=string} "获取成功" // @Router /petRecords/getPetRecordsList [get] func (petRecordsApi *PetRecordsApi) GetPetRecordsList(c *gin.Context) { // 创建业务用Context ctx := c.Request.Context() var pageInfo petReq.PetRecordsSearch err := c.ShouldBindQuery(&pageInfo) if err != nil { response.FailWithMessage(err.Error(), c) return } list, total, err := petRecordsService.GetPetRecordsInfoList(ctx, pageInfo) if err != nil { global.GVA_LOG.Error("获取失败!", zap.Error(err)) response.FailWithMessage("获取失败:"+err.Error(), c) return } response.OkWithDetailed(response.PageResult{ List: list, Total: total, Page: pageInfo.Page, PageSize: pageInfo.PageSize, }, "获取成功", c) }