mirror of
https://github.com/idanoo/autobrr
synced 2025-07-23 08:49:13 +00:00
feat(http): implement missing findByID methods (#1635)
* feat(http): implement missing methods * general cleanup * unify param handling * handle not found errors * unify err handlers * fix(http): fmt type
This commit is contained in:
parent
accc875960
commit
acb91e8709
15 changed files with 379 additions and 422 deletions
|
@ -38,7 +38,7 @@ func (h actionHandler) Routes(r chi.Router) {
|
|||
r.Get("/", h.getActions)
|
||||
r.Post("/", h.storeAction)
|
||||
|
||||
r.Route("/{id}", func(r chi.Router) {
|
||||
r.Route("/{actionID}", func(r chi.Router) {
|
||||
r.Delete("/", h.deleteAction)
|
||||
r.Put("/", h.updateAction)
|
||||
r.Patch("/toggleEnabled", h.toggleActionEnabled)
|
||||
|
@ -56,17 +56,13 @@ func (h actionHandler) getActions(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
|
||||
func (h actionHandler) storeAction(w http.ResponseWriter, r *http.Request) {
|
||||
var (
|
||||
data domain.Action
|
||||
ctx = r.Context()
|
||||
)
|
||||
|
||||
var data domain.Action
|
||||
if err := json.NewDecoder(r.Body).Decode(&data); err != nil {
|
||||
h.encoder.Error(w, err)
|
||||
return
|
||||
}
|
||||
|
||||
action, err := h.service.Store(ctx, data)
|
||||
action, err := h.service.Store(r.Context(), data)
|
||||
if err != nil {
|
||||
h.encoder.Error(w, err)
|
||||
return
|
||||
|
@ -76,17 +72,13 @@ func (h actionHandler) storeAction(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
|
||||
func (h actionHandler) updateAction(w http.ResponseWriter, r *http.Request) {
|
||||
var (
|
||||
data domain.Action
|
||||
ctx = r.Context()
|
||||
)
|
||||
|
||||
var data domain.Action
|
||||
if err := json.NewDecoder(r.Body).Decode(&data); err != nil {
|
||||
h.encoder.Error(w, err)
|
||||
return
|
||||
}
|
||||
|
||||
action, err := h.service.Store(ctx, data)
|
||||
action, err := h.service.Store(r.Context(), data)
|
||||
if err != nil {
|
||||
h.encoder.Error(w, err)
|
||||
return
|
||||
|
@ -96,7 +88,7 @@ func (h actionHandler) updateAction(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
|
||||
func (h actionHandler) deleteAction(w http.ResponseWriter, r *http.Request) {
|
||||
actionID, err := parseInt(chi.URLParam(r, "id"))
|
||||
actionID, err := parseInt(chi.URLParam(r, "actionID"))
|
||||
if err != nil {
|
||||
h.encoder.StatusError(w, http.StatusBadRequest, errors.New("bad param id"))
|
||||
return
|
||||
|
@ -111,7 +103,7 @@ func (h actionHandler) deleteAction(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
|
||||
func (h actionHandler) toggleActionEnabled(w http.ResponseWriter, r *http.Request) {
|
||||
actionID, err := parseInt(chi.URLParam(r, "id"))
|
||||
actionID, err := parseInt(chi.URLParam(r, "actionID"))
|
||||
if err != nil {
|
||||
h.encoder.StatusError(w, http.StatusBadRequest, errors.New("bad param id"))
|
||||
return
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue