feat(quick-5): add CreatedAt/UpdatedAt to playlist Summary struct
- Add CreatedAt and UpdatedAt string fields to Summary struct - Format as RFC3339 at all construction sites in playlist.go and favorites.go - Update TypeScript bindings with new fields in models.ts
This commit is contained in:
@@ -3,6 +3,7 @@ package playlist
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"yellowjacket/backend/database/sql/sqlcgen"
|
||||
"yellowjacket/backend/events"
|
||||
@@ -82,7 +83,10 @@ func (s *Service) EnsureDefaultPlaylist() {
|
||||
)
|
||||
|
||||
s.emitEvent(events.PlaylistCreated, Summary{
|
||||
ID: created.ID, Name: created.Name,
|
||||
ID: created.ID,
|
||||
Name: created.Name,
|
||||
CreatedAt: created.CreatedAt.Format(time.RFC3339),
|
||||
UpdatedAt: created.UpdatedAt.Format(time.RFC3339),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -138,7 +142,12 @@ func (s *Service) GetDefaultPlaylistInfo() (
|
||||
)
|
||||
}
|
||||
|
||||
return Summary{ID: pl.ID, Name: pl.Name}, nil
|
||||
return Summary{
|
||||
ID: pl.ID,
|
||||
Name: pl.Name,
|
||||
CreatedAt: pl.CreatedAt.Format(time.RFC3339),
|
||||
UpdatedAt: pl.UpdatedAt.Format(time.RFC3339),
|
||||
}, nil
|
||||
}
|
||||
|
||||
// ToggleDefaultPlaylistTrack adds or removes a single track
|
||||
|
||||
@@ -12,6 +12,7 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/wailsapp/wails/v2/pkg/runtime"
|
||||
|
||||
@@ -42,8 +43,10 @@ type LibraryDirProvider interface {
|
||||
// Summary is a lightweight representation of a playlist for the
|
||||
// picker UI.
|
||||
type Summary struct {
|
||||
ID int64 `json:"ID"`
|
||||
Name string `json:"Name"`
|
||||
ID int64 `json:"ID"`
|
||||
Name string `json:"Name"`
|
||||
CreatedAt string `json:"CreatedAt"`
|
||||
UpdatedAt string `json:"UpdatedAt"`
|
||||
}
|
||||
|
||||
// Track represents a track within a playlist, including its
|
||||
@@ -160,8 +163,10 @@ func (s *Service) GetAllPlaylists() ([]Summary, error) {
|
||||
|
||||
for _, p := range playlists {
|
||||
summaries = append(summaries, Summary{
|
||||
ID: p.ID,
|
||||
Name: p.Name,
|
||||
ID: p.ID,
|
||||
Name: p.Name,
|
||||
CreatedAt: p.CreatedAt.Format(time.RFC3339),
|
||||
UpdatedAt: p.UpdatedAt.Format(time.RFC3339),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -236,8 +241,13 @@ func (s *Service) GetAllPlaylistsWithTracks() (
|
||||
)
|
||||
|
||||
result = append(result, WithTracks{
|
||||
Summary: Summary{ID: p.ID, Name: p.Name},
|
||||
Tracks: tracks,
|
||||
Summary: Summary{
|
||||
ID: p.ID,
|
||||
Name: p.Name,
|
||||
CreatedAt: p.CreatedAt.Format(time.RFC3339),
|
||||
UpdatedAt: p.UpdatedAt.Format(time.RFC3339),
|
||||
},
|
||||
Tracks: tracks,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -439,11 +449,17 @@ func (s *Service) CreatePlaylist(
|
||||
|
||||
s.savePlaylistFile(created.ID, created.Name)
|
||||
s.emitEvent(events.PlaylistCreated, Summary{
|
||||
ID: created.ID, Name: created.Name,
|
||||
ID: created.ID,
|
||||
Name: created.Name,
|
||||
CreatedAt: created.CreatedAt.Format(time.RFC3339),
|
||||
UpdatedAt: created.UpdatedAt.Format(time.RFC3339),
|
||||
})
|
||||
|
||||
return Summary{
|
||||
ID: created.ID, Name: created.Name,
|
||||
ID: created.ID,
|
||||
Name: created.Name,
|
||||
CreatedAt: created.CreatedAt.Format(time.RFC3339),
|
||||
UpdatedAt: created.UpdatedAt.Format(time.RFC3339),
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -543,7 +559,10 @@ func (s *Service) CreatePlaylistWithTracks(
|
||||
}
|
||||
|
||||
summary := Summary{
|
||||
ID: created.ID, Name: created.Name,
|
||||
ID: created.ID,
|
||||
Name: created.Name,
|
||||
CreatedAt: created.CreatedAt.Format(time.RFC3339),
|
||||
UpdatedAt: created.UpdatedAt.Format(time.RFC3339),
|
||||
}
|
||||
|
||||
s.logger.Info(
|
||||
@@ -675,7 +694,8 @@ func (s *Service) RenamePlaylist(
|
||||
)
|
||||
|
||||
s.emitEvent(events.PlaylistRenamed, Summary{
|
||||
ID: playlistID, Name: trimmed,
|
||||
ID: playlistID,
|
||||
Name: trimmed,
|
||||
})
|
||||
|
||||
return nil
|
||||
@@ -689,8 +709,10 @@ func (s *Service) uniquePlaylistName(name string) string {
|
||||
if err != nil || count == 0 {
|
||||
return name
|
||||
}
|
||||
|
||||
for i := 1; ; i++ {
|
||||
candidate := fmt.Sprintf("%s (%d)", name, i)
|
||||
|
||||
c, err := s.db.Queries.CountPlaylistsByName(s.db.Ctx, candidate)
|
||||
if err != nil || c == 0 {
|
||||
return candidate
|
||||
@@ -804,7 +826,10 @@ func (s *Service) ImportPlaylist(
|
||||
)
|
||||
|
||||
summary := Summary{
|
||||
ID: created.ID, Name: playlistName,
|
||||
ID: created.ID,
|
||||
Name: playlistName,
|
||||
CreatedAt: created.CreatedAt.Format(time.RFC3339),
|
||||
UpdatedAt: created.UpdatedAt.Format(time.RFC3339),
|
||||
}
|
||||
|
||||
s.emitEvent(events.PlaylistCreated, summary)
|
||||
|
||||
@@ -305,6 +305,8 @@ export namespace playlist {
|
||||
export class Summary {
|
||||
ID: number;
|
||||
Name: string;
|
||||
CreatedAt: string;
|
||||
UpdatedAt: string;
|
||||
|
||||
static createFrom(source: any = {}) {
|
||||
return new Summary(source);
|
||||
@@ -314,6 +316,8 @@ export namespace playlist {
|
||||
if ('string' === typeof source) source = JSON.parse(source);
|
||||
this.ID = source["ID"];
|
||||
this.Name = source["Name"];
|
||||
this.CreatedAt = source["CreatedAt"];
|
||||
this.UpdatedAt = source["UpdatedAt"];
|
||||
}
|
||||
}
|
||||
export class Track {
|
||||
|
||||
Reference in New Issue
Block a user