Skip to content

Commit

Permalink
refactor: migrate return table to new function
Browse files Browse the repository at this point in the history
  • Loading branch information
thuongtruong109 committed Nov 19, 2024
1 parent 09198e0 commit 08ef801
Show file tree
Hide file tree
Showing 13 changed files with 635 additions and 670 deletions.
16 changes: 8 additions & 8 deletions cmd/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ 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/internal/albums"
"github.com/thuongtruong109/soundlib/internal/artists"
// "github.com/thuongtruong109/soundlib/internal/artists"
"github.com/thuongtruong109/soundlib/internal/common"
"github.com/thuongtruong109/soundlib/internal/genres"

Expand All @@ -18,9 +18,9 @@ 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)
genreUC := genres.NewGenreUsecase(*genreRepo, *helper)
Expand All @@ -29,10 +29,10 @@ 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"))
// 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 /**trackHandler,*/, *helper)

exe.Execution()
}
42 changes: 21 additions & 21 deletions cmd/delivery.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,32 @@ 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"

"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
// 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,
albumHandler: albumHandler,
// artistHandler: artistHandler,
genreHandler: genreHandler,
playlistHandler: playlistHandler,
trackHandler: trackHandler,
helper: helper,
// trackHandler: trackHandler,
helper: helper,
}
}

Expand All @@ -39,24 +39,24 @@ 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,
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,
Expand Down
2 changes: 1 addition & 1 deletion database/genres.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[{"id":"1687526808254750400","name":"Genre","description":"Description"},{"id":"1687526812227435700","name":"Genre","description":"Description"},{"id":"1687526815631740700","name":"Genre","description":"Description"},{"id":"1687526818712543300","name":"Genre","description":"Description"},{"id":"1687605897304680300","name":"hiih","description":"ok"},{"id":"1687606171273872000","name":"okkoko","description":"vgv"},{"id":"1687703776885603200","name":"hihi","description":"okoh"},{"id":"1687704016678422300","name":"","description":""},{"id":"1687704295465036500","name":"","description":""},{"id":"1687704371901516500","name":"","description":""},{"id":"1687704954686620900","name":"effe","description":"fe"},{"id":"1687710868792967500","name":"","description":""},{"id":"1687712036555293800","name":"drdr","description":"ferfe"}]
[{"id":"1687526808254750400","name":"Genre","description":"Description"},{"id":"1687526812227435700","name":"Genre","description":"Description"},{"id":"1687526815631740700","name":"Genre","description":"Description"},{"id":"1687526818712543300","name":"Genre","description":"Description"},{"id":"1687606171273872000","name":"okkoko","description":"vgv"},{"id":"1687703776885603200","name":"hihi","description":"okoh"},{"id":"1687704016678422300","name":"","description":""},{"id":"1687704295465036500","name":"","description":""},{"id":"1687704371901516500","name":"","description":""},{"id":"1687704954686620900","name":"effe","description":"fe"},{"id":"1687710868792967500","name":"","description":""},{"id":"1687712036555293800","name":"drdr","description":"ferfe"}]
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/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)
// }
Loading

0 comments on commit 08ef801

Please sign in to comment.