-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhandlerBrowse.go
More file actions
39 lines (33 loc) · 954 Bytes
/
handlerBrowse.go
File metadata and controls
39 lines (33 loc) · 954 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
39
package main
import (
"context"
"fmt"
"strconv"
"gator/internal/database"
)
func handlerBrowse(s *state, cmd command, user database.User) error {
limit := 2
if len(cmd.Args) == 1 {
if specifiedLimit, err := strconv.Atoi(cmd.Args[0]); err == nil {
limit = specifiedLimit
} else {
return fmt.Errorf("invalid limit: %w", err)
}
}
posts, err := s.db.GetPostsForUser(context.Background(), database.GetPostsForUserParams{
UserID: user.ID,
Limit: int32(limit),
})
if err != nil {
return fmt.Errorf("couldn't get posts for user: %w", err)
}
fmt.Printf("Found %d posts for user %s:\n", len(posts), user.Name)
for _, post := range posts {
fmt.Printf("%s from %s\n", post.PublishedAt.Time.Format("Mon Jan 2"), post.FeedName)
fmt.Printf("--- %s ---\n", post.Title)
fmt.Printf(" %v\n", post.Description.String)
fmt.Printf("Link: %s\n", post.Url)
fmt.Println("=====================================")
}
return nil
}