feat: add backend API and solana challenge flows#2
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| @contextmanager | ||
| def get_session() -> Iterator[Session]: | ||
| session = Session(engine) | ||
| try: | ||
| yield session | ||
| finally: | ||
| session.close() |
There was a problem hiding this comment.
Return actual Session object from dependency
The database dependency is wrapped in @contextmanager, so FastAPI receives a _GeneratorContextManager instead of a Session. Every route that depends on get_session calls methods like .exec on the returned value and will raise AttributeError at runtime, making all challenge/bet endpoints unusable. Remove the decorator and implement the usual yield session pattern so the dependency returns a live Session instance.
Useful? React with 👍 / 👎.
| class BetBase(SQLModel): | ||
| challenge_id: UUID = Field(foreign_key="challenge.id") | ||
| bettor_public_key: str | ||
| amount: float = Field(ge=0) | ||
| side: str = Field(regex="^(yes|no)$") | ||
| signature: str | ||
| destination: str | ||
|
|
||
|
|
||
| class Bet(BetBase, table=True): | ||
| id: UUID = Field(default_factory=uuid4, primary_key=True, index=True) | ||
| recorded_at: datetime = Field(default_factory=datetime.utcnow) | ||
| status: str = Field(default="confirmed") | ||
|
|
||
|
|
||
| class BetCreate(BetBase): | ||
| pass |
There was a problem hiding this comment.
Align bet payload with path parameter
BetCreate inherits challenge_id, but the create bet API already takes challenge_id from the URL and the client request body (see CreateBetPayload) does not include this field. FastAPI will reject every bet submission with a 422 validation error before the transaction is recorded, even though the UI sends the SOL transfer first. The DTO should omit challenge_id or the route should not require it in the body so bets can be persisted after sending funds.
Useful? React with 👍 / 👎.
Summary
Testing
https://chatgpt.com/codex/tasks/task_e_68f704fbaff48326add3ac0539c0eb69