mirror of
https://github.com/idanoo/autobrr
synced 2025-07-23 16:59:12 +00:00
fix: store filter actions (#54)
This commit is contained in:
parent
e496027798
commit
e1ef47e09a
10 changed files with 213 additions and 73 deletions
|
@ -1,15 +1,19 @@
|
|||
package action
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/asaskevich/EventBus"
|
||||
|
||||
"github.com/autobrr/autobrr/internal/domain"
|
||||
"github.com/autobrr/autobrr/internal/download_client"
|
||||
)
|
||||
|
||||
type Service interface {
|
||||
Store(action domain.Action) (*domain.Action, error)
|
||||
Store(ctx context.Context, action domain.Action) (*domain.Action, error)
|
||||
Fetch() ([]domain.Action, error)
|
||||
Delete(actionID int) error
|
||||
DeleteByFilterID(ctx context.Context, filterID int) error
|
||||
ToggleEnabled(actionID int) error
|
||||
|
||||
RunActions(actions []domain.Action, release domain.Release) error
|
||||
|
@ -25,10 +29,10 @@ func NewService(repo domain.ActionRepo, clientSvc download_client.Service, bus E
|
|||
return &service{repo: repo, clientSvc: clientSvc, bus: bus}
|
||||
}
|
||||
|
||||
func (s *service) Store(action domain.Action) (*domain.Action, error) {
|
||||
func (s *service) Store(ctx context.Context, action domain.Action) (*domain.Action, error) {
|
||||
// validate data
|
||||
|
||||
a, err := s.repo.Store(action)
|
||||
a, err := s.repo.Store(ctx, action)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -44,6 +48,14 @@ func (s *service) Delete(actionID int) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (s *service) DeleteByFilterID(ctx context.Context, filterID int) error {
|
||||
if err := s.repo.DeleteByFilterID(ctx, filterID); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *service) Fetch() ([]domain.Action, error) {
|
||||
actions, err := s.repo.List()
|
||||
if err != nil {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue