54 lines
884 B
Go
Raw Normal View History

2024-02-17 22:57:47 -08:00
package commands
import (
"context"
2024-02-18 09:58:47 -08:00
"log/slog"
"os"
2024-02-17 22:57:47 -08:00
"github.com/zmb3/spotify/v2"
"go.uber.org/fx"
2024-02-18 11:48:33 -08:00
2024-02-18 18:51:25 -08:00
"git.asdf.cafe/abs3nt/gspot/src/components/cache"
2024-02-17 22:57:47 -08:00
)
type CommanderResult struct {
fx.Out
Commander *Commander
}
type CommanderParams struct {
fx.In
Context context.Context
Client *spotify.Client
2024-02-18 11:34:08 -08:00
Log *slog.Logger
2024-02-18 11:48:33 -08:00
Cache *cache.Cache
2024-02-17 22:57:47 -08:00
}
type Commander struct {
Context context.Context
Client *spotify.Client
2024-02-18 09:58:47 -08:00
User *spotify.PrivateUser
2024-02-18 11:34:08 -08:00
Log *slog.Logger
2024-02-18 11:48:33 -08:00
Cache *cache.Cache
2024-02-17 22:57:47 -08:00
}
func NewCommander(p CommanderParams) CommanderResult {
2024-02-18 09:58:47 -08:00
currentUser, err := p.Client.CurrentUser(p.Context)
if err != nil {
slog.Error("COMMANDER", "error getting current user", err)
os.Exit(1)
}
2024-02-17 22:57:47 -08:00
c := &Commander{
Context: p.Context,
Client: p.Client,
2024-02-18 09:58:47 -08:00
User: currentUser,
2024-02-18 11:34:08 -08:00
Log: p.Log,
2024-02-18 11:48:33 -08:00
Cache: p.Cache,
2024-02-17 22:57:47 -08:00
}
return CommanderResult{
Commander: c,
}
}