Add in progress
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"downloader/internal/core/ports/download_request"
|
||||
"errors"
|
||||
"go.uber.org/zap"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type inMemoryRepository struct {
|
||||
@@ -54,3 +55,24 @@ func (i *inMemoryRepository) GetById(id string) (*entities.Download, error) {
|
||||
return nil, errors.New("download was not found in the database")
|
||||
}
|
||||
}
|
||||
|
||||
func (i *inMemoryRepository) Get(active bool) ([]*entities.Download, error) {
|
||||
var list []*entities.Download
|
||||
for _, download := range i.collection {
|
||||
if active {
|
||||
if strings.Contains(download.Status, "in-progress") {
|
||||
list = append(list, download)
|
||||
}
|
||||
} else {
|
||||
if !strings.Contains(download.Status, "in-progress") {
|
||||
list = append(list, download)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if len(list) == 0 {
|
||||
return []*entities.Download{}, nil
|
||||
}
|
||||
|
||||
return list, nil
|
||||
}
|
||||
|
@@ -6,4 +6,5 @@ type Repository interface {
|
||||
Create(download *entities.Download) (*entities.Download, error)
|
||||
GetById(id string) (*entities.Download, error)
|
||||
Update(download *entities.Download) error
|
||||
Get(active bool) ([]*entities.Download, error)
|
||||
}
|
||||
|
@@ -32,7 +32,7 @@ func NewYtDlpDownloader(logger *zap.SugaredLogger) DownloadHandler {
|
||||
|
||||
_, err = exec.Command("yt-dlp", "--version").Output()
|
||||
if err != nil {
|
||||
log.Fatal("Youtube download (youtube-dl) isn't installed on the device")
|
||||
log.Fatal("Youtube download (yt-dlp) isn't installed on the device")
|
||||
}
|
||||
|
||||
return &YtDlpDownloader{
|
||||
|
@@ -51,3 +51,7 @@ func (l *localService) Schedule(link string) (*entities.Download, error) {
|
||||
func (l *localService) Get(id string) (*entities.Download, error) {
|
||||
return l.repository.GetById(id)
|
||||
}
|
||||
|
||||
func (l *localService) GetAll(active bool) ([]*entities.Download, error) {
|
||||
return l.repository.Get(active)
|
||||
}
|
||||
|
@@ -5,4 +5,5 @@ import "downloader/internal/core/entities"
|
||||
type Service interface {
|
||||
Schedule(link string) (*entities.Download, error)
|
||||
Get(id string) (*entities.Download, error)
|
||||
GetAll(active bool) ([]*entities.Download, error)
|
||||
}
|
||||
|
Reference in New Issue
Block a user