Skip to content

Commit

Permalink
chore: update artist package
Browse files Browse the repository at this point in the history
  • Loading branch information
thuongtruong109 committed Nov 19, 2024
1 parent 08ef801 commit 3c02ea7
Show file tree
Hide file tree
Showing 12 changed files with 363 additions and 366 deletions.
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@ run:
go run main.go

build:
go build ./...
go build ./...

build-app:
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o soundlib main.go
16 changes: 8 additions & 8 deletions cmd/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,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/common"
"github.com/thuongtruong109/soundlib/internal/artists"
"github.com/thuongtruong109/soundlib/internal/genres"

"github.com/thuongtruong109/soundlib/pkg/common"
"github.com/thuongtruong109/soundlib/pkg/helpers"
)

Expand All @@ -18,11 +17,11 @@ func App() {
albumUC := albums.NewAlbumUsecase()
albumHandler := albums.NewAlbumHandler(*albumUC, *helper)

// artistRepo := artists.NewArtistRepository()
// artistUC := artists.NewArtistUsecase(*artistRepo, *helper)
// artistHandler := artists.NewArtistHandler(*artistUC, *helper, *common.NewCommonHandler(*helper, "Artists"))
artistRepo := artists.NewArtistRepository()
artistUC := artists.NewArtistUsecase(*artistRepo, *helper)
artistHandler := artists.NewArtistHandler(*artistUC, *helper, *common.NewCommonHandler(*helper, "Artists"))

genreRepo := genres.NewGenreRepository(*helper)
genreRepo := genres.NewGenreRepository()
genreUC := genres.NewGenreUsecase(*genreRepo, *helper)
genreHandler := genres.NewGenreHandler(*genreUC, *helper, *common.NewCommonHandler(*helper, "Genres"))

Expand All @@ -32,7 +31,8 @@ func App() {
// trackUC := tracks.NewTrackUsecase(*tracks.NewTrackRepository(), *helper)
// trackHandler := tracks.NewTrackHandler(*trackUC, *helper, *common.NewCommonHandler(*helper, "Tracks"))

exe := NewDelivery(*albumHandler /**artistHandler,*/, *genreHandler, *playlistHandler /**trackHandler,*/, *helper)
exe := NewDelivery(*albumHandler, *artistHandler, *genreHandler, *playlistHandler, *helper)
/**trackHandler)*/

exe.Execution()
}
18 changes: 9 additions & 9 deletions cmd/delivery.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,20 @@ import (
"github.com/thuongtruong109/soundlib/pkg/helpers"

"github.com/thuongtruong109/soundlib/internal/albums"
// "github.com/thuongtruong109/soundlib/internal/artists"
"github.com/thuongtruong109/soundlib/internal/artists"
"github.com/thuongtruong109/soundlib/internal/genres"
)

type Delivery struct {
albumHandler albums.AlbumHandler
// artistHandler artists.ArtistHandler
albumHandler albums.AlbumHandler
artistHandler artists.ArtistHandler
genreHandler genres.GenreHandler
playlistHandler playlists.PlaylistHandler
// trackHandler tracks.TrackHandler
helper helpers.Helper
}

func NewDelivery(albumHandler albums.AlbumHandler /*artistHandler artists.ArtistHandler, */, genreHandler genres.GenreHandler, playlistHandler playlists.PlaylistHandler /*trackHandler tracks.TrackHandler,*/, helper helpers.Helper) *Delivery {
func NewDelivery(albumHandler albums.AlbumHandler, artistHandler artists.ArtistHandler, genreHandler genres.GenreHandler, playlistHandler playlists.PlaylistHandler /*trackHandler tracks.TrackHandler,*/, helper helpers.Helper) *Delivery {
return &Delivery{
albumHandler: albumHandler,
// artistHandler: artistHandler,
Expand All @@ -39,13 +39,13 @@ 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,
7: h.artistHandler.CreateArtist,
8: h.artistHandler.GetArtists,
9: h.artistHandler.GetArtist,
// 10: h.artistHandler.GetAlbumsOfArtist,
// 11: h.artistHandler.GetTracksOfArtist,
// 12: h.artistHandler.DeleteArtist,
// 13: h.artistHandler.UpdateArtist,
12: h.artistHandler.DeleteArtist,
13: h.artistHandler.UpdateArtist,
14: h.genreHandler.CreateGenre,
15: h.genreHandler.GetGenres,
16: h.genreHandler.GetGenre,
Expand Down
98 changes: 49 additions & 49 deletions internal/artists/handler.go
Original file line number Diff line number Diff line change
@@ -1,51 +1,51 @@
package artists

// import (
// "github.com/thuongtruong109/soundlib/internal/common"
// "github.com/thuongtruong109/soundlib/pkg/constants"
// "github.com/thuongtruong109/soundlib/pkg/helpers"
// )

// type ArtistHandler struct {
// uc ArtistUsecase
// helper helpers.Helper
// ch common.CommonHandler
// }

// func NewArtistHandler(uc ArtistUsecase, helper helpers.Helper, ch common.CommonHandler) *ArtistHandler {
// return &ArtistHandler{
// uc: uc,
// helper: helper,
// ch: ch,
// }
// }

// func (u *ArtistHandler) GetArtists() {
// result, err := u.uc.GetArtists()
// u.ch.ErrorWrapper(constants.GET_FAILED, err)
// u.ch.SuccessWrapper(constants.GET_SUCCESS, result)
// }

// func (u *ArtistHandler) GetArtist() {
// result, err := u.uc.GetArtist()
// u.ch.ErrorWrapper(constants.GET_FAILED, err)
// u.ch.SuccessWrapper(constants.GET_SUCCESS, result)
// }

// func (u *ArtistHandler) CreateArtist() {
// result, err := u.uc.CreateArtist()
// u.ch.ErrorWrapper(constants.CREATE_FAILED, err)
// u.ch.SuccessWrapper(constants.CREATE_SUCCESS, result)
// }

// func (u *ArtistHandler) DeleteArtist() {
// err := u.uc.DeleteArtist()
// u.ch.ErrorWrapper(constants.DELETE_FAILED, err)
// u.helper.OutputSuccess(constants.DELETE_SUCCESS)
// }

// func (u *ArtistHandler) UpdateArtist() {
// result, err := u.uc.UpdateArtist()
// u.ch.ErrorWrapper(constants.UPDATE_FAILED, err)
// u.ch.SuccessWrapper(constants.UPDATE_SUCCESS, result)
// }
import (
"github.com/thuongtruong109/soundlib/pkg/common"
"github.com/thuongtruong109/soundlib/pkg/constants"
"github.com/thuongtruong109/soundlib/pkg/helpers"
)

type ArtistHandler struct {
uc ArtistUsecase
helper helpers.Helper
ch common.CommonHandler
}

func NewArtistHandler(uc ArtistUsecase, helper helpers.Helper, ch common.CommonHandler) *ArtistHandler {
return &ArtistHandler{
uc: uc,
helper: helper,
ch: ch,
}
}

func (u *ArtistHandler) GetArtists() {
result, time, err := u.uc.GetArtists()
u.ch.ErrorWrapper(constants.GET_FAILED, err)
u.ch.SuccessDataWrapper(constants.GET_SUCCESS, result, time)
}

func (u *ArtistHandler) GetArtist() {
result, time, err := u.uc.GetArtist()
u.ch.ErrorWrapper(constants.GET_FAILED, err)
u.ch.SuccessDataWrapper(constants.GET_SUCCESS, result, time)
}

func (u *ArtistHandler) CreateArtist() {
result, time, err := u.uc.CreateArtist()
u.ch.ErrorWrapper(constants.CREATE_FAILED, err)
u.ch.SuccessDataWrapper(constants.CREATE_SUCCESS, result, time)
}

func (u *ArtistHandler) DeleteArtist() {
time, err := u.uc.DeleteArtist()
u.ch.ErrorWrapper(constants.DELETE_FAILED, err)
u.ch.SuccessNoDataWrapper(constants.DELETE_SUCCESS, time)
}

func (u *ArtistHandler) UpdateArtist() {
result, time, err := u.uc.UpdateArtist()
u.ch.ErrorWrapper(constants.UPDATE_FAILED, err)
u.ch.SuccessDataWrapper(constants.UPDATE_SUCCESS, result, time)
}
Loading

0 comments on commit 3c02ea7

Please sign in to comment.