#8 - list feeds, no content still
This commit is contained in:
43
internal/database/listFeeds.sql.go
Normal file
43
internal/database/listFeeds.sql.go
Normal file
@@ -0,0 +1,43 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.28.0
|
||||
// source: listFeeds.sql
|
||||
|
||||
package database
|
||||
|
||||
import (
|
||||
"context"
|
||||
)
|
||||
|
||||
const listFeeds = `-- name: ListFeeds :many
|
||||
SELECT name, url, (SELECT name FROM users WHERE users.id = feeds.user_id) as user_name FROM feeds
|
||||
`
|
||||
|
||||
type ListFeedsRow struct {
|
||||
Name string
|
||||
Url string
|
||||
UserName string
|
||||
}
|
||||
|
||||
func (q *Queries) ListFeeds(ctx context.Context) ([]ListFeedsRow, error) {
|
||||
rows, err := q.db.QueryContext(ctx, listFeeds)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []ListFeedsRow
|
||||
for rows.Next() {
|
||||
var i ListFeedsRow
|
||||
if err := rows.Scan(&i.Name, &i.Url, &i.UserName); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Close(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
@@ -34,7 +34,7 @@ func AddFeedHandler(s *config.State, cmd config.Command) error {
|
||||
}
|
||||
|
||||
f, err := s.DB.CreateFeed(ctx, database.CreateFeedParams{
|
||||
ID: uuid.UUID{},
|
||||
ID: uuid.New(),
|
||||
CreatedAt: time.Time{},
|
||||
UpdatedAt: time.Time{},
|
||||
UserID: user.ID,
|
||||
|
||||
21
internal/handlers/listFeedsHandler.go
Normal file
21
internal/handlers/listFeedsHandler.go
Normal file
@@ -0,0 +1,21 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/rdarius/boot-dev-blog-aggregator/internal/config"
|
||||
)
|
||||
|
||||
func ListFeedsHandler(s *config.State, cmd config.Command) error {
|
||||
ctx := context.Background()
|
||||
feeds, err := s.DB.ListFeeds(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, feed := range feeds {
|
||||
fmt.Printf("Article: %s | Url: %s | User: %s\n", feed.Name, feed.Url, feed.UserName)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user