Skip to content

Commit

Permalink
Merge pull request #780 from longguikeji/loopbing_2.5
Browse files Browse the repository at this point in the history
feat: 🎸 代码修复
  • Loading branch information
hanbinloop authored Apr 19, 2022
2 parents 566b177 + 04a31ed commit 10e5a0e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
8 changes: 5 additions & 3 deletions api/v1/views/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,21 @@ class AppConfigSchemaIn(Schema):


class AppConfigSchemaOut(Schema):
config_id: str
app_id: str


@transaction.atomic
@api.post("/{tenant_id}/app/", response=AppConfigSchemaOut, auth=None)
def create_app_config(request, tenant_id: str, data: AppConfigSchemaIn):
# 此处多了一层data需要多次获取
data = data.data
tenant = request.tenant
# 事件分发
results = dispatch_event(Event(tag=CREATE_APP, tenant=tenant, request=request, data=data))
for func, (result, extension) in results:
for func, ((result, extension), item) in results:
if result:
# 创建config
config = extension.create_tenant_config(tenant, data.config.data.dict())
config = extension.create_tenant_config(tenant, data.config.dict())
# 创建app
app = App()
app.name = data.name
Expand Down
5 changes: 3 additions & 2 deletions arkid/core/extension/app_protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def create_app_protocol_extension_config_schema(schema_cls, **field_definitions)
"""
for schema in app_protocol_schema_map.values():
core_api.add_fields(schema, **field_definitions)
core_api.add_fields(schema_cls, __root__=(Union[tuple(app_protocol_schema_map.values())], Field(discriminator='app_type'))) # type: ignore
core_api.add_fields(schema_cls, data=(Union[tuple(app_protocol_schema_map.values())], Field(discriminator='app_type'))) # type: ignore


class AppProtocolExtension(Extension):
Expand All @@ -56,7 +56,7 @@ def register_config_schema(self, schema, app_type, package=None,**kwargs):
# raise Exception('')
new_schema = create_schema(App,
name=self.package+'_config',
exclude=['is_del', 'is_active', 'updated', 'created', 'tenant', 'secret'],
exclude=['is_del', 'is_active', 'updated', 'created', 'tenant', 'secret', 'type'],
custom_fields=[
("app_type", Literal[app_type], Field()),
("config", schema, Field())
Expand All @@ -68,6 +68,7 @@ def register_config_schema(self, schema, app_type, package=None,**kwargs):

def filter_event_handler(self, event, **kwargs):
if event.data.app_type in self.app_type_map:
data = event.data
if event.tag == core_event.CREATE_APP:
return self.create_app(event, data.config)
elif event.tag == core_event.UPDATE_APP:
Expand Down

0 comments on commit 10e5a0e

Please sign in to comment.