feat: site count
This commit is contained in:
@@ -3,6 +3,7 @@ package sites
|
||||
import (
|
||||
"context"
|
||||
"furtuna-be/internal/common/logger"
|
||||
"furtuna-be/internal/common/mycontext"
|
||||
"furtuna-be/internal/entity"
|
||||
|
||||
"go.uber.org/zap"
|
||||
@@ -129,3 +130,21 @@ func (r *SiteRepository) Delete(ctx context.Context, id int64) error {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *SiteRepository) Count(ctx mycontext.Context, req entity.SiteSearch) (*entity.SiteCountDB, error) {
|
||||
count := new(entity.SiteCountDB)
|
||||
|
||||
query := r.db.Table("sites").
|
||||
Select("count(*) as count")
|
||||
|
||||
if !req.IsAdmin {
|
||||
query = query.Where("partner_id = ?", req.PartnerID)
|
||||
}
|
||||
|
||||
if err := query.Scan(&count).Error; err != nil {
|
||||
logger.ContextLogger(ctx).Error("error when get count sites", zap.Error(err))
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return count, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user