feat: add portfolio ownership model, auth guards, and migration
This commit is contained in:
+13
-1
@@ -117,6 +117,7 @@ class FakeRepo:
|
||||
status: str = "enabled",
|
||||
active_strategy_id: str | None = None,
|
||||
avabile_strategies: list[str] | None = None,
|
||||
owner_user_id: str | None = None,
|
||||
initial_cash: float = 0.0,
|
||||
) -> Portfolio:
|
||||
if self._portfolio is None:
|
||||
@@ -126,6 +127,7 @@ class FakeRepo:
|
||||
status=status,
|
||||
name=name or symbol,
|
||||
symbol=symbol,
|
||||
owner_user_id=owner_user_id,
|
||||
cash_balance=initial_cash,
|
||||
active_strategy_id=active_strategy_id,
|
||||
avabile_strategies=avabile_strategies,
|
||||
@@ -136,6 +138,7 @@ class FakeRepo:
|
||||
self,
|
||||
portfolio_id: str,
|
||||
*,
|
||||
owner_user_id: str,
|
||||
broker: str,
|
||||
status: str,
|
||||
name: str,
|
||||
@@ -153,6 +156,7 @@ class FakeRepo:
|
||||
status=status,
|
||||
name=name,
|
||||
symbol=symbol,
|
||||
owner_user_id=owner_user_id,
|
||||
cash_balance=cash_balance,
|
||||
asset_quantity=asset_quantity,
|
||||
price=asset_price,
|
||||
@@ -169,13 +173,21 @@ class FakeRepo:
|
||||
setattr(portfolio, key, value)
|
||||
return portfolio
|
||||
|
||||
def list_portfolios(self, *, broker: str | None = None, status: str | None = None) -> list[Portfolio]:
|
||||
def list_portfolios(
|
||||
self,
|
||||
*,
|
||||
broker: str | None = None,
|
||||
status: str | None = None,
|
||||
owner_user_id: str | None = None,
|
||||
) -> list[Portfolio]:
|
||||
if self._portfolio is None:
|
||||
return []
|
||||
if broker is not None and self._portfolio.broker != broker:
|
||||
return []
|
||||
if status is not None and self._portfolio.status != status:
|
||||
return []
|
||||
if owner_user_id is not None and self._portfolio.owner_user_id != owner_user_id:
|
||||
return []
|
||||
return [self._portfolio]
|
||||
|
||||
def get_or_create_strategy_set(self, name: str, config: str) -> StrategySet:
|
||||
|
||||
Reference in New Issue
Block a user