mirror of
https://github.com/idanoo/autobrr
synced 2025-07-23 00:39:13 +00:00
feat(filters): support partial update (#409)
This commit is contained in:
parent
fa20978d58
commit
3a334121f7
4 changed files with 349 additions and 8 deletions
|
@ -27,6 +27,7 @@ type Service interface {
|
|||
ListFilters(ctx context.Context) ([]domain.Filter, error)
|
||||
Store(ctx context.Context, filter domain.Filter) (*domain.Filter, error)
|
||||
Update(ctx context.Context, filter domain.Filter) (*domain.Filter, error)
|
||||
UpdatePartial(ctx context.Context, filter domain.FilterUpdate) error
|
||||
Duplicate(ctx context.Context, filterID int) (*domain.Filter, error)
|
||||
ToggleEnabled(ctx context.Context, filterID int, enabled bool) error
|
||||
Delete(ctx context.Context, filterID int) error
|
||||
|
@ -153,6 +154,33 @@ func (s *service) Update(ctx context.Context, filter domain.Filter) (*domain.Fil
|
|||
return f, nil
|
||||
}
|
||||
|
||||
func (s *service) UpdatePartial(ctx context.Context, filter domain.FilterUpdate) error {
|
||||
|
||||
// update
|
||||
if err := s.repo.UpdatePartial(ctx, filter); err != nil {
|
||||
s.log.Error().Err(err).Msgf("could not update partial filter: %v", filter.ID)
|
||||
return err
|
||||
}
|
||||
|
||||
if filter.Indexers != nil {
|
||||
// take care of connected indexers
|
||||
if err := s.repo.StoreIndexerConnections(ctx, filter.ID, filter.Indexers); err != nil {
|
||||
s.log.Error().Err(err).Msgf("could not store filter indexer connections: %v", filter.Name)
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if filter.Actions != nil {
|
||||
// take care of filter actions
|
||||
if _, err := s.actionRepo.StoreFilterActions(ctx, filter.Actions, int64(filter.ID)); err != nil {
|
||||
s.log.Error().Err(err).Msgf("could not store filter actions: %v", filter.ID)
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *service) Duplicate(ctx context.Context, filterID int) (*domain.Filter, error) {
|
||||
// find filter
|
||||
baseFilter, err := s.repo.FindByID(ctx, filterID)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue