-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhandler_unfollow.go
More file actions
38 lines (31 loc) · 882 Bytes
/
handler_unfollow.go
File metadata and controls
38 lines (31 loc) · 882 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package main
import (
"context"
"fmt"
"os"
"github.com/josephus-git/gator/internal/database"
)
// unfollow removes a feed follow entry for the authenticated user based on a given feed URL.
func unfollow(s *state, cmd command, user database.User) error {
// Check if input is accurate
if len(cmd.Handler) < 2 {
fmt.Println("Usage: ./gator Unfollow <url>")
os.Exit(1)
}
// get feed id
url := cmd.Handler[1]
feed, err := s.db.Getfeed(context.Background(), url)
if err != nil {
return fmt.Errorf("error getting feed id: %s", err)
}
deleteparams := database.DeleteFeedFollowParams{
FeedID: feed.ID,
UserID: user.ID,
}
err = s.db.DeleteFeedFollow(context.Background(), deleteparams)
if err != nil {
return fmt.Errorf("error deleting feed follow: %s", err)
}
fmt.Printf("Successfully deleted Feed: %s for User: %s", feed.Name, user.Name)
return nil
}