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

Method Update

_examples/database/mysql/api/product_handler.go:99–123  ·  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

97// Update performs a full-update of a record in the database.
98// Method: PUT.
99func (h *ProductHandler) Update(ctx iris.Context) {
100 var product entity.Product
101 if err := ctx.ReadJSON(&product); err != nil {
102 return
103 }
104
105 affected, err := h.service.Update(ctx.Request().Context(), product)
106 if err != nil {
107 if err == sql.ErrUnprocessable {
108 ctx.StopWithJSON(iris.StatusUnprocessableEntity, newError(iris.StatusUnprocessableEntity, ctx.Request().Method, ctx.Path(), "required fields are missing"))
109 return
110 }
111
112 debugf("ProductHandler.Update(DB): %v", err)
113 writeInternalServerError(ctx)
114 return
115 }
116
117 status := iris.StatusOK
118 if affected == 0 {
119 status = iris.StatusNotModified
120 }
121
122 ctx.StatusCode(status)
123}
124
125// PartialUpdate is the handler for partially update one or more fields of the record.
126// 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