mirror of
https://github.com/idanoo/autobrr
synced 2025-07-23 00:39:13 +00:00
feat(releases): replay actions (#932)
* feat(releases): replay actions * feat(releases): replay actions component * fix: update filter actions * fix: select filter_id from ras
This commit is contained in:
parent
97333d334f
commit
6898ad8315
16 changed files with 752 additions and 189 deletions
|
@ -11,13 +11,14 @@ import (
|
|||
"strconv"
|
||||
|
||||
"github.com/autobrr/autobrr/internal/domain"
|
||||
|
||||
"github.com/go-chi/chi/v5"
|
||||
)
|
||||
|
||||
type actionService interface {
|
||||
List(ctx context.Context) ([]domain.Action, error)
|
||||
Store(ctx context.Context, action domain.Action) (*domain.Action, error)
|
||||
Delete(actionID int) error
|
||||
Delete(ctx context.Context, req *domain.DeleteActionRequest) error
|
||||
ToggleEnabled(actionID int) error
|
||||
}
|
||||
|
||||
|
@ -36,15 +37,19 @@ func newActionHandler(encoder encoder, service actionService) *actionHandler {
|
|||
func (h actionHandler) Routes(r chi.Router) {
|
||||
r.Get("/", h.getActions)
|
||||
r.Post("/", h.storeAction)
|
||||
r.Delete("/{id}", h.deleteAction)
|
||||
r.Put("/{id}", h.updateAction)
|
||||
r.Patch("/{id}/toggleEnabled", h.toggleActionEnabled)
|
||||
|
||||
r.Route("/{id}", func(r chi.Router) {
|
||||
r.Delete("/", h.deleteAction)
|
||||
r.Put("/", h.updateAction)
|
||||
r.Patch("/toggleEnabled", h.toggleActionEnabled)
|
||||
})
|
||||
}
|
||||
|
||||
func (h actionHandler) getActions(w http.ResponseWriter, r *http.Request) {
|
||||
actions, err := h.service.List(r.Context())
|
||||
if err != nil {
|
||||
// encode error
|
||||
h.encoder.Error(w, err)
|
||||
return
|
||||
}
|
||||
|
||||
h.encoder.StatusResponse(w, http.StatusOK, actions)
|
||||
|
@ -57,13 +62,14 @@ func (h actionHandler) storeAction(w http.ResponseWriter, r *http.Request) {
|
|||
)
|
||||
|
||||
if err := json.NewDecoder(r.Body).Decode(&data); err != nil {
|
||||
// encode error
|
||||
h.encoder.Error(w, err)
|
||||
return
|
||||
}
|
||||
|
||||
action, err := h.service.Store(ctx, data)
|
||||
if err != nil {
|
||||
// encode error
|
||||
h.encoder.Error(w, err)
|
||||
return
|
||||
}
|
||||
|
||||
h.encoder.StatusResponse(w, http.StatusCreated, action)
|
||||
|
@ -76,13 +82,14 @@ func (h actionHandler) updateAction(w http.ResponseWriter, r *http.Request) {
|
|||
)
|
||||
|
||||
if err := json.NewDecoder(r.Body).Decode(&data); err != nil {
|
||||
// encode error
|
||||
h.encoder.Error(w, err)
|
||||
return
|
||||
}
|
||||
|
||||
action, err := h.service.Store(ctx, data)
|
||||
if err != nil {
|
||||
// encode error
|
||||
h.encoder.Error(w, err)
|
||||
return
|
||||
}
|
||||
|
||||
h.encoder.StatusResponse(w, http.StatusCreated, action)
|
||||
|
@ -91,11 +98,13 @@ 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"))
|
||||
if err != nil {
|
||||
h.encoder.StatusResponse(w, http.StatusBadRequest, errors.New("bad param id"))
|
||||
h.encoder.StatusError(w, http.StatusBadRequest, errors.New("bad param id"))
|
||||
return
|
||||
}
|
||||
|
||||
if err := h.service.Delete(actionID); err != nil {
|
||||
// encode error
|
||||
if err := h.service.Delete(r.Context(), &domain.DeleteActionRequest{ActionId: actionID}); err != nil {
|
||||
h.encoder.Error(w, err)
|
||||
return
|
||||
}
|
||||
|
||||
h.encoder.StatusResponse(w, http.StatusNoContent, nil)
|
||||
|
@ -104,11 +113,13 @@ 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"))
|
||||
if err != nil {
|
||||
h.encoder.StatusResponse(w, http.StatusBadRequest, errors.New("bad param id"))
|
||||
h.encoder.StatusError(w, http.StatusBadRequest, errors.New("bad param id"))
|
||||
return
|
||||
}
|
||||
|
||||
if err := h.service.ToggleEnabled(actionID); err != nil {
|
||||
// encode error
|
||||
h.encoder.Error(w, err)
|
||||
return
|
||||
}
|
||||
|
||||
h.encoder.StatusResponse(w, http.StatusCreated, nil)
|
||||
|
|
|
@ -10,6 +10,7 @@ import (
|
|||
"strconv"
|
||||
|
||||
"github.com/autobrr/autobrr/internal/domain"
|
||||
|
||||
"github.com/go-chi/chi/v5"
|
||||
)
|
||||
|
||||
|
@ -19,6 +20,7 @@ type releaseService interface {
|
|||
GetIndexerOptions(ctx context.Context) ([]string, error)
|
||||
Stats(ctx context.Context) (*domain.ReleaseStats, error)
|
||||
Delete(ctx context.Context) error
|
||||
Retry(ctx context.Context, req *domain.ReleaseActionRetryReq) error
|
||||
}
|
||||
|
||||
type releaseHandler struct {
|
||||
|
@ -39,6 +41,10 @@ func (h releaseHandler) Routes(r chi.Router) {
|
|||
r.Get("/stats", h.getStats)
|
||||
r.Get("/indexers", h.getIndexerOptions)
|
||||
r.Delete("/all", h.deleteReleases)
|
||||
|
||||
r.Route("/{releaseId}", func(r chi.Router) {
|
||||
r.Post("/actions/{actionStatusId}/retry", h.retryAction)
|
||||
})
|
||||
}
|
||||
|
||||
func (h releaseHandler) findReleases(w http.ResponseWriter, r *http.Request) {
|
||||
|
@ -186,3 +192,46 @@ func (h releaseHandler) deleteReleases(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
h.encoder.NoContent(w)
|
||||
}
|
||||
|
||||
func (h releaseHandler) retryAction(w http.ResponseWriter, r *http.Request) {
|
||||
var (
|
||||
req *domain.ReleaseActionRetryReq
|
||||
err error
|
||||
)
|
||||
|
||||
releaseIdParam := chi.URLParam(r, "releaseId")
|
||||
if releaseIdParam == "" {
|
||||
h.encoder.StatusError(w, http.StatusBadRequest, err)
|
||||
return
|
||||
}
|
||||
|
||||
releaseId, err := strconv.Atoi(releaseIdParam)
|
||||
if err != nil {
|
||||
h.encoder.StatusError(w, http.StatusBadRequest, err)
|
||||
return
|
||||
}
|
||||
|
||||
actionStatusIdParam := chi.URLParam(r, "actionStatusId")
|
||||
if actionStatusIdParam == "" {
|
||||
h.encoder.StatusError(w, http.StatusBadRequest, err)
|
||||
return
|
||||
}
|
||||
|
||||
actionStatusId, err := strconv.Atoi(actionStatusIdParam)
|
||||
if err != nil {
|
||||
h.encoder.StatusError(w, http.StatusBadRequest, err)
|
||||
return
|
||||
}
|
||||
|
||||
req = &domain.ReleaseActionRetryReq{
|
||||
ReleaseId: releaseId,
|
||||
ActionStatusId: actionStatusId,
|
||||
}
|
||||
|
||||
if err := h.service.Retry(r.Context(), req); err != nil {
|
||||
h.encoder.Error(w, err)
|
||||
return
|
||||
}
|
||||
|
||||
h.encoder.NoContent(w)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue