mirror of
https://ids-dev.idsbuybuybuy.com/ids-ecommerce/ids-svc-product.git
synced 2026-11-29 16:57:41 +08:00
- 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.
25 lines
573 B
Go
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
|
|
}
|