feat: scope articles by brand
This commit is contained in:
@@ -11,6 +11,7 @@ type Actor struct {
|
||||
|
||||
type actorKey struct{}
|
||||
type currentWorkspaceIDKey struct{}
|
||||
type currentBrandIDKey struct{}
|
||||
|
||||
func WithActor(ctx context.Context, actor Actor) context.Context {
|
||||
return context.WithValue(ctx, actorKey{}, actor)
|
||||
@@ -51,3 +52,22 @@ func CurrentWorkspaceID(ctx context.Context) int64 {
|
||||
}
|
||||
return actor.PrimaryWorkspaceID
|
||||
}
|
||||
|
||||
func WithCurrentBrandID(ctx context.Context, brandID int64) context.Context {
|
||||
return context.WithValue(ctx, currentBrandIDKey{}, brandID)
|
||||
}
|
||||
|
||||
func CurrentBrandIDFromCtx(ctx context.Context) (int64, bool) {
|
||||
brandID, ok := ctx.Value(currentBrandIDKey{}).(int64)
|
||||
if !ok || brandID <= 0 {
|
||||
return 0, false
|
||||
}
|
||||
return brandID, true
|
||||
}
|
||||
|
||||
func CurrentBrandID(ctx context.Context) int64 {
|
||||
if brandID, ok := CurrentBrandIDFromCtx(ctx); ok {
|
||||
return brandID
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user