Update performs a full-update of a record in the database. Method: PUT.
(ctx iris.Context)
| 97 | // Update performs a full-update of a record in the database. |
| 98 | // Method: PUT. |
| 99 | func (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. |
nothing calls this directly
no test coverage detected