MCPcopy
hub / github.com/go-dev-frame/sponge / UpdateByID

Method UpdateByID

internal/handler/userExample.go:124–157  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

122// @Router /api/v1/userExample/{id} [put]
123// @Security BearerAuth
124func (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

Callers

nothing calls this directly

Calls 13

ErrorFunction · 0.92
WarnFunction · 0.92
ErrFunction · 0.92
GCtxRequestIDFieldFunction · 0.92
CopyFunction · 0.92
WrapCtxFunction · 0.92
ErrorFunction · 0.92
AnyFunction · 0.92
OutputFunction · 0.92
SuccessFunction · 0.92
getUserExampleIDFromPathFunction · 0.85
ToHTTPCodeMethod · 0.80

Tested by

no test coverage detected