fix: store filter actions (#54)

This commit is contained in:
Ludvig Lundgren 2021-12-27 15:14:39 +01:00 committed by GitHub
parent e496027798
commit e1ef47e09a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 213 additions and 73 deletions

View file

@ -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 {