forked from baron/baron-sso
ReBAC 고도화 및 애플리케이션 관리 시스템 통합 구현
This commit is contained in:
61
backend/internal/repository/relying_party_repository.go
Normal file
61
backend/internal/repository/relying_party_repository.go
Normal file
@@ -0,0 +1,61 @@
|
||||
package repository
|
||||
|
||||
import (
|
||||
"baron-sso-backend/internal/domain"
|
||||
"context"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type RelyingPartyRepository interface {
|
||||
Create(ctx context.Context, rp *domain.RelyingParty) error
|
||||
Update(ctx context.Context, rp *domain.RelyingParty) error
|
||||
Delete(ctx context.Context, clientID string) error
|
||||
FindByID(ctx context.Context, clientID string) (*domain.RelyingParty, error)
|
||||
ListByTenantID(ctx context.Context, tenantID string) ([]domain.RelyingParty, error)
|
||||
ListAll(ctx context.Context) ([]domain.RelyingParty, error)
|
||||
}
|
||||
|
||||
func (r *relyingPartyRepository) ListAll(ctx context.Context) ([]domain.RelyingParty, error) {
|
||||
var rps []domain.RelyingParty
|
||||
if err := r.db.WithContext(ctx).Find(&rps).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return rps, nil
|
||||
}
|
||||
|
||||
type relyingPartyRepository struct {
|
||||
db *gorm.DB
|
||||
}
|
||||
|
||||
func NewRelyingPartyRepository(db *gorm.DB) RelyingPartyRepository {
|
||||
return &relyingPartyRepository{db: db}
|
||||
}
|
||||
|
||||
func (r *relyingPartyRepository) Create(ctx context.Context, rp *domain.RelyingParty) error {
|
||||
return r.db.WithContext(ctx).Create(rp).Error
|
||||
}
|
||||
|
||||
func (r *relyingPartyRepository) Update(ctx context.Context, rp *domain.RelyingParty) error {
|
||||
return r.db.WithContext(ctx).Save(rp).Error
|
||||
}
|
||||
|
||||
func (r *relyingPartyRepository) Delete(ctx context.Context, clientID string) error {
|
||||
return r.db.WithContext(ctx).Delete(&domain.RelyingParty{}, "client_id = ?", clientID).Error
|
||||
}
|
||||
|
||||
func (r *relyingPartyRepository) FindByID(ctx context.Context, clientID string) (*domain.RelyingParty, error) {
|
||||
var rp domain.RelyingParty
|
||||
if err := r.db.WithContext(ctx).First(&rp, "client_id = ?", clientID).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &rp, nil
|
||||
}
|
||||
|
||||
func (r *relyingPartyRepository) ListByTenantID(ctx context.Context, tenantID string) ([]domain.RelyingParty, error) {
|
||||
var rps []domain.RelyingParty
|
||||
if err := r.db.WithContext(ctx).Where("tenant_id = ?", tenantID).Find(&rps).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return rps, nil
|
||||
}
|
||||
@@ -13,6 +13,7 @@ type UserRepository interface {
|
||||
FindByEmail(ctx context.Context, email string) (*domain.User, error)
|
||||
FindByID(ctx context.Context, id string) (*domain.User, error)
|
||||
ListByTenant(ctx context.Context, tenantID string) ([]domain.User, error)
|
||||
List(ctx context.Context, offset, limit int, search string) ([]domain.User, int64, error)
|
||||
}
|
||||
|
||||
type userRepository struct {
|
||||
@@ -54,3 +55,24 @@ func (r *userRepository) ListByTenant(ctx context.Context, tenantID string) ([]d
|
||||
}
|
||||
return users, nil
|
||||
}
|
||||
|
||||
func (r *userRepository) List(ctx context.Context, offset, limit int, search string) ([]domain.User, int64, error) {
|
||||
var users []domain.User
|
||||
var total int64
|
||||
db := r.db.WithContext(ctx).Model(&domain.User{})
|
||||
|
||||
if search != "" {
|
||||
searchTerm := "%" + search + "%"
|
||||
db = db.Where("email LIKE ? OR name LIKE ?", searchTerm, searchTerm)
|
||||
}
|
||||
|
||||
if err := db.Count(&total).Error; err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
if err := db.Offset(offset).Limit(limit).Find(&users).Error; err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
return users, total, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user