Add function to delete a like
This commit is contained in:
parent
fc5096997c
commit
78e33be780
@ -20,6 +20,14 @@ func (p Profile) SaveLike(l scraper.Like) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (p Profile) DeleteLike(l scraper.Like) error {
|
||||||
|
_, err := p.DB.NamedExec(`delete from likes where user_id = :user_id and tweet_id = :tweet_id`, l)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("Error executing DeleteLike(%#v):\n %w", l, err)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (p Profile) GetLikeBySortID(id scraper.LikeSortID) (scraper.Like, error) {
|
func (p Profile) GetLikeBySortID(id scraper.LikeSortID) (scraper.Like, error) {
|
||||||
var l scraper.Like
|
var l scraper.Like
|
||||||
err := p.DB.Get(&l, `
|
err := p.DB.Get(&l, `
|
||||||
|
@ -36,3 +36,22 @@ func TestSaveAndLoadLike(t *testing.T) {
|
|||||||
t.Error(diff)
|
t.Error(diff)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestDeleteLike(t *testing.T) {
|
||||||
|
require := require.New(t)
|
||||||
|
|
||||||
|
profile_path := "test_profiles/TestLikesQueries"
|
||||||
|
profile := create_or_load_profile(profile_path)
|
||||||
|
|
||||||
|
like := create_dummy_like()
|
||||||
|
err := profile.SaveLike(like)
|
||||||
|
require.NoError(err)
|
||||||
|
|
||||||
|
// Delete it
|
||||||
|
err = profile.DeleteLike(like)
|
||||||
|
require.NoError(err)
|
||||||
|
|
||||||
|
// Should be gone
|
||||||
|
_, err = profile.GetLikeBySortID(like.SortID)
|
||||||
|
require.Error(err)
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user