ids-svc-product/internal/repository/store_scope.go
robinj0726 604dfeb06c feat: implement store scope validation and enforce it in product repository
- Added StoreScope struct with TenantID and StoreID fields.
- Introduced ErrStoreScopeRequired to handle missing store scope.
- Implemented Valid method to check if both TenantID and StoreID are present.
- Created requireWriteScope function to validate store scope before write operations.
- Updated product repository methods to require store scope for various operations.
- Added tests for StoreScope validation and requirement enforcement.
2026-09-13 00:12:44 +08:00

25 lines
573 B
Go

package repository
import "errors"
// ErrStoreScopeRequired is returned when a store-scoped write or list has no shop.
var ErrStoreScopeRequired = errors.New("store scope is required")
// StoreScope identifies the shop for a repository call.
type StoreScope struct {
TenantID int64
StoreID int64
}
// Valid reports whether both tenant and store identifiers are present.
func (s StoreScope) Valid() bool {
return s.TenantID > 0 && s.StoreID > 0
}
func requireWriteScope(scope StoreScope) error {
if !scope.Valid() {
return ErrStoreScopeRequired
}
return nil
}