fix(pin db): added a function to get the count of pinned repos

This commit is contained in:
Daniel Carvalho 2024-05-17 16:14:04 +00:00
parent b941b04269
commit a019e443c4
2 changed files with 7 additions and 3 deletions

View File

@ -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

View File

@ -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
}