mirror of
https://github.com/go-gitea/gitea
synced 2024-06-16 10:00:29 +02:00
fix(pin db): added a function to get the count of pinned repos
This commit is contained in:
parent
b941b04269
commit
a019e443c4
|
@ -85,6 +85,10 @@ func GetPinnedRepos(ctx context.Context, opts *PinnedReposOptions) (RepositoryLi
|
|||
return db.Find[Repository](ctx, opts)
|
||||
}
|
||||
|
||||
func CountPinnedRepos(ctx context.Context, opts *PinnedReposOptions) (int64, error) {
|
||||
return db.Count[Repository](ctx, opts)
|
||||
}
|
||||
|
||||
type WatchedReposOptions struct {
|
||||
db.ListOptions
|
||||
WatcherID int64
|
||||
|
|
|
@ -19,18 +19,18 @@ const maxPins = 6
|
|||
// Check if a user have a new pinned repo in it's profile, meaning that it
|
||||
// has permissions to pin said repo and also has enough space on the pinned list.
|
||||
func CanPin(ctx *context.Context, u *user_model.User, r *repo_model.Repository) (bool, error) {
|
||||
repos, err := repo_model.GetPinnedRepos(*ctx, &repo_model.PinnedReposOptions{
|
||||
count, err := repo_model.CountPinnedRepos(*ctx, &repo_model.PinnedReposOptions{
|
||||
ListOptions: db.ListOptions{
|
||||
ListAll: true,
|
||||
},
|
||||
PinnerID: u.ID,
|
||||
})
|
||||
if err != nil {
|
||||
ctx.ServerError("GetPinnedRepos", err)
|
||||
ctx.ServerError("CountPinnedRepos", err)
|
||||
return false, err
|
||||
}
|
||||
|
||||
if len(repos) >= maxPins {
|
||||
if count >= maxPins {
|
||||
return false, nil
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user