kopia lustrzana https://github.com/bugout-dev/moonstream
code review changes
rodzic
0cf4f317d2
commit
5a2b88d86d
|
@ -12,6 +12,13 @@ from sqlalchemy.orm import Session, query, query_expression
|
||||||
|
|
||||||
from . import data
|
from . import data
|
||||||
from .settings import ETHERSCAN_SMARTCONTRACTS_BUCKET
|
from .settings import ETHERSCAN_SMARTCONTRACTS_BUCKET
|
||||||
|
import uuid
|
||||||
|
from bugout.data import BugoutResource
|
||||||
|
from .settings import (
|
||||||
|
MOONSTREAM_APPLICATION_ID,
|
||||||
|
bugout_client as bc,
|
||||||
|
BUGOUT_REQUEST_TIMEOUT_SECONDS,
|
||||||
|
)
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
ETHERSCAN_SMARTCONTRACT_LABEL_NAME = "etherscan_smartcontract"
|
ETHERSCAN_SMARTCONTRACT_LABEL_NAME = "etherscan_smartcontract"
|
||||||
|
@ -141,3 +148,25 @@ def get_address_labels(
|
||||||
)
|
)
|
||||||
|
|
||||||
return addresses_response
|
return addresses_response
|
||||||
|
|
||||||
|
|
||||||
|
def create_onboarding_resource(
|
||||||
|
token: uuid.UUID,
|
||||||
|
resource_data: Dict[str, Any] = {
|
||||||
|
"type": data.USER_ONBOARDING_STATE,
|
||||||
|
"steps": {
|
||||||
|
"welcome": 0,
|
||||||
|
"subscriptions": 0,
|
||||||
|
"stream": 0,
|
||||||
|
},
|
||||||
|
"is_complete": False,
|
||||||
|
},
|
||||||
|
) -> BugoutResource:
|
||||||
|
|
||||||
|
resource = bc.create_resource(
|
||||||
|
token=token,
|
||||||
|
application_id=MOONSTREAM_APPLICATION_ID,
|
||||||
|
resource_data=resource_data,
|
||||||
|
timeout=BUGOUT_REQUEST_TIMEOUT_SECONDS,
|
||||||
|
)
|
||||||
|
return resource
|
||||||
|
|
|
@ -2,8 +2,11 @@
|
||||||
Pydantic schemas for the Moonstream HTTP API
|
Pydantic schemas for the Moonstream HTTP API
|
||||||
"""
|
"""
|
||||||
from typing import List, Optional, Dict, Any
|
from typing import List, Optional, Dict, Any
|
||||||
|
|
||||||
from pydantic import BaseModel, Field
|
from pydantic import BaseModel, Field
|
||||||
|
|
||||||
|
USER_ONBOARDING_STATE = "onboarding_state"
|
||||||
|
|
||||||
|
|
||||||
class SubscriptionTypeResourceData(BaseModel):
|
class SubscriptionTypeResourceData(BaseModel):
|
||||||
id: str
|
id: str
|
||||||
|
|
|
@ -27,6 +27,7 @@ from ..settings import (
|
||||||
BUGOUT_REQUEST_TIMEOUT_SECONDS,
|
BUGOUT_REQUEST_TIMEOUT_SECONDS,
|
||||||
)
|
)
|
||||||
from ..version import MOONSTREAM_VERSION
|
from ..version import MOONSTREAM_VERSION
|
||||||
|
from ..actions import create_onboarding_resource
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
@ -176,31 +177,6 @@ async def logout_handler(request: Request) -> uuid.UUID:
|
||||||
return token_id
|
return token_id
|
||||||
|
|
||||||
|
|
||||||
USER_ONBOARDING_STATE = "onboarding_state"
|
|
||||||
|
|
||||||
|
|
||||||
def create_onboarding_resource(
|
|
||||||
token,
|
|
||||||
resource_data={
|
|
||||||
"type": USER_ONBOARDING_STATE,
|
|
||||||
"steps": {
|
|
||||||
"welcome": 0,
|
|
||||||
"subscriptions": 0,
|
|
||||||
"stream": 0,
|
|
||||||
},
|
|
||||||
"is_complete": False,
|
|
||||||
},
|
|
||||||
) -> BugoutResource:
|
|
||||||
|
|
||||||
resource = bc.create_resource(
|
|
||||||
token=token,
|
|
||||||
application_id=MOONSTREAM_APPLICATION_ID,
|
|
||||||
resource_data=resource_data,
|
|
||||||
timeout=BUGOUT_REQUEST_TIMEOUT_SECONDS,
|
|
||||||
)
|
|
||||||
return resource
|
|
||||||
|
|
||||||
|
|
||||||
@app.post("/onboarding", tags=["users"], response_model=data.OnboardingState)
|
@app.post("/onboarding", tags=["users"], response_model=data.OnboardingState)
|
||||||
async def set_onboarding_state(
|
async def set_onboarding_state(
|
||||||
request: Request,
|
request: Request,
|
||||||
|
@ -208,13 +184,13 @@ async def set_onboarding_state(
|
||||||
) -> data.OnboardingState:
|
) -> data.OnboardingState:
|
||||||
|
|
||||||
token = request.state.token
|
token = request.state.token
|
||||||
|
try:
|
||||||
response = bc.list_resources(
|
response = bc.list_resources(
|
||||||
token=token,
|
token=token,
|
||||||
params={"type": USER_ONBOARDING_STATE},
|
params={"type": data.USER_ONBOARDING_STATE},
|
||||||
timeout=BUGOUT_REQUEST_TIMEOUT_SECONDS,
|
timeout=BUGOUT_REQUEST_TIMEOUT_SECONDS,
|
||||||
)
|
)
|
||||||
resource_data = {"type": USER_ONBOARDING_STATE, **onboarding_data.dict()}
|
resource_data = {"type": data.USER_ONBOARDING_STATE, **onboarding_data.dict()}
|
||||||
try:
|
|
||||||
if response.resources:
|
if response.resources:
|
||||||
resource = bc.update_resource(
|
resource = bc.update_resource(
|
||||||
token=token,
|
token=token,
|
||||||
|
@ -250,12 +226,12 @@ async def set_onboarding_state(
|
||||||
@app.get("/onboarding", tags=["users"], response_model=data.OnboardingState)
|
@app.get("/onboarding", tags=["users"], response_model=data.OnboardingState)
|
||||||
async def get_onboarding_state(request: Request) -> data.OnboardingState:
|
async def get_onboarding_state(request: Request) -> data.OnboardingState:
|
||||||
token = request.state.token
|
token = request.state.token
|
||||||
|
try:
|
||||||
response = bc.list_resources(
|
response = bc.list_resources(
|
||||||
token=token,
|
token=token,
|
||||||
params={"type": USER_ONBOARDING_STATE},
|
params={"type": data.USER_ONBOARDING_STATE},
|
||||||
timeout=BUGOUT_REQUEST_TIMEOUT_SECONDS,
|
timeout=BUGOUT_REQUEST_TIMEOUT_SECONDS,
|
||||||
)
|
)
|
||||||
try:
|
|
||||||
|
|
||||||
if response.resources:
|
if response.resources:
|
||||||
resource = response.resources[0]
|
resource = response.resources[0]
|
||||||
|
@ -285,14 +261,14 @@ async def get_onboarding_state(request: Request) -> data.OnboardingState:
|
||||||
@app.delete("/onboarding", tags=["users"], response_model=data.OnboardingState)
|
@app.delete("/onboarding", tags=["users"], response_model=data.OnboardingState)
|
||||||
async def delete_onboarding_state(request: Request) -> data.OnboardingState:
|
async def delete_onboarding_state(request: Request) -> data.OnboardingState:
|
||||||
token = request.state.token
|
token = request.state.token
|
||||||
|
try:
|
||||||
response = bc.list_resources(
|
response = bc.list_resources(
|
||||||
token=token,
|
token=token,
|
||||||
params={"type": USER_ONBOARDING_STATE},
|
params={"type": data.USER_ONBOARDING_STATE},
|
||||||
timeout=BUGOUT_REQUEST_TIMEOUT_SECONDS,
|
timeout=BUGOUT_REQUEST_TIMEOUT_SECONDS,
|
||||||
)
|
)
|
||||||
if not response.resources:
|
if not response.resources:
|
||||||
raise HTTPException(status_code=404, detail="not found")
|
raise HTTPException(status_code=404, detail="not found")
|
||||||
try:
|
|
||||||
if response.resources:
|
if response.resources:
|
||||||
resource: BugoutResource = bc.delete_resource(
|
resource: BugoutResource = bc.delete_resource(
|
||||||
token=token,
|
token=token,
|
||||||
|
|
Ładowanie…
Reference in New Issue