mirror of
https://git.sr.ht/~phw/scotty
synced 2025-04-28 06:57:56 +02:00
Move models to separate package
This allows easier reuse and better separation of code without introducing circular dependencies
This commit is contained in:
parent
cdddf89a3e
commit
9d97e324aa
8 changed files with 43 additions and 37 deletions
|
@ -28,6 +28,7 @@ import (
|
|||
|
||||
"github.com/spf13/viper"
|
||||
"go.uploadedlobster.com/scotty/backends/maloja"
|
||||
"go.uploadedlobster.com/scotty/models"
|
||||
)
|
||||
|
||||
type MalojaApiBackend struct {
|
||||
|
@ -42,11 +43,11 @@ func (b MalojaApiBackend) FromConfig(config *viper.Viper) Backend {
|
|||
return b
|
||||
}
|
||||
|
||||
func (b MalojaApiBackend) ExportListens(oldestTimestamp time.Time) ([]Listen, error) {
|
||||
func (b MalojaApiBackend) ExportListens(oldestTimestamp time.Time) ([]models.Listen, error) {
|
||||
page := 0
|
||||
perPage := 1000
|
||||
|
||||
listens := make([]Listen, 0)
|
||||
listens := make([]models.Listen, 0)
|
||||
|
||||
out:
|
||||
for {
|
||||
|
@ -62,7 +63,7 @@ out:
|
|||
|
||||
for _, listen := range result.Listens {
|
||||
if listen.ListenedAt > oldestTimestamp.Unix() {
|
||||
listens = append(listens, Listen{}.FromMaloja(listen))
|
||||
listens = append(listens, ListenFromMaloja(listen))
|
||||
} else {
|
||||
break out
|
||||
}
|
||||
|
@ -75,12 +76,12 @@ out:
|
|||
return listens, nil
|
||||
}
|
||||
|
||||
func (l Listen) FromMaloja(mlListen maloja.Listen) Listen {
|
||||
func ListenFromMaloja(mlListen maloja.Listen) models.Listen {
|
||||
track := mlListen.Track
|
||||
listen := Listen{
|
||||
listen := models.Listen{
|
||||
ListenedAt: time.Unix(mlListen.ListenedAt, 0),
|
||||
PlaybackDuration: time.Duration(mlListen.Duration * int64(time.Second)),
|
||||
Track: Track{
|
||||
Track: models.Track{
|
||||
TrackName: track.Title,
|
||||
ReleaseName: track.Album.Title,
|
||||
ArtistNames: track.Artists,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue