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

Method PartialUpdate

_examples/database/mysql/api/product_handler.go:127–153  ·  view source on GitHub ↗

PartialUpdate is the handler for partially update one or more fields of the record. Method: PATCH.

(ctx iris.Context)

Source from the content-addressed store, hash-verified

125// PartialUpdate is the handler for partially update one or more fields of the record.
126// Method: PATCH.
127func (h *ProductHandler) PartialUpdate(ctx iris.Context) {
128 id := ctx.Params().GetInt64Default("id", 0)
129
130 var attrs map[string]interface{}
131 if err := ctx.ReadJSON(&attrs); err != nil {
132 return
133 }
134
135 affected, err := h.service.PartialUpdate(ctx.Request().Context(), id, attrs)
136 if err != nil {
137 if err == sql.ErrUnprocessable {
138 ctx.StopWithJSON(iris.StatusUnprocessableEntity, newError(iris.StatusUnprocessableEntity, ctx.Request().Method, ctx.Path(), "unsupported value(s)"))
139 return
140 }
141
142 debugf("ProductHandler.PartialUpdate(DB): %v", err)
143 writeInternalServerError(ctx)
144 return
145 }
146
147 status := iris.StatusOK
148 if affected == 0 {
149 status = iris.StatusNotModified
150 }
151
152 ctx.StatusCode(status)
153}
154
155// Delete removes a record from the database.
156// Method: DELETE.

Callers

nothing calls this directly

Calls 11

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

Tested by

no test coverage detected