settings.go
| 1 | package service |
| 2 | |
| 3 | import ( |
| 4 | "vidarchive/internal/models" |
| 5 | "vidarchive/internal/repository" |
| 6 | ) |
| 7 | |
| 8 | type SettingsService struct { |
| 9 | repo *repository.SettingsRepository |
| 10 | } |
| 11 | |
| 12 | func NewSettingsService(repo *repository.SettingsRepository) *SettingsService { |
| 13 | return &SettingsService{repo: repo} |
| 14 | } |
| 15 | |
| 16 | func (s *SettingsService) GetAll() (*models.Settings, error) { |
| 17 | return s.repo.GetAll() |
| 18 | } |
| 19 | |
| 20 | func (s *SettingsService) SetRefreshInterval(interval string) error { |
| 21 | return s.repo.Set("refresh_interval", interval) |
| 22 | } |
| 23 | |
| 24 | func (s *SettingsService) SetAutoRefreshLibrary(enabled bool) error { |
| 25 | val := "0" |
| 26 | if enabled { |
| 27 | val = "1" |
| 28 | } |
| 29 | return s.repo.Set("auto_refresh_library", val) |
| 30 | } |
| 31 | |
| 32 | func (s *SettingsService) SetAutoRefreshDownloads(enabled bool) error { |
| 33 | val := "0" |
| 34 | if enabled { |
| 35 | val = "1" |
| 36 | } |
| 37 | return s.repo.Set("auto_refresh_downloads", val) |
| 38 | } |
| 39 | |
| 40 | func (s *SettingsService) SetCookies(cookies string) error { |
| 41 | return s.repo.Set("cookies", cookies) |
| 42 | } |
| 43 | |
| 44 | func (s *SettingsService) GetCookies() (string, error) { |
| 45 | return s.repo.Get("cookies") |
| 46 | } |
| 47 |