28 lines
1.2 KiB
Go
28 lines
1.2 KiB
Go
package repository
|
|
|
|
import (
|
|
"context"
|
|
|
|
"code.30cm.net/digimon/app-cloudep-permission-server/pkg/domain/entity"
|
|
"go.mongodb.org/mongo-driver/mongo"
|
|
)
|
|
|
|
type UserRoleRepository interface {
|
|
GetAll(ctx context.Context) ([]*entity.UserRole, error) // `All` -> `GetAll`,更直觀
|
|
GetByUserID(ctx context.Context, uid string) (entity.UserRole, error) // `Get` -> `GetByUserID`,明確是透過 `uid` 查詢
|
|
GetUsersByRoleID(ctx context.Context, roleID string) ([]entity.UserRole, error) // `GetByRoleID` -> `GetUsersByRoleID`,更具語意
|
|
CountUsersByRole(ctx context.Context) ([]RoleUserCount, error) // `UserCount` -> `CountUsersByRole`,清楚表達它是計算使用者數量
|
|
CreateUserRole(ctx context.Context, param entity.UserRole) error // `Create` -> `CreateUserRole`,明確表示新增的是使用者與角色的關係
|
|
UpdateUserRole(ctx context.Context, uid, roleID string) (entity.UserRole, error) // `Update` -> `UpdateUserRole`,明確描述更新的是哪個對象
|
|
UserRoleIndex
|
|
}
|
|
|
|
type UserRoleIndex interface {
|
|
Index20250225UP(ctx context.Context) (*mongo.Cursor, error)
|
|
}
|
|
|
|
type RoleUserCount struct {
|
|
RoleID string `bson:"_id"`
|
|
Count int `bson:"count"`
|
|
}
|