-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
167 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package spotlike | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/zmb3/spotify/v2" | ||
) | ||
|
||
// checkLikeUseCase is a struct that contains the use case of checking for an artist. | ||
type CheckLikeUseCase struct { | ||
Client *spotify.Client | ||
} | ||
|
||
// NewCheckLikeUseCase returns a new instance of the checkLikeUseCase struct. | ||
func NewCheckLikeUseCase(client *spotify.Client) *CheckLikeUseCase { | ||
return &CheckLikeUseCase{ | ||
Client: client, | ||
} | ||
} | ||
|
||
// Run returns the check result of the artist. | ||
func (uc *CheckLikeUseCase) Run(id string, contentType SpotifyContentType) (bool, error) { | ||
var alreadyLiked bool | ||
switch contentType { | ||
case Artist: | ||
result, err := uc.Client.CurrentUserFollows(context.Background(), "artist", spotify.ID(id)) | ||
if err != nil { | ||
return false, err | ||
} | ||
alreadyLiked = result[0] | ||
case Album: | ||
result, err := uc.Client.UserHasAlbums(context.Background(), spotify.ID(id)) | ||
if err != nil { | ||
return false, err | ||
} | ||
alreadyLiked = result[0] | ||
case Track: | ||
result, err := uc.Client.UserHasTracks(context.Background(), spotify.ID(id)) | ||
if err != nil { | ||
return false, err | ||
} | ||
alreadyLiked = result[0] | ||
} | ||
|
||
return alreadyLiked, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package spotlike | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/zmb3/spotify/v2" | ||
) | ||
|
||
// likeArtistUseCase is a struct that contains the use case of likeing for an artist. | ||
type likeArtistUseCase struct { | ||
Client *spotify.Client | ||
} | ||
|
||
// NewLikeArtistUseCase returns a new instance of the likeArtistUseCase struct. | ||
func NewLikeArtistUseCase(client *spotify.Client) *likeArtistUseCase { | ||
return &likeArtistUseCase{ | ||
Client: client, | ||
} | ||
} | ||
|
||
// Run returns the like result of the artist. | ||
func (uc *likeArtistUseCase) Run(id string) error { | ||
return uc.Client.FollowArtist(context.Background(), spotify.ID(id)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters