kopia lustrzana https://github.com/bugout-dev/moonstream
Add changes.
rodzic
4e2100423d
commit
6f8e852386
|
@ -2,14 +2,17 @@
|
|||
Pydantic schemas for the Moonstream HTTP API
|
||||
"""
|
||||
from datetime import datetime
|
||||
import json
|
||||
from enum import Enum
|
||||
from typing import Any, Dict, List, Optional, Union, Literal
|
||||
from uuid import UUID
|
||||
from xmlrpc.client import Boolean
|
||||
|
||||
from fastapi import Form
|
||||
from pydantic import BaseModel, Field, validator
|
||||
from sqlalchemy import false
|
||||
|
||||
|
||||
USER_ONBOARDING_STATE = "onboarding_state"
|
||||
|
||||
BUGOUT_RESOURCE_QUERY_RESOLVER = "query_name_resolver"
|
||||
|
@ -245,6 +248,22 @@ class SubdcriptionsAbiResponse(BaseModel):
|
|||
abi: str
|
||||
|
||||
|
||||
class UpdateSubscriptionRequest(BaseModel):
|
||||
color: Optional[str] = Form(None)
|
||||
label: Optional[str] = Form(None)
|
||||
abi: Optional[str] = Form(None)
|
||||
description: Optional[str] = Form(None)
|
||||
tags: Optional[List[Dict[str, Any]]] = Form(None)
|
||||
|
||||
@validator("tags", pre=True, always=True)
|
||||
def transform_to_dict(cls, v):
|
||||
if isinstance(v, str):
|
||||
return json.loads(v)
|
||||
elif isinstance(v, list):
|
||||
return v
|
||||
return []
|
||||
|
||||
|
||||
class DashboardMeta(BaseModel):
|
||||
subscription_id: UUID
|
||||
generic: Optional[List[Dict[str, str]]]
|
||||
|
|
|
@ -6,7 +6,6 @@ import hashlib
|
|||
import json
|
||||
import logging
|
||||
from typing import Any, Dict, List, Optional
|
||||
import traceback
|
||||
|
||||
from bugout.exceptions import BugoutResponseException
|
||||
from bugout.data import BugoutSearchResult
|
||||
|
@ -38,6 +37,8 @@ from ..web3_provider import (
|
|||
yield_web3_provider,
|
||||
)
|
||||
|
||||
import traceback
|
||||
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
@ -184,6 +185,7 @@ async def add_subscription_handler(
|
|||
internal_error=e,
|
||||
)
|
||||
except Exception as e:
|
||||
traceback.print_exc()
|
||||
logger.error(f"Failed to get collection id")
|
||||
raise MoonstreamHTTPException(
|
||||
status_code=500,
|
||||
|
@ -362,11 +364,6 @@ async def update_subscriptions_handler(
|
|||
request: Request,
|
||||
subscription_id: str,
|
||||
background_tasks: BackgroundTasks,
|
||||
color: Optional[str] = Form(None),
|
||||
label: Optional[str] = Form(None),
|
||||
abi: Optional[str] = Form(None),
|
||||
description: Optional[str] = Form(None),
|
||||
tags: Optional[str] = Form(None),
|
||||
) -> data.SubscriptionResourceData:
|
||||
"""
|
||||
Get user's subscriptions.
|
||||
|
@ -375,6 +372,16 @@ async def update_subscriptions_handler(
|
|||
|
||||
user = request.state.user
|
||||
|
||||
form = await request.form()
|
||||
|
||||
form_data = data.UpdateSubscriptionRequest(**form)
|
||||
|
||||
color = form_data.color
|
||||
label = form_data.label
|
||||
abi = form_data.abi
|
||||
description = form_data.description
|
||||
tags = form_data.tags
|
||||
|
||||
try:
|
||||
collection_id = get_entity_subscription_collection_id(
|
||||
resource_type=BUGOUT_RESOURCE_TYPE_ENTITY_SUBSCRIPTION,
|
||||
|
@ -408,7 +415,7 @@ async def update_subscriptions_handler(
|
|||
f"Subscription entity {subscription_id} in collection {collection_id} has no subscription_type_id malformed subscription entity"
|
||||
)
|
||||
raise MoonstreamHTTPException(
|
||||
status_code=404,
|
||||
status_code=409,
|
||||
detail="Not valid subscription entity",
|
||||
)
|
||||
|
||||
|
@ -424,16 +431,20 @@ async def update_subscriptions_handler(
|
|||
)
|
||||
raise MoonstreamHTTPException(status_code=500, internal_error=e)
|
||||
|
||||
#
|
||||
|
||||
for field in update_required_fields:
|
||||
if "color" in field and color is not None:
|
||||
field["color"] = color
|
||||
if "color" in field:
|
||||
if color is not None:
|
||||
field["color"] = color
|
||||
else:
|
||||
color = field["color"]
|
||||
|
||||
if "label" in field and label is not None:
|
||||
field["label"] = label
|
||||
if "label" in field:
|
||||
if label is not None:
|
||||
field["label"] = label
|
||||
else:
|
||||
label = field["label"]
|
||||
|
||||
if abi:
|
||||
if abi is not None:
|
||||
try:
|
||||
json_abi = json.loads(abi)
|
||||
except json.JSONDecodeError:
|
||||
|
@ -448,11 +459,11 @@ async def update_subscriptions_handler(
|
|||
|
||||
update_secondary_fields["abi_hash"] = hash
|
||||
|
||||
if description:
|
||||
if description is not None:
|
||||
update_secondary_fields["description"] = description
|
||||
|
||||
if tags:
|
||||
additional_required_fields_dict = json.loads(tags)
|
||||
if tags is not None:
|
||||
additional_required_fields_dict = tags
|
||||
|
||||
allowed_required_fields = {
|
||||
key: value
|
||||
|
|
Ładowanie…
Reference in New Issue