appview: db: pulls: add method for getting any pulls on a repo #475

merged
opened by ptr.pet targeting master from ptr.pet/core: repo-feed
Changed files
+22 -3
appview
+22 -3
appview/db/pulls.go
···
return pullId - 1, err
}
-
func GetPulls(e Execer, filters ...filter) ([]*Pull, error) {
+
func GetPullsWithLimit(e Execer, limit int, filters ...filter) ([]*Pull, error) {
pulls := make(map[int]*Pull)
var conditions []string
···
if conditions != nil {
whereClause = " where " + strings.Join(conditions, " and ")
}
+
limitClause := ""
+
if limit != 0 {
+
limitClause = fmt.Sprintf(" limit %d ", limit)
+
}
query := fmt.Sprintf(`
select
···
from
pulls
%s
-
`, whereClause)
+
order by
+
created desc
+
%s
+
`, whereClause, limitClause)
rows, err := e.Query(query, args...)
if err != nil {
···
inClause := strings.TrimSuffix(strings.Repeat("?, ", len(pulls)), ", ")
submissionsQuery := fmt.Sprintf(`
select
-
id, pull_id, round_number, patch, source_rev
+
id, pull_id, round_number, patch, created, source_rev
from
pull_submissions
where
···
for submissionsRows.Next() {
var s PullSubmission
var sourceRev sql.NullString
+
var createdAt string
err := submissionsRows.Scan(
&s.ID,
&s.PullId,
&s.RoundNumber,
&s.Patch,
+
&createdAt,
&sourceRev,
)
if err != nil {
return nil, err
}
+
createdTime, err := time.Parse(time.RFC3339, createdAt)
+
if err != nil {
+
return nil, err
+
}
+
s.Created = createdTime
+
if sourceRev.Valid {
s.SourceRev = sourceRev.String
}
···
return orderedByPullId, nil
}
+
func GetPulls(e Execer, filters ...filter) ([]*Pull, error) {
+
return GetPullsWithLimit(e, 0, filters...)
+
}
+
func GetPull(e Execer, repoAt syntax.ATURI, pullId int) (*Pull, error) {
query := `
select