@@ -6,12 +6,14 @@ import (
66
77 "opencsg.com/csghub-server/builder/store/database"
88 "opencsg.com/csghub-server/common/config"
9+ "opencsg.com/csghub-server/common/errorx"
910 "opencsg.com/csghub-server/common/types"
1011)
1112
1213type mirrorNamespaceMappingComponentImpl struct {
1314 mirrorNamespaceMappingStore database.MirrorNamespaceMappingStore
1415 userStore database.UserStore
16+ namespaceStore database.NamespaceStore
1517}
1618
1719type MirrorNamespaceMappingComponent interface {
@@ -26,10 +28,19 @@ func NewMirrorNamespaceMappingComponent(config *config.Config) (MirrorNamespaceM
2628 return & mirrorNamespaceMappingComponentImpl {
2729 mirrorNamespaceMappingStore : database .NewMirrorNamespaceMappingStore (),
2830 userStore : database .NewUserStore (),
31+ namespaceStore : database .NewNamespaceStore (),
2932 }, nil
3033}
3134
3235func (c * mirrorNamespaceMappingComponentImpl ) Create (ctx context.Context , req types.CreateMirrorNamespaceMappingReq ) (* database.MirrorNamespaceMapping , error ) {
36+ exists , err := c .namespaceStore .Exists (ctx , req .TargetNamespace )
37+ if err != nil {
38+ return nil , fmt .Errorf ("failed to check target namespace existence, error: %w" , err )
39+ }
40+ if ! exists {
41+ return nil , errorx .TargetNamespaceNotFound (req .TargetNamespace )
42+ }
43+
3344 var mnm database.MirrorNamespaceMapping
3445 mnm .SourceNamespace = req .SourceNamespace
3546 mnm .TargetNamespace = req .TargetNamespace
@@ -59,6 +70,16 @@ func (c *mirrorNamespaceMappingComponentImpl) Index(ctx context.Context) ([]data
5970 return mnm , nil
6071}
6172func (c * mirrorNamespaceMappingComponentImpl ) Update (ctx context.Context , req types.UpdateMirrorNamespaceMappingReq ) (* database.MirrorNamespaceMapping , error ) {
73+ if req .TargetNamespace != nil {
74+ exists , err := c .namespaceStore .Exists (ctx , * req .TargetNamespace )
75+ if err != nil {
76+ return nil , fmt .Errorf ("failed to check target namespace existence, error: %w" , err )
77+ }
78+ if ! exists {
79+ return nil , errorx .TargetNamespaceNotFound (* req .TargetNamespace )
80+ }
81+ }
82+
6283 var mnm database.MirrorNamespaceMapping
6384 mnm .ID = req .ID
6485 if req .SourceNamespace != nil {
0 commit comments