feat: scope articles by brand

This commit is contained in:
2026-05-20 15:37:25 +08:00
parent 5fb9d0b0dd
commit dd082e2ed1
72 changed files with 3213 additions and 432 deletions
+20
View File
@@ -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
}