MCPcopy Create free account
hub / github.com/kataras/iris / Update

Method Update

_examples/database/mysql/api/category_handler.go:108–132  ·  view source on GitHub ↗

Update performs a full-update of a record in the database. Method: PUT.

(ctx iris.Context)

Source from the content-addressed store, hash-verified

106// Update performs a full-update of a record in the database.
107// Method: PUT.
108func (h *CategoryHandler) Update(ctx iris.Context) {
109 var cat entity.Category
110 if err := ctx.ReadJSON(&cat); err != nil {
111 return
112 }
113
114 affected, err := h.service.Update(ctx.Request().Context(), cat)
115 if err != nil {
116 if err == sql.ErrUnprocessable {
117 ctx.StopWithJSON(iris.StatusUnprocessableEntity, newError(iris.StatusUnprocessableEntity, ctx.Request().Method, ctx.Path(), "required fields are missing"))
118 return
119 }
120
121 debugf("CategoryHandler.Update(DB): %v", err)
122 writeInternalServerError(ctx)
123 return
124 }
125
126 status := iris.StatusOK
127 if affected == 0 {
128 status = iris.StatusNotModified
129 }
130
131 ctx.StatusCode(status)
132}
133
134// PartialUpdate is the handler for partially update one or more fields of the record.
135// Method: PATCH.

Callers

nothing calls this directly

Calls 10

debugfFunction · 0.85
writeInternalServerErrorFunction · 0.85
ContextMethod · 0.80
RequestMethod · 0.80
StopWithJSONMethod · 0.80
newErrorFunction · 0.70
UpdateMethod · 0.65
PathMethod · 0.65
StatusCodeMethod · 0.65
ReadJSONMethod · 0.45

Tested by

no test coverage detected