feat(REQ-014): add portfolio-create-user-required requirement and implementation
- Add docs/srs/Interface/req-014_portfolio-create-user-required.md with acceptance criteria - Create docs/batches/bat-004_20260502_portfolio-create-user-required/ delivery batch - Enhance app/cli/commands/portfolio.py: validate user_id parameter before portfolio creation - Add comprehensive CLI tests in tests/test_cli.py for portfolio create validation flows - Update docs/batches/index.md and docs/srs/index.md with new requirement/batch references - Update README.md documentation
This commit is contained in:
@@ -119,6 +119,7 @@ def portfolio_status(
|
||||
def create_portfolio(
|
||||
ctx: typer.Context,
|
||||
portfolio_id: str = typer.Argument(..., help="Portfolio identifier."),
|
||||
user: str | None = typer.Option(None, "--user", help="Owner username (required)."),
|
||||
name: str | None = typer.Option(None, help="Asset display name."),
|
||||
symbol: str = typer.Option(..., help="Trading symbol."),
|
||||
broker: str = typer.Option("kis", help="Broker code."),
|
||||
@@ -131,10 +132,16 @@ def create_portfolio(
|
||||
strategy_params: str = typer.Option("{}", help="Strategy params as JSON object."),
|
||||
force: bool = typer.Option(False, "--force", help="Skip confirmation prompt."),
|
||||
) -> None:
|
||||
if user is None:
|
||||
ctx.obj.console.print("Error: --user 옵션은 필수입니다.")
|
||||
raise typer.Exit(code=1)
|
||||
_confirm(force, f"Create portfolio {portfolio_id} for symbol {symbol}?")
|
||||
detail = _with_service(
|
||||
ctx,
|
||||
lambda service, app_context: service.create_portfolio(
|
||||
|
||||
def _callback(service, repository, app_context):
|
||||
owner = repository.get_user_by_username(user)
|
||||
if owner is None:
|
||||
raise ValueError(f"사용자를 찾을 수 없습니다: {user}")
|
||||
return service.create_portfolio(
|
||||
CreatePortfolioRequest(
|
||||
portfolio_id=portfolio_id,
|
||||
name=name,
|
||||
@@ -147,9 +154,11 @@ def create_portfolio(
|
||||
profit_buffer=profit_buffer,
|
||||
strategy_name=strategy_name,
|
||||
strategy_params=_parse_strategy_params(strategy_params),
|
||||
)
|
||||
),
|
||||
)
|
||||
),
|
||||
owner_user_id=owner.id,
|
||||
)
|
||||
|
||||
detail = _with_service_and_repo(ctx, _callback)
|
||||
render_output(ctx.obj.console, ctx.obj.output_format, detail)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user