Fetch items from channel with channelID
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Peter Stuifzand 2021-05-11 20:48:58 +02:00
parent 486961ba24
commit afbd987ca3
Signed by: peter
GPG Key ID: 374322D56E5209E8

View File

@ -80,7 +80,7 @@ CREATE TABLE IF NOT EXISTS "items" (
// Items // Items
func (p *postgresStream) Items(before, after string) (microsub.Timeline, error) { func (p *postgresStream) Items(before, after string) (microsub.Timeline, error) {
rows, err := p.database.Query(`SELECT "id", "uid", "data", "created_at", "is_read" FROM "items" WHERE "channel_id" = $1`, p.channel) rows, err := p.database.Query(`SELECT "id", "uid", "data", "created_at", "is_read" FROM "items" WHERE "channel_id" = $1 ORDER BY "published_at"`, p.channelID)
if err != nil { if err != nil {
return microsub.Timeline{}, fmt.Errorf("while query: %w", err) return microsub.Timeline{}, fmt.Errorf("while query: %w", err)
} }
@ -96,13 +96,23 @@ func (p *postgresStream) Items(before, after string) (microsub.Timeline, error)
err = rows.Scan(&id, &uid, &item, &createdAt, &isRead) err = rows.Scan(&id, &uid, &item, &createdAt, &isRead)
if err != nil { if err != nil {
return microsub.Timeline{}, fmt.Errorf("while scanning: %w", err) break
} }
item.Read = isRead == 1 item.Read = isRead == 1
item.ID = uid item.ID = uid
tl.Items = append(tl.Items, item) tl.Items = append(tl.Items, item)
} }
if closeErr := rows.Close(); closeErr != nil {
return tl, err
}
if err != nil {
return tl, err
}
if err = rows.Err(); err != nil {
return tl, err
}
return tl, nil return tl, nil
} }