mirror of
https://github.com/idanoo/autobrr
synced 2025-07-23 00:39:13 +00:00

* chore: tidy deps * refactor: database migration * refactor: store release * refactor: save release * chore: add packages * feat(web): show stats and recent releases * refactor: simply filter struct * feat: add eventbus * chore: cleanup logging * chore: update packages
62 lines
1.3 KiB
Go
62 lines
1.3 KiB
Go
package action
|
|
|
|
import (
|
|
"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)
|
|
Fetch() ([]domain.Action, error)
|
|
Delete(actionID int) error
|
|
ToggleEnabled(actionID int) error
|
|
|
|
RunActions(actions []domain.Action, release domain.Release) error
|
|
}
|
|
|
|
type service struct {
|
|
repo domain.ActionRepo
|
|
clientSvc download_client.Service
|
|
bus EventBus.Bus
|
|
}
|
|
|
|
func NewService(repo domain.ActionRepo, clientSvc download_client.Service, bus EventBus.Bus) Service {
|
|
return &service{repo: repo, clientSvc: clientSvc, bus: bus}
|
|
}
|
|
|
|
func (s *service) Store(action domain.Action) (*domain.Action, error) {
|
|
// validate data
|
|
|
|
a, err := s.repo.Store(action)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return a, nil
|
|
}
|
|
|
|
func (s *service) Delete(actionID int) error {
|
|
if err := s.repo.Delete(actionID); err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func (s *service) Fetch() ([]domain.Action, error) {
|
|
actions, err := s.repo.List()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return actions, nil
|
|
}
|
|
|
|
func (s *service) ToggleEnabled(actionID int) error {
|
|
if err := s.repo.ToggleEnabled(actionID); err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|