-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhandler_addfeed.go
More file actions
50 lines (41 loc) · 1.13 KB
/
Copy pathhandler_addfeed.go
File metadata and controls
50 lines (41 loc) · 1.13 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
45
46
47
48
49
50
package main
import (
"context"
"fmt"
"time"
"github.com/SamW94/GoGator/internal/database"
"github.com/google/uuid"
)
func handlerAddfeed(s *state, cmd command, user database.User) error {
if len(cmd.arguments) < 2 {
return fmt.Errorf("not enough arguments supplied - the addfeed handler expects 2 arguments in format 'gator addfeed <name> <url>")
}
userID := user.ID
name := cmd.arguments[0]
url := cmd.arguments[1]
feedParams := database.CreateFeedParams{
ID: uuid.New(),
CreatedAt: time.Now(),
UpdatedAt: time.Now(),
Name: name,
Url: url,
UserID: userID,
}
feed, err := s.db.CreateFeed(context.Background(), feedParams)
if err != nil {
return fmt.Errorf("error calling database.CreateFeed() function: %w", err)
}
followParams := database.CreateFeedFollowParams{
ID: uuid.New(),
CreatedAt: time.Now(),
UpdatedAt: time.Now(),
UserID: userID,
FeedID: feed.ID,
}
_, err = s.db.CreateFeedFollow(context.Background(), followParams)
if err != nil {
return fmt.Errorf("error calling the database.CreateFeedFollow() function: %w", err)
}
fmt.Println(feed)
return nil
}