mirror of
https://codeberg.org/davrot/forgejo.git
synced 2025-05-16 20:00:03 +02:00
[API] generalize list header (#16551)
* Add info about list endpoints to CONTRIBUTING.md * Let all list endpoints return X-Total-Count header * Add TODOs for GetCombinedCommitStatusByRef * Fix models/issue_stopwatch.go * Rrefactor models.ListDeployKeys * Introduce helper func and use them for SetLinkHeader related func
This commit is contained in:
parent
ca13e1d56c
commit
2289580bb7
88 changed files with 637 additions and 329 deletions
|
@ -184,7 +184,7 @@ func (opts *FindTopicOptions) toConds() builder.Cond {
|
|||
}
|
||||
|
||||
// FindTopics retrieves the topics via FindTopicOptions
|
||||
func FindTopics(opts *FindTopicOptions) (topics []*Topic, err error) {
|
||||
func FindTopics(opts *FindTopicOptions) ([]*Topic, int64, error) {
|
||||
sess := x.Select("topic.*").Where(opts.toConds())
|
||||
if opts.RepoID > 0 {
|
||||
sess.Join("INNER", "repo_topic", "repo_topic.topic_id = topic.id")
|
||||
|
@ -192,7 +192,18 @@ func FindTopics(opts *FindTopicOptions) (topics []*Topic, err error) {
|
|||
if opts.PageSize != 0 && opts.Page != 0 {
|
||||
sess = opts.setSessionPagination(sess)
|
||||
}
|
||||
return topics, sess.Desc("topic.repo_count").Find(&topics)
|
||||
topics := make([]*Topic, 0, 10)
|
||||
total, err := sess.Desc("topic.repo_count").FindAndCount(&topics)
|
||||
return topics, total, err
|
||||
}
|
||||
|
||||
// CountTopics counts the number of topics matching the FindTopicOptions
|
||||
func CountTopics(opts *FindTopicOptions) (int64, error) {
|
||||
sess := x.Where(opts.toConds())
|
||||
if opts.RepoID > 0 {
|
||||
sess.Join("INNER", "repo_topic", "repo_topic.topic_id = topic.id")
|
||||
}
|
||||
return sess.Count(new(Topic))
|
||||
}
|
||||
|
||||
// GetRepoTopicByName retrieves topic from name for a repo if it exist
|
||||
|
@ -269,7 +280,7 @@ func DeleteTopic(repoID int64, topicName string) (*Topic, error) {
|
|||
|
||||
// SaveTopics save topics to a repository
|
||||
func SaveTopics(repoID int64, topicNames ...string) error {
|
||||
topics, err := FindTopics(&FindTopicOptions{
|
||||
topics, _, err := FindTopics(&FindTopicOptions{
|
||||
RepoID: repoID,
|
||||
})
|
||||
if err != nil {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue