-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhandler_unfollow.go
More file actions
38 lines (28 loc) · 903 Bytes
/
handler_unfollow.go
File metadata and controls
38 lines (28 loc) · 903 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"
"github.com/SamW94/GoGator/internal/database"
)
func handlerUnfollow(s *state, cmd command, user database.User) error {
if len(cmd.arguments) == 0 {
return fmt.Errorf("no arguments supplied with unfollow command - the unfollow handler expects a URL in format 'gator unfollow <url>")
}
userID := user.ID
url := cmd.arguments[0]
feedStruct, err := s.db.GetFeed(context.Background(), url)
if err != nil {
return fmt.Errorf("error retrieving feed with URL %s from database.GetFeed(): %w", url, err)
}
feedID := feedStruct.ID
followDeleteParams := database.DeleteFeedFollowParams{
UserID: userID,
FeedID: feedID,
}
feedFollow, err := s.db.DeleteFeedFollow(context.TODO(), followDeleteParams)
if err != nil {
return fmt.Errorf("error calling the database.DeleteFeedFollow() function: %w", err)
}
fmt.Println(feedFollow)
return nil
}