-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhandler_addfeed.go
More file actions
36 lines (28 loc) · 878 Bytes
/
handler_addfeed.go
File metadata and controls
36 lines (28 loc) · 878 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
package main
import (
"context"
"errors"
"fmt"
"time"
"github.com/google/uuid"
"github.com/jovanadjuric/rss-aggregator/internal/database"
)
func handlerAddfeed(s *state, cmd command, user database.User) error {
if len(cmd.args) != 2 {
return errors.New("addfeed handler expects two arguments, name and url")
}
uid := uuid.New()
feed, err := s.db.CreateFeed(context.Background(), database.CreateFeedParams{ID: uid, CreatedAt: time.Now(), UpdatedAt: time.Now(), Name: cmd.args[0], Url: cmd.args[1], UserID: user.ID})
if err != nil {
return err
}
uid = uuid.New()
_, err = s.db.CreateFeedFollow(context.Background(), database.CreateFeedFollowParams{ID: uid, CreatedAt: time.Now(), UpdatedAt: time.Now(), FeedID: feed.ID, UserID: user.ID})
if err != nil {
return err
}
fmt.Println(feed.ID)
fmt.Println(feed.Name)
fmt.Println(feed.Url)
return nil
}