replaced sql command to order the new articles by source (#30)
This commit is contained in:
parent
337151b39d
commit
94da578c82
@ -354,7 +354,6 @@ const getArticlesBySource = `-- name: GetArticlesBySource :many
|
|||||||
select articles.id, sourceid, articles.tags, title, articles.url, pubdate, video, videoheight, videowidth, thumbnail, description, authorname, authorimage, sources.id, site, name, source, type, value, enabled, sources.url, sources.tags from articles
|
select articles.id, sourceid, articles.tags, title, articles.url, pubdate, video, videoheight, videowidth, thumbnail, description, authorname, authorimage, sources.id, site, name, source, type, value, enabled, sources.url, sources.tags from articles
|
||||||
INNER join sources on articles.sourceid=Sources.ID
|
INNER join sources on articles.sourceid=Sources.ID
|
||||||
where site = $1
|
where site = $1
|
||||||
ORDER By pubdate desc
|
|
||||||
`
|
`
|
||||||
|
|
||||||
type GetArticlesBySourceRow struct {
|
type GetArticlesBySourceRow struct {
|
||||||
@ -607,6 +606,49 @@ func (q *Queries) GetIconBySite(ctx context.Context, site string) (Icon, error)
|
|||||||
return i, err
|
return i, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const getNewArticlesBySourceId = `-- name: GetNewArticlesBySourceId :many
|
||||||
|
SELECT id, sourceid, tags, title, url, pubdate, video, videoheight, videowidth, thumbnail, description, authorname, authorimage FROM articles
|
||||||
|
Where sourceid = $1
|
||||||
|
ORDER BY pubdate desc Limit 50
|
||||||
|
`
|
||||||
|
|
||||||
|
func (q *Queries) GetNewArticlesBySourceId(ctx context.Context, sourceid uuid.UUID) ([]Article, error) {
|
||||||
|
rows, err := q.db.QueryContext(ctx, getNewArticlesBySourceId, sourceid)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
defer rows.Close()
|
||||||
|
var items []Article
|
||||||
|
for rows.Next() {
|
||||||
|
var i Article
|
||||||
|
if err := rows.Scan(
|
||||||
|
&i.ID,
|
||||||
|
&i.Sourceid,
|
||||||
|
&i.Tags,
|
||||||
|
&i.Title,
|
||||||
|
&i.Url,
|
||||||
|
&i.Pubdate,
|
||||||
|
&i.Video,
|
||||||
|
&i.Videoheight,
|
||||||
|
&i.Videowidth,
|
||||||
|
&i.Thumbnail,
|
||||||
|
&i.Description,
|
||||||
|
&i.Authorname,
|
||||||
|
&i.Authorimage,
|
||||||
|
); 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
|
||||||
|
}
|
||||||
|
|
||||||
const getSettingByID = `-- name: GetSettingByID :one
|
const getSettingByID = `-- name: GetSettingByID :one
|
||||||
Select id, key, value, options From settings
|
Select id, key, value, options From settings
|
||||||
Where ID = $1 Limit 1
|
Where ID = $1 Limit 1
|
||||||
|
@ -11,14 +11,17 @@ Where Url = $1 LIMIT 1;
|
|||||||
Select * From articles Limit $1;
|
Select * From articles Limit $1;
|
||||||
|
|
||||||
-- name: ListArticlesByDate :many
|
-- name: ListArticlesByDate :many
|
||||||
Select * From articles
|
Select * From articles ORDER BY pubdate desc Limit $1;
|
||||||
ORDER BY pubdate desc Limit $1;
|
|
||||||
|
|
||||||
-- name: GetArticlesBySource :many
|
-- name: GetArticlesBySource :many
|
||||||
select * from articles
|
select * from articles
|
||||||
INNER join sources on articles.sourceid=Sources.ID
|
INNER join sources on articles.sourceid=Sources.ID
|
||||||
WHERE site = $1
|
where site = $1;
|
||||||
ORDER By pubdate desc;
|
|
||||||
|
-- name: GetNewArticlesBySourceId :many
|
||||||
|
SELECT * FROM articles
|
||||||
|
Where sourceid = $1
|
||||||
|
ORDER BY pubdate desc Limit 50;
|
||||||
|
|
||||||
-- name: GetArticlesBySourceId :many
|
-- name: GetArticlesBySourceId :many
|
||||||
Select * From articles
|
Select * From articles
|
||||||
|
@ -81,7 +81,8 @@ func (s *Server) GetArticlesBySourceId(w http.ResponseWriter, r *http.Request) {
|
|||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
res, err := s.Db.GetArticlesBySourceId(*s.ctx, uuid)
|
res, err := s.Db.GetNewArticlesBySourceId(*s.ctx, uuid)
|
||||||
|
//res, err := s.Db.GetArticlesBySourceId(*s.ctx, uuid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
w.Write([]byte(err.Error()))
|
w.Write([]byte(err.Error()))
|
||||||
panic(err)
|
panic(err)
|
||||||
|
Loading…
Reference in New Issue
Block a user