wip
This commit is contained in:
parent
1a0bf1adb9
commit
c3db85a209
21 changed files with 647 additions and 658 deletions
|
|
@ -1,3 +1,4 @@
|
|||
import httpx
|
||||
from rich.console import Console
|
||||
import typer
|
||||
import uvicorn
|
||||
|
|
@ -38,15 +39,11 @@ def status(
|
|||
help="show the log messages",
|
||||
),
|
||||
):
|
||||
import httpx
|
||||
|
||||
config = get_config()
|
||||
host = config.api_server.host
|
||||
port = config.api_server.port
|
||||
url = f"http://{host}:{port}/docs"
|
||||
url = config.api_client.url
|
||||
|
||||
try:
|
||||
r = httpx.get(url)
|
||||
r = httpx.get(url + "/docs")
|
||||
if r.status_code == 200:
|
||||
Console().print(f"[green]API: ([gold1]{url}[green]) is running")
|
||||
else:
|
||||
|
|
@ -59,7 +56,7 @@ def status(
|
|||
Console().print(
|
||||
f"[green]database: ([gold1]{config.database.engine}[green]) is running"
|
||||
)
|
||||
except Exception as e:
|
||||
except Exception:
|
||||
Console().print(
|
||||
f"[red]database: ([gold1]{config.database.engine}[red]) is not running"
|
||||
)
|
||||
|
|
|
|||
|
|
@ -2,13 +2,11 @@ import sys
|
|||
from typing import List, Optional, Union
|
||||
|
||||
from engorgio import engorgio
|
||||
import httpx
|
||||
from rich.console import Console
|
||||
import typer
|
||||
|
||||
from learn_sql_model.config import Config, get_config
|
||||
from learn_sql_model.config import get_config
|
||||
from learn_sql_model.factories.hero import HeroFactory
|
||||
from learn_sql_model.factories.pet import PetFactory
|
||||
from learn_sql_model.models.hero import (
|
||||
Hero,
|
||||
HeroCreate,
|
||||
|
|
@ -19,6 +17,8 @@ from learn_sql_model.models.hero import (
|
|||
|
||||
hero_app = typer.Typer()
|
||||
|
||||
config = get_config()
|
||||
|
||||
|
||||
@hero_app.callback()
|
||||
def hero():
|
||||
|
|
@ -28,12 +28,10 @@ def hero():
|
|||
@hero_app.command()
|
||||
@engorgio(typer=True)
|
||||
def get(
|
||||
id: Optional[int] = typer.Argument(default=None),
|
||||
config: Config = None,
|
||||
hero_id: Optional[int] = typer.Argument(default=None),
|
||||
) -> Union[Hero, List[Hero]]:
|
||||
"get one hero"
|
||||
config.init()
|
||||
hero = HeroRead.get(id=id, config=config)
|
||||
hero = HeroRead.get(id=hero_id)
|
||||
Console().print(hero)
|
||||
return hero
|
||||
|
||||
|
|
@ -42,12 +40,11 @@ def get(
|
|||
@engorgio(typer=True)
|
||||
def list(
|
||||
where: Optional[str] = None,
|
||||
config: Config = None,
|
||||
offset: int = 0,
|
||||
limit: Optional[int] = None,
|
||||
) -> Union[Hero, List[Hero]]:
|
||||
"get one hero"
|
||||
hero = HeroRead.list(config=config, where=where, offset=offset, limit=limit)
|
||||
"list many heros"
|
||||
hero = HeroRead.list(where=where, offset=offset, limit=limit)
|
||||
Console().print(hero)
|
||||
return hero
|
||||
|
||||
|
|
@ -56,65 +53,39 @@ def list(
|
|||
@engorgio(typer=True)
|
||||
def create(
|
||||
hero: HeroCreate,
|
||||
config: Config = None,
|
||||
) -> Hero:
|
||||
"read all the heros"
|
||||
|
||||
r = httpx.post(
|
||||
f"{config.api_client.url}/hero/",
|
||||
json=hero.dict(),
|
||||
)
|
||||
if r.status_code != 200:
|
||||
raise RuntimeError(f"{r.status_code}:\n {r.text}")
|
||||
|
||||
# hero = hero.post(config=config)
|
||||
# Console().print(hero)
|
||||
# return hero
|
||||
"create one hero"
|
||||
hero.post()
|
||||
|
||||
|
||||
@hero_app.command()
|
||||
@engorgio(typer=True)
|
||||
def update(
|
||||
hero: HeroUpdate,
|
||||
config: Config = None,
|
||||
) -> Hero:
|
||||
"read all the heros"
|
||||
r = httpx.patch(
|
||||
f"{config.api_client.url}/hero/",
|
||||
json=hero.dict(),
|
||||
)
|
||||
if r.status_code != 200:
|
||||
raise RuntimeError(f"{r.status_code}:\n {r.text}")
|
||||
"update one hero"
|
||||
hero.update()
|
||||
|
||||
|
||||
@hero_app.command()
|
||||
@engorgio(typer=True)
|
||||
def delete(
|
||||
hero: HeroDelete,
|
||||
config: Config = None,
|
||||
) -> Hero:
|
||||
"read all the heros"
|
||||
r = httpx.delete(
|
||||
f"{config.api_client.url}/hero/{hero.id}",
|
||||
)
|
||||
if r.status_code != 200:
|
||||
raise RuntimeError(f"{r.status_code}:\n {r.text}")
|
||||
"delete a hero by id"
|
||||
hero.delete()
|
||||
|
||||
|
||||
@hero_app.command()
|
||||
@engorgio(typer=True)
|
||||
def populate(
|
||||
hero: Hero,
|
||||
n: int = 10,
|
||||
) -> Hero:
|
||||
"read all the heros"
|
||||
config = get_config()
|
||||
"Create n number of heros"
|
||||
if config.env == "prod":
|
||||
Console().print("populate is not supported in production")
|
||||
sys.exit(1)
|
||||
|
||||
for hero in HeroFactory().batch(n):
|
||||
pet = PetFactory().build()
|
||||
hero.pet = pet
|
||||
Console().print(hero)
|
||||
hero.post(config=config)
|
||||
hero = HeroCreate(**hero.dict())
|
||||
hero.post()
|
||||
|
|
|
|||
|
|
@ -44,7 +44,6 @@ def create_revision(
|
|||
prompt=True,
|
||||
),
|
||||
):
|
||||
|
||||
alembic_cfg = Config("alembic.ini")
|
||||
alembic.command.revision(
|
||||
config=alembic_cfg,
|
||||
|
|
@ -63,7 +62,6 @@ def checkout(
|
|||
),
|
||||
revision: str = typer.Option("head"),
|
||||
):
|
||||
|
||||
alembic_cfg = Config("alembic.ini")
|
||||
alembic.command.upgrade(config=alembic_cfg, revision="head")
|
||||
|
||||
|
|
|
|||
|
|
@ -1,107 +0,0 @@
|
|||
import sys
|
||||
from typing import List, Optional, Union
|
||||
|
||||
from engorgio import engorgio
|
||||
from rich.console import Console
|
||||
import typer
|
||||
|
||||
from learn_sql_model.config import Config, get_config
|
||||
from learn_sql_model.factories.new import newFactory
|
||||
from learn_sql_model.factories.pet import PetFactory
|
||||
from learn_sql_model.models.new import (
|
||||
new,
|
||||
newCreate,
|
||||
newDelete,
|
||||
newRead,
|
||||
newUpdate,
|
||||
)
|
||||
|
||||
new_app = typer.Typer()
|
||||
|
||||
|
||||
@new_app.callback()
|
||||
def new():
|
||||
"model cli"
|
||||
|
||||
|
||||
@new_app.command()
|
||||
@engorgio(typer=True)
|
||||
def get(
|
||||
id: Optional[int] = typer.Argument(default=None),
|
||||
config: Config = None,
|
||||
) -> Union[new, List[new]]:
|
||||
"get one new"
|
||||
config.init()
|
||||
new = newRead.get(id=id, config=config)
|
||||
Console().print(new)
|
||||
return new
|
||||
|
||||
|
||||
@new_app.command()
|
||||
@engorgio(typer=True)
|
||||
def list(
|
||||
where: Optional[str] = None,
|
||||
config: Config = None,
|
||||
offset: int = 0,
|
||||
limit: Optional[int] = None,
|
||||
) -> Union[new, List[new]]:
|
||||
"get one new"
|
||||
new = newRead.list(config=config, where=where, offset=offset, limit=limit)
|
||||
Console().print(new)
|
||||
return new
|
||||
|
||||
|
||||
@new_app.command()
|
||||
@engorgio(typer=True)
|
||||
def create(
|
||||
new: newCreate,
|
||||
config: Config = None,
|
||||
) -> new:
|
||||
"read all the news"
|
||||
# config.init()
|
||||
new = new.post(config=config)
|
||||
Console().print(new)
|
||||
return new
|
||||
|
||||
|
||||
@new_app.command()
|
||||
@engorgio(typer=True)
|
||||
def update(
|
||||
new: newUpdate,
|
||||
config: Config = None,
|
||||
) -> new:
|
||||
"read all the news"
|
||||
new = new.update(config=config)
|
||||
Console().print(new)
|
||||
return new
|
||||
|
||||
|
||||
@new_app.command()
|
||||
@engorgio(typer=True)
|
||||
def delete(
|
||||
new: newDelete,
|
||||
config: Config = None,
|
||||
) -> new:
|
||||
"read all the news"
|
||||
# config.init()
|
||||
new = new.delete(config=config)
|
||||
return new
|
||||
|
||||
|
||||
@new_app.command()
|
||||
@engorgio(typer=True)
|
||||
def populate(
|
||||
new: new,
|
||||
n: int = 10,
|
||||
) -> new:
|
||||
"read all the news"
|
||||
config = get_config()
|
||||
if config.env == "prod":
|
||||
Console().print("populate is not supported in production")
|
||||
sys.exit(1)
|
||||
|
||||
for new in newFactory().batch(n):
|
||||
pet = PetFactory().build()
|
||||
new.pet = pet
|
||||
Console().print(new)
|
||||
new.post(config=config)
|
||||
Loading…
Add table
Add a link
Reference in a new issue