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