feat: site count
This commit is contained in:
@@ -3,6 +3,7 @@ package repository
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"furtuna-be/internal/common/mycontext"
|
||||
"furtuna-be/internal/repository/branches"
|
||||
"furtuna-be/internal/repository/brevo"
|
||||
mdtrns "furtuna-be/internal/repository/midtrans"
|
||||
@@ -16,6 +17,7 @@ import (
|
||||
"furtuna-be/internal/repository/trx"
|
||||
"furtuna-be/internal/repository/users"
|
||||
repository "furtuna-be/internal/repository/wallet"
|
||||
|
||||
"github.com/golang-jwt/jwt"
|
||||
"gorm.io/gorm"
|
||||
|
||||
@@ -154,6 +156,7 @@ type SiteRepository interface {
|
||||
GetByID(ctx context.Context, id int64) (*entity.SiteDB, error)
|
||||
GetAll(ctx context.Context, req entity.SiteSearch) (entity.SiteList, int, error)
|
||||
Delete(ctx context.Context, id int64) error
|
||||
Count(ctx mycontext.Context, req entity.SiteSearch) (*entity.SiteCountDB, error)
|
||||
}
|
||||
|
||||
type TransactionManager interface {
|
||||
|
||||
@@ -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