kopia lustrzana https://github.com/bugout-dev/moonstream
Little bit of code cleanup
- Fixed mypy issues around `MOONSTREAM_ADMIN_ACCESS_TOKEN`. - Added `StreamBoundary` pydantic model to represent core information about view window into a stream. `PageBoundary` derives from `StreamBoundary`. - Removed unused imports and scratch comments from the /streams route definition.pull/105/head
rodzic
401f12a488
commit
3a3ef9ed39
|
@ -127,15 +127,31 @@ class EthereumTransactionItem(BaseModel):
|
|||
subscription_type_id: Optional[str] = None
|
||||
|
||||
|
||||
class PageBoundary(BaseModel):
|
||||
class StreamBoundary(BaseModel):
|
||||
"""
|
||||
StreamBoundary represents a window of time through which an API caller can view a stream.
|
||||
|
||||
This data structure is foundational to our stream rendering, and is used throughout the code
|
||||
base.
|
||||
"""
|
||||
|
||||
start_time: int
|
||||
end_time: int
|
||||
next_event_time: Optional[int] = None
|
||||
previous_event_time: Optional[int] = None
|
||||
include_start: bool = False
|
||||
include_end: bool = False
|
||||
|
||||
|
||||
class PageBoundary(StreamBoundary):
|
||||
"""
|
||||
A PageBoundary adds information about previous and subsequent events to a StreamBoundary.
|
||||
|
||||
This additional information helps callers manage their views into a stream.
|
||||
"""
|
||||
|
||||
next_event_time: Optional[int] = None
|
||||
previous_event_time: Optional[int] = None
|
||||
|
||||
|
||||
class EthereumTransactionResponse(BaseModel):
|
||||
stream: List[EthereumTransactionItem]
|
||||
boundaries: Optional[PageBoundary]
|
||||
|
|
|
@ -2,14 +2,11 @@
|
|||
The Moonstream subscriptions HTTP API
|
||||
"""
|
||||
import logging
|
||||
from typing import Any, cast, Dict, List, Optional, Set, Union
|
||||
from pydantic.utils import to_camel
|
||||
|
||||
from datetime import datetime, timedelta
|
||||
from typing import Dict, Optional
|
||||
|
||||
from bugout.data import BugoutResources
|
||||
from bugout.exceptions import BugoutResponseException
|
||||
from fastapi import FastAPI, HTTPException, Request, Form, Query, Depends
|
||||
from fastapi import FastAPI, HTTPException, Request, Query, Depends
|
||||
from fastapi.middleware.cors import CORSMiddleware
|
||||
from moonstreamdb import db
|
||||
from sqlalchemy.orm import Session
|
||||
|
@ -19,7 +16,6 @@ from .. import actions
|
|||
from .. import data
|
||||
from ..middleware import BroodAuthMiddleware
|
||||
from ..settings import (
|
||||
MOONSTREAM_APPLICATION_ID,
|
||||
DOCS_TARGET_PATH,
|
||||
ORIGINS,
|
||||
DOCS_PATHS,
|
||||
|
@ -60,15 +56,14 @@ app.add_middleware(BroodAuthMiddleware, whitelist=whitelist_paths)
|
|||
async def search_transactions(
|
||||
request: Request,
|
||||
q: str = Query(""),
|
||||
start_time: Optional[int] = Query(0), # Optional[int] = Query(0), #
|
||||
end_time: Optional[int] = Query(0), # Optional[int] = Query(0), #
|
||||
start_time: Optional[int] = Query(0),
|
||||
end_time: Optional[int] = Query(0),
|
||||
include_start: bool = Query(False),
|
||||
include_end: bool = Query(False),
|
||||
db_session: Session = Depends(db.yield_db_session),
|
||||
):
|
||||
|
||||
# get user subscriptions
|
||||
|
||||
token = request.state.token
|
||||
params = {"user_id": str(request.state.user.id)}
|
||||
try:
|
||||
|
@ -87,8 +82,6 @@ async def search_transactions(
|
|||
for resource in user_subscriptions_resources.resources
|
||||
}
|
||||
|
||||
# transactions: List[Any] = []
|
||||
|
||||
boundaries = data.PageBoundary(
|
||||
start_time=start_time,
|
||||
end_time=end_time,
|
||||
|
@ -97,7 +90,6 @@ async def search_transactions(
|
|||
include_start=include_start,
|
||||
include_end=include_end,
|
||||
)
|
||||
print(boundaries)
|
||||
|
||||
if address_to_subscriptions:
|
||||
print("address_to_subscriptions")
|
||||
|
@ -107,8 +99,6 @@ async def search_transactions(
|
|||
user_subscriptions_resources_by_address=address_to_subscriptions,
|
||||
boundaries=boundaries,
|
||||
)
|
||||
print(response.boundaries)
|
||||
|
||||
return response
|
||||
else:
|
||||
return data.EthereumTransactionResponse(stream=[], boundaries=boundaries)
|
||||
|
|
|
@ -16,8 +16,8 @@ MOONSTREAM_DATA_JOURNAL_ID = os.environ.get("MOONSTREAM_DATA_JOURNAL_ID")
|
|||
if MOONSTREAM_DATA_JOURNAL_ID is None:
|
||||
raise ValueError("MOONSTREAM_DATA_JOURNAL_ID environment variable must be set")
|
||||
|
||||
MOONSTREAM_ADMIN_ACCESS_TOKEN = os.environ.get("MOONSTREAM_ADMIN_ACCESS_TOKEN")
|
||||
if MOONSTREAM_ADMIN_ACCESS_TOKEN is None:
|
||||
MOONSTREAM_ADMIN_ACCESS_TOKEN = os.environ.get("MOONSTREAM_ADMIN_ACCESS_TOKEN", "")
|
||||
if MOONSTREAM_ADMIN_ACCESS_TOKEN == "":
|
||||
raise ValueError("MOONSTREAM_ADMIN_ACCESS_TOKEN environment variable must be set")
|
||||
|
||||
# Origin
|
||||
|
|
Ładowanie…
Reference in New Issue