PartialUpdate is the handler for partially update one or more fields of the record. Method: PATCH.
(ctx iris.Context)
| 125 | // PartialUpdate is the handler for partially update one or more fields of the record. |
| 126 | // Method: PATCH. |
| 127 | func (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. |
nothing calls this directly
no test coverage detected