-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhandler_follow.go
More file actions
44 lines (33 loc) · 1.02 KB
/
handler_follow.go
File metadata and controls
44 lines (33 loc) · 1.02 KB
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
39
40
41
42
43
44
package main
import (
"context"
"fmt"
"time"
"github.com/SamW94/GoGator/internal/database"
"github.com/google/uuid"
)
func handlerFollow(s *state, cmd command, user database.User) error {
if len(cmd.arguments) == 0 {
return fmt.Errorf("no arguments supplied with follow command - the follow handler expects a URL in format 'gator follow <url>")
}
url := cmd.arguments[0]
userID := user.ID
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
followParams := database.CreateFeedFollowParams{
ID: uuid.New(),
CreatedAt: time.Now(),
UpdatedAt: time.Now(),
UserID: userID,
FeedID: feedID,
}
_, err = s.db.CreateFeedFollow(context.Background(), followParams)
if err != nil {
return fmt.Errorf("error calling the database.CreateFeedFollow() function: %w", err)
}
fmt.Printf("Feed Name: %s\nCurrent User: %s\n", feedStruct.Name, user.Name)
return nil
}