template-monorepo/internal/model/permission/domain/repository/user_role.go

31 lines
1.0 KiB
Go
Raw Normal View History

package repository
import (
"context"
"gateway/internal/model/permission/domain/entity"
"gateway/internal/model/permission/domain/enum"
)
// UserRoleRepository persists user↔role assignments.
//
// ReplaceForSource is the building block used by SyncFromX flows: it
// removes existing assignments of the given source for (tenant_id, uid)
// and inserts the new set in one transaction-equivalent step. Manual
// assignments are untouched.
type UserRoleRepository interface {
Insert(ctx context.Context, ur *entity.UserRole) error
BulkInsert(ctx context.Context, urs []*entity.UserRole) error
Delete(ctx context.Context, tenantID, uid, roleID string) error
DeleteByRole(ctx context.Context, tenantID, roleID string) (int64, error)
ReplaceForSource(
ctx context.Context,
tenantID, uid string,
source enum.RoleSource,
roleIDs []string,
) error
ListByUser(ctx context.Context, tenantID, uid string) ([]*entity.UserRole, error)
ListByRole(ctx context.Context, tenantID, roleID string) ([]*entity.UserRole, error)
}