UpdateByID update a userExample by id @Summary Update a userExample by id @Description Updates the specified userExample by given id in the path, support partial update. @Tags userExample @Accept json @Produce json @Param id path string true "id" @Param data body types.UpdateUserExampleByIDRequest t
(c *gin.Context)
| 122 | // @Router /api/v1/userExample/{id} [put] |
| 123 | // @Security BearerAuth |
| 124 | func (h *userExampleHandler) UpdateByID(c *gin.Context) { |
| 125 | _, id, isAbort := getUserExampleIDFromPath(c) |
| 126 | if isAbort { |
| 127 | response.Error(c, ecode.InvalidParams) |
| 128 | return |
| 129 | } |
| 130 | |
| 131 | form := &types.UpdateUserExampleByIDRequest{} |
| 132 | err := c.ShouldBindJSON(form) |
| 133 | if err != nil { |
| 134 | logger.Warn("ShouldBindJSON error: ", logger.Err(err), middleware.GCtxRequestIDField(c)) |
| 135 | response.Error(c, ecode.InvalidParams) |
| 136 | return |
| 137 | } |
| 138 | form.ID = id |
| 139 | |
| 140 | userExample := &model.UserExample{} |
| 141 | err = copier.Copy(userExample, form) |
| 142 | if err != nil { |
| 143 | response.Error(c, ecode.ErrUpdateByIDUserExample) |
| 144 | return |
| 145 | } |
| 146 | // Note: if copier.Copy cannot assign a value to a field, add it here |
| 147 | |
| 148 | ctx := middleware.WrapCtx(c) |
| 149 | err = h.iDao.UpdateByID(ctx, userExample) |
| 150 | if err != nil { |
| 151 | logger.Error("UpdateByID error", logger.Err(err), logger.Any("form", form), middleware.GCtxRequestIDField(c)) |
| 152 | response.Output(c, ecode.InternalServerError.ToHTTPCode()) |
| 153 | return |
| 154 | } |
| 155 | |
| 156 | response.Success(c) |
| 157 | } |
| 158 | |
| 159 | // GetByID get a userExample by id |
| 160 | // @Summary Get a userExample by id |
nothing calls this directly
no test coverage detected