diff --git a/cmd/app.go b/cmd/app.go index 60c6aae..4e79e07 100644 --- a/cmd/app.go +++ b/cmd/app.go @@ -1,11 +1,11 @@ package cmd import ( - "github.com/thuongtruong109/soundlib/internal/playlists" - // "github.com/thuongtruong109/soundlib/internal/tracks" "github.com/thuongtruong109/soundlib/internal/albums" "github.com/thuongtruong109/soundlib/internal/artists" "github.com/thuongtruong109/soundlib/internal/genres" + "github.com/thuongtruong109/soundlib/internal/playlists" + "github.com/thuongtruong109/soundlib/internal/tracks" "github.com/thuongtruong109/soundlib/pkg/common" "github.com/thuongtruong109/soundlib/pkg/helpers" @@ -28,10 +28,11 @@ func App() { playlistUC := playlists.NewPlaylistUsecase() playlistHandler := playlists.NewPlaylistHandler(*playlistUC, *helper) - // trackUC := tracks.NewTrackUsecase(*tracks.NewTrackRepository(), *helper) - // trackHandler := tracks.NewTrackHandler(*trackUC, *helper, *common.NewCommonHandler(*helper, "Tracks")) + trackRepo := tracks.NewTrackRepository() + trackUC := tracks.NewTrackUsecase(*trackRepo, *helper) + trackHandler := tracks.NewTrackHandler(*trackUC, *helper, *common.NewCommonHandler(*helper, "Tracks")) - exe := NewDelivery(*albumHandler, *artistHandler, *genreHandler, *playlistHandler, *helper) + exe := NewDelivery(*helper, *albumHandler, *artistHandler, *genreHandler, *playlistHandler, *trackHandler) /**trackHandler)*/ exe.Execution() diff --git a/cmd/delivery.go b/cmd/delivery.go index 3aafe18..0158793 100644 --- a/cmd/delivery.go +++ b/cmd/delivery.go @@ -2,7 +2,7 @@ package cmd import ( "github.com/thuongtruong109/soundlib/internal/playlists" - // "github.com/thuongtruong109/soundlib/internal/tracks" + "github.com/thuongtruong109/soundlib/internal/tracks" "github.com/thuongtruong109/soundlib/pkg/constants" "github.com/thuongtruong109/soundlib/pkg/helpers" @@ -12,22 +12,22 @@ import ( ) type Delivery struct { + helper helpers.Helper albumHandler albums.AlbumHandler artistHandler artists.ArtistHandler genreHandler genres.GenreHandler playlistHandler playlists.PlaylistHandler - // trackHandler tracks.TrackHandler - helper helpers.Helper + trackHandler tracks.TrackHandler } -func NewDelivery(albumHandler albums.AlbumHandler, artistHandler artists.ArtistHandler, genreHandler genres.GenreHandler, playlistHandler playlists.PlaylistHandler /*trackHandler tracks.TrackHandler,*/, helper helpers.Helper) *Delivery { +func NewDelivery(helper helpers.Helper, albumHandler albums.AlbumHandler, artistHandler artists.ArtistHandler, genreHandler genres.GenreHandler, playlistHandler playlists.PlaylistHandler, trackHandler tracks.TrackHandler) *Delivery { return &Delivery{ + helper: helper, albumHandler: albumHandler, - // artistHandler: artistHandler, + artistHandler: artistHandler, genreHandler: genreHandler, playlistHandler: playlistHandler, - // trackHandler: trackHandler, - helper: helper, + trackHandler: trackHandler, } } @@ -39,6 +39,7 @@ func (h *Delivery) HandleOption(option int8) { 4: h.albumHandler.DeleteAlbum, 5: h.albumHandler.UpdateAlbum, 6: h.albumHandler.GetTracksOfAlbum, + 7: h.artistHandler.CreateArtist, 8: h.artistHandler.GetArtists, 9: h.artistHandler.GetArtist, @@ -46,17 +47,20 @@ func (h *Delivery) HandleOption(option int8) { // 11: h.artistHandler.GetTracksOfArtist, 12: h.artistHandler.DeleteArtist, 13: h.artistHandler.UpdateArtist, + 14: h.genreHandler.CreateGenre, 15: h.genreHandler.GetGenres, 16: h.genreHandler.GetGenre, 17: h.genreHandler.DeleteGenre, 18: h.genreHandler.UpdateGenre, + // 19: h.genreHandler.GetTracksOfGenre, - // 20: h.trackHandler.CreateTrack, - // 21: h.trackHandler.GetTracks, - // 22: h.trackHandler.GetTrack, - // 23: h.trackHandler.DeleteTrack, - // 24: h.trackHandler.UpdateTrack, + 20: h.trackHandler.CreateTrack, + 21: h.trackHandler.GetTracks, + 22: h.trackHandler.GetTrack, + 23: h.trackHandler.DeleteTrack, + 24: h.trackHandler.UpdateTrack, + 25: h.playlistHandler.CreatePlaylist, 26: h.playlistHandler.GetPlaylists, 27: h.playlistHandler.GetPlaylist, diff --git a/cmd/execution.go b/cmd/execution.go index c7f9742..ba1bf82 100644 --- a/cmd/execution.go +++ b/cmd/execution.go @@ -2,9 +2,10 @@ package cmd import ( "fmt" - "github.com/thuongtruong109/soundlib/pkg/constants" + gu_console "github.com/thuongtruong109/gouse/console" gu_shared "github.com/thuongtruong109/gouse/shared" + "github.com/thuongtruong109/soundlib/pkg/constants" ) func (d *Delivery) Execution() { @@ -29,4 +30,4 @@ func (d *Delivery) Execution() { break } } -} \ No newline at end of file +} diff --git a/database/artists.json b/database/artists.json index d49acc9..8dcbb22 100644 --- a/database/artists.json +++ b/database/artists.json @@ -1 +1 @@ -[{"id":"1731822899559367500","username":"w","full_name":"w","bio":"ew","avatar_url":"eqeqw","debut_at":"2024-11-17T12:54:59.559Z"}] \ No newline at end of file +[{"id":"1731822899559367500","username":"w","full_name":"w","bio":"ew","avatar_url":"eqeqw","debut_at":"2024-11-17T12:54:59.559Z"},{"id":"1734055056352055600","username":"jiefr","full_name":"jgotege","bio":"jgegege","avatar_url":"eg9giegher","debut_at":"2024-12-13T08:57:36.352Z"}] \ No newline at end of file diff --git a/database/tracks.json b/database/tracks.json new file mode 100644 index 0000000..df4fe7f --- /dev/null +++ b/database/tracks.json @@ -0,0 +1 @@ +[{"id":"1734056816899324200","name":"title","play_count":999,"duration":12,"file_url":"http","created_at":"2024-12-13T09:26:56.899Z","genre_id":"id","artist_id":"aid"}] \ No newline at end of file diff --git a/go.mod b/go.mod index a0c9140..a8beb00 100644 --- a/go.mod +++ b/go.mod @@ -1,11 +1,11 @@ module github.com/thuongtruong109/soundlib -go 1.20 +go 1.23 require ( github.com/AlecAivazis/survey/v2 v2.3.7 github.com/jedib0t/go-pretty/v6 v6.4.6 - github.com/thuongtruong109/gouse v0.0.0-20240709131131-080109e15476 + github.com/thuongtruong109/gouse v0.1.0 golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1 ) @@ -16,8 +16,8 @@ require ( github.com/mattn/go-isatty v0.0.19 // indirect github.com/mattn/go-runewidth v0.0.15 // indirect github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b // indirect - github.com/rivo/uniseg v0.2.0 // indirect + github.com/rivo/uniseg v0.4.4 // indirect golang.org/x/sys v0.20.0 // indirect golang.org/x/term v0.15.0 // indirect - golang.org/x/text v0.14.0 // indirect + golang.org/x/text v0.16.0 // indirect ) diff --git a/go.sum b/go.sum index 136d007..cdabc3b 100644 --- a/go.sum +++ b/go.sum @@ -28,16 +28,18 @@ github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b/go.mod h1:01TrycV0kFyex github.com/pkg/profile v1.6.0/go.mod h1:qBsxPvzyUincmltOk6iyRVxHYg4adc0OFOv72ZdLa18= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY= github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= +github.com/rivo/uniseg v0.4.4 h1:8TfxU8dW6PdqD27gjM8MVNuicgxIjxpm4K7x4jp8sis= +github.com/rivo/uniseg v0.4.4/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.4/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= -github.com/thuongtruong109/gouse v0.0.0-20240709131131-080109e15476 h1:vBCVnxAOczzqBUobXn5kVmOk3+MCpVL02ntP3QlqLE8= -github.com/thuongtruong109/gouse v0.0.0-20240709131131-080109e15476/go.mod h1:79vQ38zBdDAynxA/cjdqLzqsx53PmZA1rXcw5Hy4zYw= +github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +github.com/thuongtruong109/gouse v0.1.0 h1:Wxk+zmXceL1f7NeqMdUmdl6hhVQtWzW/Dx8j+itHcoI= +github.com/thuongtruong109/gouse v0.1.0/go.mod h1:HsqBRrlT3r5S+/XtXycoOki/mj4NwYWRhYnSngx2WdU= github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= @@ -67,8 +69,8 @@ golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= -golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= -golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= +golang.org/x/text v0.16.0 h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4= +golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= diff --git a/internal/tracks/handler.go b/internal/tracks/handler.go index 898f987..c19adb2 100644 --- a/internal/tracks/handler.go +++ b/internal/tracks/handler.go @@ -1,54 +1,54 @@ package tracks -// import ( -// "github.com/thuongtruong109/soundlib/pkg/helpers" -// "github.com/thuongtruong109/soundlib/pkg/constants" -// "github.com/thuongtruong109/soundlib/internal/common" -// ) - -// type TrackHandler struct { -// uc TrackUsecase -// helper helpers.Helper -// ch common.CommonHandler -// } - -// func NewTrackHandler(uc TrackUsecase, helper helpers.Helper, ch common.CommonHandler) *TrackHandler { -// return &TrackHandler{ -// uc: uc, -// helper: helper, -// ch: ch, -// } -// } - -// func (u *TrackHandler) GetTracks() { -// result, err := u.uc.GetTracks() -// u.ch.ErrorWrapper(constants.GET_FAILED, err) -// u.ch.SuccessDataWrapper(constants.GET_SUCCESS, result) -// } - -// func (u *TrackHandler) GetTrack() { -// result, err := u.uc.GetTrack() -// u.ch.ErrorWrapper(constants.GET_FAILED, err) -// u.ch.SuccessDataWrapper(constants.GET_SUCCESS, result) -// } - -// func (u *TrackHandler) CreateTrack() { -// result, err := u.uc.CreateTrack() -// u.ch.ErrorWrapper(constants.CREATE_FAILED, err) -// u.ch.SuccessDataWrapper(constants.CREATE_SUCCESS, result) -// } - -// func (u *TrackHandler) DeleteTrack() { -// err := u.uc.DeleteTrack() -// u.ch.ErrorWrapper(constants.DELETE_FAILED, err) -// u.helper.OutputSuccess(constants.DELETE_SUCCESS) -// } - -// func (u *TrackHandler) UpdateTrack() { -// result, err := u.uc.UpdateTrack() -// u.ch.ErrorWrapper(constants.UPDATE_FAILED, err) -// u.ch.SuccessDataWrapper(constants.UPDATE_SUCCESS, result) -// } +import ( + "github.com/thuongtruong109/soundlib/pkg/common" + "github.com/thuongtruong109/soundlib/pkg/constants" + "github.com/thuongtruong109/soundlib/pkg/helpers" +) + +type TrackHandler struct { + uc TrackUsecase + helper helpers.Helper + ch common.CommonHandler +} + +func NewTrackHandler(uc TrackUsecase, helper helpers.Helper, ch common.CommonHandler) *TrackHandler { + return &TrackHandler{ + uc: uc, + helper: helper, + ch: ch, + } +} + +func (u *TrackHandler) GetTracks() { + result, time, err := u.uc.GetTracks() + u.ch.ErrorWrapper(constants.GET_FAILED, err) + u.ch.SuccessDataWrapper(constants.GET_SUCCESS, result, time) +} + +func (u *TrackHandler) GetTrack() { + result, time, err := u.uc.GetTrack() + u.ch.ErrorWrapper(constants.GET_FAILED, err) + u.ch.SuccessDataWrapper(constants.GET_SUCCESS, result, time) +} + +func (u *TrackHandler) CreateTrack() { + result, time, err := u.uc.CreateTrack() + u.ch.ErrorWrapper(constants.CREATE_FAILED, err) + u.ch.SuccessDataWrapper(constants.CREATE_SUCCESS, result, time) +} + +func (u *TrackHandler) DeleteTrack() { + time, err := u.uc.DeleteTrack() + u.ch.ErrorWrapper(constants.DELETE_FAILED, err) + u.ch.SuccessNoDataWrapper(constants.DELETE_SUCCESS, time) +} + +func (u *TrackHandler) UpdateTrack() { + result, time, err := u.uc.UpdateTrack() + u.ch.ErrorWrapper(constants.UPDATE_FAILED, err) + u.ch.SuccessDataWrapper(constants.UPDATE_SUCCESS, result, time) +} // func (u *TrackHandler) GetAlbumsOfTrack() { // u.helper.OutputSuccess("GetAlbumsOfTrack") diff --git a/internal/tracks/repository.go b/internal/tracks/repository.go index d1922b0..851ceab 100644 --- a/internal/tracks/repository.go +++ b/internal/tracks/repository.go @@ -57,6 +57,11 @@ func (tr *TrackRepository) CreateTrack(newTrack *Track) (*Track, error) { trackInit = append(trackInit, newTrack) + err := io.WriteFileObj(constants.TRACK_PATH, trackInit) + if err != nil { + return nil, err + } + return newTrack, nil } diff --git a/internal/tracks/usecase.go b/internal/tracks/usecase.go index a8935f8..411e3dd 100644 --- a/internal/tracks/usecase.go +++ b/internal/tracks/usecase.go @@ -1,173 +1,173 @@ package tracks -// import ( -// "fmt" - -// gu_date "github.com/thuongtruong109/gouse/date" -// gu_helper "github.com/thuongtruong109/gouse/helper" -// "github.com/thuongtruong109/soundlib/pkg/constants" -// "github.com/thuongtruong109/soundlib/pkg/helpers" -// ) - -// type TrackUsecase struct { -// repo TrackRepository -// helper helpers.Helper -// } - -// func NewTrackUsecase(repo TrackRepository, helper helpers.Helper) *TrackUsecase { -// return &TrackUsecase{ -// repo: repo, -// helper: helper, -// } -// } - -// func (a *TrackUsecase) GetTracks() ([]string, error) { -// result, err := helpers.QueryTimeTwoOutput[[]*Track](a.repo.GetTracks)() -// if err != nil { -// return nil, err -// } - -// if result == nil { -// return nil, fmt.Errorf(constants.NOT_FOUND_DATA) -// } - -// var output []string -// for _, v := range result { -// output = append(output, fmt.Sprintf("ID: %s, Name: %s, Play Count: %d, Duration: %f, File URL: %s, Created At: %s", v.ID, v.Name, v.PlayCount, v.Duration, v.FileUrl, v.CreatedAt)) -// } - -// return output, nil -// } - -// func (a *TrackUsecase) GetTrack() ([]string, error) { -// var id string -// fmt.Print("» Enter ID: ") -// fmt.Scanln(&id) - -// result, err := helpers.QueryTimeTwoOutputWithParams[*Track, string](a.repo.GetTrackById)(id) -// if err != nil { -// return nil, err -// } - -// if result == nil { -// return nil, fmt.Errorf(constants.NOT_FOUND_DATA) -// } - -// output := []string{fmt.Sprintf("ID: %s, Name: %s, Play Count: %d, Duration: %f, File URL: %s, Created At: %s", result.ID, result.Name, result.PlayCount, result.Duration, result.FileUrl, result.CreatedAt)} - -// return output, nil -// } - -// func (a *TrackUsecase) CreateTrack() ([]string, error) { -// var name, genreID, artistID, fileURL string -// fmt.Print("» Enter track title: ") -// fmt.Scanln(&name) - -// fmt.Print("» Enter genre ID: ") -// fmt.Scanln(&genreID) - -// fmt.Print("» Enter artist ID: ") -// fmt.Scanln(&artistID) - -// fmt.Print("» Enter file URL: ") -// fmt.Scanln(&fileURL) - -// var duration float32 -// fmt.Print("» Enter duration: ") -// fmt.Scanln(&duration) - -// var playCount int -// fmt.Print("» Enter play count: ") -// fmt.Scanln(&playCount) - -// newTrack := &Track{ -// ID: gu_helper.RandomID(), -// Name: name, -// GenreID: genreID, -// ArtistID: artistID, -// FileUrl: fileURL, -// Duration: duration, -// PlayCount: playCount, -// CreatedAt: gu_date.ISO(), -// } - -// result, err := helpers.QueryTimeTwoOutputWithParams[*Track, *Track](a.repo.CreateTrack)(newTrack) -// if err != nil { -// return nil, err -// } - -// if result == nil { -// return nil, fmt.Errorf(constants.NOT_FOUND_DATA) -// } - -// output := []string{fmt.Sprintf("ID: %s", result.ID)} - -// return output, nil -// } - -// func (a *TrackUsecase) DeleteTrack() error { -// var id string -// fmt.Print("» Enter ID: ") -// fmt.Scanln(&id) - -// err := helpers.QueryTimeOneOutputWithParams[error](a.repo.DeleteTrack)(id) -// if err != nil { -// return err -// } - -// return nil -// } - -// func (a *TrackUsecase) UpdateTrack() ([]string, error) { -// var id string -// fmt.Print("» Enter ID: ") -// fmt.Scanln(&id) - -// var name, genreID, artistID, fileURL string -// fmt.Print("» Enter track name: ") -// fmt.Scanln(&name) - -// fmt.Print("» Enter genre ID: ") -// fmt.Scanln(&genreID) - -// fmt.Print("» Enter artist ID: ") -// fmt.Scanln(&artistID) - -// fmt.Print("» Enter file URL: ") -// fmt.Scanln(&fileURL) - -// var duration float32 -// fmt.Print("» Enter duration: ") -// fmt.Scanln(&duration) - -// var playCount int -// fmt.Print("» Enter play count: ") -// fmt.Scanln(&playCount) - -// newTrack := &Track{ -// ID: id, -// Name: name, -// GenreID: genreID, -// ArtistID: artistID, -// FileUrl: fileURL, -// Duration: duration, -// PlayCount: playCount, -// CreatedAt: gu_date.ISO(), -// } - -// result, err := helpers.QueryTimeTwoOutputWithParams[*Track, *Track](a.repo.UpdateTrack)(newTrack) -// if err != nil { -// return nil, err -// } - -// if result == nil { -// return nil, fmt.Errorf(constants.NOT_FOUND_DATA) -// } - -// output := []string{fmt.Sprintf("ID: %s", result.ID)} - -// return output, nil -// } +import ( + "fmt" + + gu_date "github.com/thuongtruong109/gouse/date" + gu_helper "github.com/thuongtruong109/gouse/helper" + "github.com/thuongtruong109/soundlib/pkg/constants" + "github.com/thuongtruong109/soundlib/pkg/helpers" +) + +type TrackUsecase struct { + repo TrackRepository + helper helpers.Helper +} + +func NewTrackUsecase(repo TrackRepository, helper helpers.Helper) *TrackUsecase { + return &TrackUsecase{ + repo: repo, + helper: helper, + } +} + +func (a *TrackUsecase) GetTracks() ([]string, string, error) { + result, time, err := helpers.QueryTimeTwoOutput[[]*Track](a.repo.GetTracks)() + if err != nil { + return nil, time, err + } + + if result == nil { + return nil, "", fmt.Errorf(constants.NOT_FOUND_DATA) + } + + var output []string + for _, v := range result { + output = append(output, fmt.Sprintf("ID: %s, Name: %s, Play Count: %d, Duration: %f, File URL: %s, Created At: %s", v.ID, v.Name, v.PlayCount, v.Duration, v.FileUrl, v.CreatedAt)) + } + + return output, time, nil +} + +func (a *TrackUsecase) GetTrack() ([]string, string, error) { + var id string + fmt.Print("» Enter ID: ") + fmt.Scanln(&id) + + result, time, err := helpers.QueryTimeTwoOutputWithParams[*Track, string](a.repo.GetTrackById)(id) + if err != nil { + return nil, time, err + } + + if result == nil { + return nil, time, fmt.Errorf(constants.NOT_FOUND_DATA) + } + + output := []string{fmt.Sprintf("ID: %s, Name: %s, Play Count: %d, Duration: %f, File URL: %s, Created At: %s", result.ID, result.Name, result.PlayCount, result.Duration, result.FileUrl, result.CreatedAt)} + + return output, time, nil +} + +func (a *TrackUsecase) CreateTrack() ([]string, string, error) { + var name, genreID, artistID, fileURL string + fmt.Print("» Enter track title: ") + fmt.Scanln(&name) + + fmt.Print("» Enter genre ID: ") + fmt.Scanln(&genreID) + + fmt.Print("» Enter artist ID: ") + fmt.Scanln(&artistID) + + fmt.Print("» Enter file URL: ") + fmt.Scanln(&fileURL) + + var duration float32 + fmt.Print("» Enter duration: ") + fmt.Scanln(&duration) + + var playCount int + fmt.Print("» Enter play count: ") + fmt.Scanln(&playCount) + + newTrack := &Track{ + ID: gu_helper.RandomID(), + Name: name, + GenreID: genreID, + ArtistID: artistID, + FileUrl: fileURL, + Duration: duration, + PlayCount: playCount, + CreatedAt: gu_date.ISO(), + } + + result, time, err := helpers.QueryTimeTwoOutputWithParams[*Track, *Track](a.repo.CreateTrack)(newTrack) + if err != nil { + return nil, time, err + } + + if result == nil { + return nil, time, fmt.Errorf(constants.NOT_FOUND_DATA) + } + + output := []string{fmt.Sprintf("ID: %s", result.ID)} + + return output, time, nil +} + +func (a *TrackUsecase) DeleteTrack() (string, error) { + var id string + fmt.Print("» Enter ID: ") + fmt.Scanln(&id) + + time, err := helpers.QueryTimeErrorWithParams[error](a.repo.DeleteTrack)(id) + if err != nil { + return "", err + } + + return time, nil +} + +func (a *TrackUsecase) UpdateTrack() ([]string, string, error) { + var id string + fmt.Print("» Enter ID: ") + fmt.Scanln(&id) + + var name, genreID, artistID, fileURL string + fmt.Print("» Enter track name: ") + fmt.Scanln(&name) + + fmt.Print("» Enter genre ID: ") + fmt.Scanln(&genreID) + + fmt.Print("» Enter artist ID: ") + fmt.Scanln(&artistID) + + fmt.Print("» Enter file URL: ") + fmt.Scanln(&fileURL) + + var duration float32 + fmt.Print("» Enter duration: ") + fmt.Scanln(&duration) + + var playCount int + fmt.Print("» Enter play count: ") + fmt.Scanln(&playCount) + + newTrack := &Track{ + ID: id, + Name: name, + GenreID: genreID, + ArtistID: artistID, + FileUrl: fileURL, + Duration: duration, + PlayCount: playCount, + CreatedAt: gu_date.ISO(), + } + + result, time, err := helpers.QueryTimeTwoOutputWithParams[*Track, *Track](a.repo.UpdateTrack)(newTrack) + if err != nil { + return nil, time, err + } + + if result == nil { + return nil, time, fmt.Errorf(constants.NOT_FOUND_DATA) + } + + output := []string{fmt.Sprintf("ID: %s", result.ID)} + + return output, time, nil +} // func (a *TrackUsecase) GetTracksOfGenre() string { // return "Tracks of Genre"