FastAPI-fastkit 1.0.0__py3-none-any.whl → 1.0.2__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- fastapi_fastkit/__init__.py +10 -1
- fastapi_fastkit/backend/main.py +482 -482
- fastapi_fastkit/backend/transducer.py +106 -106
- fastapi_fastkit/cli.py +664 -631
- fastapi_fastkit/core/settings.py +155 -155
- fastapi_fastkit/fastapi_project_template/README.md +90 -90
- fastapi_fastkit/fastapi_project_template/fastapi-async-crud/.env-tpl +1 -1
- fastapi_fastkit/fastapi_project_template/fastapi-async-crud/.gitignore-tpl +30 -30
- fastapi_fastkit/fastapi_project_template/fastapi-async-crud/README.md-tpl +107 -107
- fastapi_fastkit/fastapi_project_template/fastapi-async-crud/requirements.txt-tpl +36 -36
- fastapi_fastkit/fastapi_project_template/fastapi-async-crud/scripts/format.sh-tpl +5 -5
- fastapi_fastkit/fastapi_project_template/fastapi-async-crud/scripts/lint.sh-tpl +5 -5
- fastapi_fastkit/fastapi_project_template/fastapi-async-crud/scripts/run-server.sh-tpl +8 -8
- fastapi_fastkit/fastapi_project_template/fastapi-async-crud/scripts/test.sh-tpl +6 -6
- fastapi_fastkit/fastapi_project_template/fastapi-async-crud/setup.cfg-tpl +14 -14
- fastapi_fastkit/fastapi_project_template/fastapi-async-crud/setup.py-tpl +25 -25
- fastapi_fastkit/fastapi_project_template/fastapi-async-crud/src/api/api.py-tpl +9 -9
- fastapi_fastkit/fastapi_project_template/fastapi-async-crud/src/api/routes/items.py-tpl +57 -57
- fastapi_fastkit/fastapi_project_template/fastapi-async-crud/src/core/config.py-tpl +64 -64
- fastapi_fastkit/fastapi_project_template/fastapi-async-crud/src/crud/items.py-tpl +21 -21
- fastapi_fastkit/fastapi_project_template/fastapi-async-crud/src/main.py-tpl +26 -26
- fastapi_fastkit/fastapi_project_template/fastapi-async-crud/src/mocks/mock_items.json-tpl +8 -8
- fastapi_fastkit/fastapi_project_template/fastapi-async-crud/src/schemas/items.py-tpl +22 -22
- fastapi_fastkit/fastapi_project_template/fastapi-async-crud/tests/conftest.py-tpl +42 -42
- fastapi_fastkit/fastapi_project_template/fastapi-async-crud/tests/test_items.py-tpl +48 -48
- fastapi_fastkit/fastapi_project_template/fastapi-custom-response/.env-tpl +1 -1
- fastapi_fastkit/fastapi_project_template/fastapi-custom-response/.gitignore-tpl +191 -191
- fastapi_fastkit/fastapi_project_template/fastapi-custom-response/README.md-tpl +156 -156
- fastapi_fastkit/fastapi_project_template/fastapi-custom-response/requirements.txt-tpl +36 -36
- fastapi_fastkit/fastapi_project_template/fastapi-custom-response/scripts/format.sh-tpl +5 -5
- fastapi_fastkit/fastapi_project_template/fastapi-custom-response/scripts/lint.sh-tpl +5 -5
- fastapi_fastkit/fastapi_project_template/fastapi-custom-response/scripts/run-server.sh-tpl +8 -8
- fastapi_fastkit/fastapi_project_template/fastapi-custom-response/scripts/test.sh-tpl +6 -6
- fastapi_fastkit/fastapi_project_template/fastapi-custom-response/setup.cfg-tpl +12 -12
- fastapi_fastkit/fastapi_project_template/fastapi-custom-response/setup.py-tpl +27 -27
- fastapi_fastkit/fastapi_project_template/fastapi-custom-response/src/.DS_Store +0 -0
- fastapi_fastkit/fastapi_project_template/fastapi-custom-response/src/api/api.py-tpl +9 -9
- fastapi_fastkit/fastapi_project_template/fastapi-custom-response/src/api/routes/items.py-tpl +172 -172
- fastapi_fastkit/fastapi_project_template/fastapi-custom-response/src/core/config.py-tpl +64 -64
- fastapi_fastkit/fastapi_project_template/fastapi-custom-response/src/crud/items.py-tpl +21 -21
- fastapi_fastkit/fastapi_project_template/fastapi-custom-response/src/helper/exceptions.py-tpl +103 -103
- fastapi_fastkit/fastapi_project_template/fastapi-custom-response/src/helper/pagination.py-tpl +72 -72
- fastapi_fastkit/fastapi_project_template/fastapi-custom-response/src/main.py-tpl +39 -39
- fastapi_fastkit/fastapi_project_template/fastapi-custom-response/src/mocks/mock_items.json-tpl +8 -8
- fastapi_fastkit/fastapi_project_template/fastapi-custom-response/src/schemas/base.py-tpl +49 -49
- fastapi_fastkit/fastapi_project_template/fastapi-custom-response/src/schemas/items.py-tpl +22 -22
- fastapi_fastkit/fastapi_project_template/fastapi-custom-response/src/utils/documents.py-tpl +20 -20
- fastapi_fastkit/fastapi_project_template/fastapi-custom-response/tests/conftest.py-tpl +42 -42
- fastapi_fastkit/fastapi_project_template/fastapi-custom-response/tests/test_items.py-tpl +61 -61
- fastapi_fastkit/fastapi_project_template/fastapi-default/README.md-tpl +101 -101
- fastapi_fastkit/fastapi_project_template/fastapi-default/scripts/run-server.sh-tpl +8 -8
- fastapi_fastkit/fastapi_project_template/fastapi-default/setup.py-tpl +22 -22
- fastapi_fastkit/fastapi_project_template/fastapi-default/src/mocks/mock_items.json-tpl +8 -8
- fastapi_fastkit/fastapi_project_template/fastapi-default/tests/conftest.py-tpl +30 -30
- fastapi_fastkit/fastapi_project_template/fastapi-default/tests/test_items.py-tpl +44 -44
- fastapi_fastkit/fastapi_project_template/fastapi-dockerized/.env-tpl +1 -1
- fastapi_fastkit/fastapi_project_template/fastapi-dockerized/.gitignore-tpl +30 -30
- fastapi_fastkit/fastapi_project_template/fastapi-dockerized/Dockerfile-tpl +23 -23
- fastapi_fastkit/fastapi_project_template/fastapi-dockerized/README.md-tpl +119 -119
- fastapi_fastkit/fastapi_project_template/fastapi-dockerized/requirements.txt-tpl +36 -36
- fastapi_fastkit/fastapi_project_template/fastapi-dockerized/scripts/format.sh-tpl +5 -5
- fastapi_fastkit/fastapi_project_template/fastapi-dockerized/scripts/lint.sh-tpl +5 -5
- fastapi_fastkit/fastapi_project_template/fastapi-dockerized/scripts/run-server.sh-tpl +8 -8
- fastapi_fastkit/fastapi_project_template/fastapi-dockerized/scripts/test.sh-tpl +6 -6
- fastapi_fastkit/fastapi_project_template/fastapi-dockerized/setup.cfg-tpl +13 -13
- fastapi_fastkit/fastapi_project_template/fastapi-dockerized/setup.py-tpl +22 -22
- fastapi_fastkit/fastapi_project_template/fastapi-dockerized/src/api/api.py-tpl +6 -6
- fastapi_fastkit/fastapi_project_template/fastapi-dockerized/src/api/routes/items.py-tpl +54 -54
- fastapi_fastkit/fastapi_project_template/fastapi-dockerized/src/core/config.py-tpl +64 -64
- fastapi_fastkit/fastapi_project_template/fastapi-dockerized/src/crud/items.py-tpl +15 -15
- fastapi_fastkit/fastapi_project_template/fastapi-dockerized/src/main.py-tpl +26 -26
- fastapi_fastkit/fastapi_project_template/fastapi-dockerized/src/mocks/mock_items.json-tpl +8 -8
- fastapi_fastkit/fastapi_project_template/fastapi-dockerized/src/schemas/items.py-tpl +19 -19
- fastapi_fastkit/fastapi_project_template/fastapi-dockerized/tests/conftest.py-tpl +30 -30
- fastapi_fastkit/fastapi_project_template/fastapi-dockerized/tests/test_items.py-tpl +44 -44
- fastapi_fastkit/fastapi_project_template/fastapi-empty/.env-tpl +1 -1
- fastapi_fastkit/fastapi_project_template/fastapi-empty/setup.py-tpl +22 -22
- fastapi_fastkit/fastapi_project_template/fastapi-empty/src/core/config.py-tpl +75 -75
- fastapi_fastkit/fastapi_project_template/fastapi-empty/src/main.py-tpl +36 -36
- fastapi_fastkit/fastapi_project_template/fastapi-psql-orm/.env-tpl +9 -9
- fastapi_fastkit/fastapi_project_template/fastapi-psql-orm/.gitignore-tpl +30 -30
- fastapi_fastkit/fastapi_project_template/fastapi-psql-orm/Dockerfile-tpl +23 -23
- fastapi_fastkit/fastapi_project_template/fastapi-psql-orm/README.md-tpl +144 -144
- fastapi_fastkit/fastapi_project_template/fastapi-psql-orm/alembic.ini-tpl +119 -119
- fastapi_fastkit/fastapi_project_template/fastapi-psql-orm/docker-compose.yml-tpl +44 -44
- fastapi_fastkit/fastapi_project_template/fastapi-psql-orm/requirements.txt-tpl +41 -41
- fastapi_fastkit/fastapi_project_template/fastapi-psql-orm/scripts/format.sh-tpl +5 -5
- fastapi_fastkit/fastapi_project_template/fastapi-psql-orm/scripts/lint.sh-tpl +5 -5
- fastapi_fastkit/fastapi_project_template/fastapi-psql-orm/scripts/pre-start.sh-tpl +16 -16
- fastapi_fastkit/fastapi_project_template/fastapi-psql-orm/scripts/run-server.sh-tpl +8 -8
- fastapi_fastkit/fastapi_project_template/fastapi-psql-orm/scripts/test.sh-tpl +10 -10
- fastapi_fastkit/fastapi_project_template/fastapi-psql-orm/setup.cfg-tpl +13 -13
- fastapi_fastkit/fastapi_project_template/fastapi-psql-orm/setup.py-tpl +25 -25
- fastapi_fastkit/fastapi_project_template/fastapi-psql-orm/src/alembic/README-tpl +1 -1
- fastapi_fastkit/fastapi_project_template/fastapi-psql-orm/src/alembic/env.py-tpl +85 -85
- fastapi_fastkit/fastapi_project_template/fastapi-psql-orm/src/alembic/script.py.mako-tpl +26 -26
- fastapi_fastkit/fastapi_project_template/fastapi-psql-orm/src/alembic/versions/bedcdc35b64a_first_alembic.py-tpl +37 -37
- fastapi_fastkit/fastapi_project_template/fastapi-psql-orm/src/api/api.py-tpl +11 -11
- fastapi_fastkit/fastapi_project_template/fastapi-psql-orm/src/api/deps.py-tpl +19 -19
- fastapi_fastkit/fastapi_project_template/fastapi-psql-orm/src/api/routes/items.py-tpl +109 -109
- fastapi_fastkit/fastapi_project_template/fastapi-psql-orm/src/core/config.py-tpl +88 -88
- fastapi_fastkit/fastapi_project_template/fastapi-psql-orm/src/core/db.py-tpl +53 -53
- fastapi_fastkit/fastapi_project_template/fastapi-psql-orm/src/crud/items.py-tpl +102 -102
- fastapi_fastkit/fastapi_project_template/fastapi-psql-orm/src/main.py-tpl +45 -45
- fastapi_fastkit/fastapi_project_template/fastapi-psql-orm/src/schemas/items.py-tpl +54 -54
- fastapi_fastkit/fastapi_project_template/fastapi-psql-orm/src/utils/backend_pre_start.py-tpl +39 -39
- fastapi_fastkit/fastapi_project_template/fastapi-psql-orm/src/utils/init_data.py-tpl +23 -23
- fastapi_fastkit/fastapi_project_template/fastapi-psql-orm/src/utils/tests_pre_start.py-tpl +39 -39
- fastapi_fastkit/fastapi_project_template/fastapi-psql-orm/tests/conftest.py-tpl +63 -63
- fastapi_fastkit/fastapi_project_template/fastapi-psql-orm/tests/test_items.py-tpl +44 -44
- fastapi_fastkit/fastapi_project_template/modules/api/routes/new_route.py-tpl +64 -64
- fastapi_fastkit/fastapi_project_template/modules/crud/new_route.py-tpl +29 -29
- fastapi_fastkit/fastapi_project_template/modules/schemas/new_route.py-tpl +23 -23
- fastapi_fastkit/logs/fastkit_debug_20250702_161423.log +21 -0
- fastapi_fastkit/logs/fastkit_debug_20250702_162706.log +20 -0
- fastapi_fastkit/logs/fastkit_debug_20250702_163010.log +21 -0
- fastapi_fastkit/logs/fastkit_debug_20250702_163526.log +21 -0
- fastapi_fastkit/logs/fastkit_debug_20250702_164053.log +21 -0
- fastapi_fastkit/logs/fastkit_debug_20250702_165220.log +21 -0
- fastapi_fastkit/logs/fastkit_debug_20250702_165647.log +21 -0
- fastapi_fastkit/utils/logging.py +112 -1
- fastapi_fastkit/utils/main.py +140 -129
- fastapi_fastkit-1.0.2.dist-info/METADATA +320 -0
- {fastapi_fastkit-1.0.0.dist-info → fastapi_fastkit-1.0.2.dist-info}/RECORD +127 -119
- {fastapi_fastkit-1.0.0.dist-info → fastapi_fastkit-1.0.2.dist-info}/WHEEL +1 -1
- {fastapi_fastkit-1.0.0.dist-info → fastapi_fastkit-1.0.2.dist-info}/licenses/LICENSE +21 -21
- fastapi_fastkit-1.0.0.dist-info/METADATA +0 -208
- {fastapi_fastkit-1.0.0.dist-info → fastapi_fastkit-1.0.2.dist-info}/entry_points.txt +0 -0
|
@@ -1,85 +1,85 @@
|
|
|
1
|
-
import os
|
|
2
|
-
from logging.config import fileConfig
|
|
3
|
-
|
|
4
|
-
from sqlalchemy import engine_from_config, pool
|
|
5
|
-
|
|
6
|
-
from alembic import context
|
|
7
|
-
|
|
8
|
-
# this is the Alembic Config object, which provides
|
|
9
|
-
# access to the values within the .ini file in use.
|
|
10
|
-
config = context.config
|
|
11
|
-
|
|
12
|
-
# Interpret the config file for Python logging.
|
|
13
|
-
# This line sets up loggers basically.
|
|
14
|
-
fileConfig(config.config_file_name) # type: ignore
|
|
15
|
-
|
|
16
|
-
# add your model's MetaData object here
|
|
17
|
-
# for 'autogenerate' support
|
|
18
|
-
# from myapp import mymodel
|
|
19
|
-
# target_metadata = mymodel.Base.metadata
|
|
20
|
-
# target_metadata = None
|
|
21
|
-
|
|
22
|
-
from src.core.config import settings # noqa
|
|
23
|
-
from src.schemas.items import SQLModel # noqa
|
|
24
|
-
|
|
25
|
-
target_metadata = SQLModel.metadata
|
|
26
|
-
|
|
27
|
-
# other values from the config, defined by the needs of env.py,
|
|
28
|
-
# can be acquired:
|
|
29
|
-
# my_important_option = config.get_main_option("my_important_option")
|
|
30
|
-
# ... etc.
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
def get_url():
|
|
34
|
-
return str(settings.SQLALCHEMY_DATABASE_URI)
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
def run_migrations_offline():
|
|
38
|
-
"""Run migrations in 'offline' mode.
|
|
39
|
-
|
|
40
|
-
This configures the context with just a URL
|
|
41
|
-
and not an Engine, though an Engine is acceptable
|
|
42
|
-
here as well. By skipping the Engine creation
|
|
43
|
-
we don't even need a DBAPI to be available.
|
|
44
|
-
|
|
45
|
-
Calls to context.execute() here emit the given string to the
|
|
46
|
-
script output.
|
|
47
|
-
|
|
48
|
-
"""
|
|
49
|
-
url = get_url()
|
|
50
|
-
context.configure(
|
|
51
|
-
url=url, target_metadata=target_metadata, literal_binds=True, compare_type=True
|
|
52
|
-
)
|
|
53
|
-
|
|
54
|
-
with context.begin_transaction():
|
|
55
|
-
context.run_migrations()
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
def run_migrations_online():
|
|
59
|
-
"""Run migrations in 'online' mode.
|
|
60
|
-
|
|
61
|
-
In this scenario we need to create an Engine
|
|
62
|
-
and associate a connection with the context.
|
|
63
|
-
|
|
64
|
-
"""
|
|
65
|
-
configuration = config.get_section(config.config_ini_section)
|
|
66
|
-
configuration["sqlalchemy.url"] = get_url()
|
|
67
|
-
connectable = engine_from_config(
|
|
68
|
-
configuration,
|
|
69
|
-
prefix="sqlalchemy.",
|
|
70
|
-
poolclass=pool.NullPool,
|
|
71
|
-
)
|
|
72
|
-
|
|
73
|
-
with connectable.connect() as connection:
|
|
74
|
-
context.configure(
|
|
75
|
-
connection=connection, target_metadata=target_metadata, compare_type=True
|
|
76
|
-
)
|
|
77
|
-
|
|
78
|
-
with context.begin_transaction():
|
|
79
|
-
context.run_migrations()
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
if context.is_offline_mode():
|
|
83
|
-
run_migrations_offline()
|
|
84
|
-
else:
|
|
85
|
-
run_migrations_online()
|
|
1
|
+
import os
|
|
2
|
+
from logging.config import fileConfig
|
|
3
|
+
|
|
4
|
+
from sqlalchemy import engine_from_config, pool
|
|
5
|
+
|
|
6
|
+
from alembic import context
|
|
7
|
+
|
|
8
|
+
# this is the Alembic Config object, which provides
|
|
9
|
+
# access to the values within the .ini file in use.
|
|
10
|
+
config = context.config
|
|
11
|
+
|
|
12
|
+
# Interpret the config file for Python logging.
|
|
13
|
+
# This line sets up loggers basically.
|
|
14
|
+
fileConfig(config.config_file_name) # type: ignore
|
|
15
|
+
|
|
16
|
+
# add your model's MetaData object here
|
|
17
|
+
# for 'autogenerate' support
|
|
18
|
+
# from myapp import mymodel
|
|
19
|
+
# target_metadata = mymodel.Base.metadata
|
|
20
|
+
# target_metadata = None
|
|
21
|
+
|
|
22
|
+
from src.core.config import settings # noqa
|
|
23
|
+
from src.schemas.items import SQLModel # noqa
|
|
24
|
+
|
|
25
|
+
target_metadata = SQLModel.metadata
|
|
26
|
+
|
|
27
|
+
# other values from the config, defined by the needs of env.py,
|
|
28
|
+
# can be acquired:
|
|
29
|
+
# my_important_option = config.get_main_option("my_important_option")
|
|
30
|
+
# ... etc.
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def get_url():
|
|
34
|
+
return str(settings.SQLALCHEMY_DATABASE_URI)
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def run_migrations_offline():
|
|
38
|
+
"""Run migrations in 'offline' mode.
|
|
39
|
+
|
|
40
|
+
This configures the context with just a URL
|
|
41
|
+
and not an Engine, though an Engine is acceptable
|
|
42
|
+
here as well. By skipping the Engine creation
|
|
43
|
+
we don't even need a DBAPI to be available.
|
|
44
|
+
|
|
45
|
+
Calls to context.execute() here emit the given string to the
|
|
46
|
+
script output.
|
|
47
|
+
|
|
48
|
+
"""
|
|
49
|
+
url = get_url()
|
|
50
|
+
context.configure(
|
|
51
|
+
url=url, target_metadata=target_metadata, literal_binds=True, compare_type=True
|
|
52
|
+
)
|
|
53
|
+
|
|
54
|
+
with context.begin_transaction():
|
|
55
|
+
context.run_migrations()
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def run_migrations_online():
|
|
59
|
+
"""Run migrations in 'online' mode.
|
|
60
|
+
|
|
61
|
+
In this scenario we need to create an Engine
|
|
62
|
+
and associate a connection with the context.
|
|
63
|
+
|
|
64
|
+
"""
|
|
65
|
+
configuration = config.get_section(config.config_ini_section)
|
|
66
|
+
configuration["sqlalchemy.url"] = get_url()
|
|
67
|
+
connectable = engine_from_config(
|
|
68
|
+
configuration,
|
|
69
|
+
prefix="sqlalchemy.",
|
|
70
|
+
poolclass=pool.NullPool,
|
|
71
|
+
)
|
|
72
|
+
|
|
73
|
+
with connectable.connect() as connection:
|
|
74
|
+
context.configure(
|
|
75
|
+
connection=connection, target_metadata=target_metadata, compare_type=True
|
|
76
|
+
)
|
|
77
|
+
|
|
78
|
+
with context.begin_transaction():
|
|
79
|
+
context.run_migrations()
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
if context.is_offline_mode():
|
|
83
|
+
run_migrations_offline()
|
|
84
|
+
else:
|
|
85
|
+
run_migrations_online()
|
|
@@ -1,26 +1,26 @@
|
|
|
1
|
-
"""${message}
|
|
2
|
-
|
|
3
|
-
Revision ID: ${up_revision}
|
|
4
|
-
Revises: ${down_revision | comma,n}
|
|
5
|
-
Create Date: ${create_date}
|
|
6
|
-
|
|
7
|
-
"""
|
|
8
|
-
from typing import Sequence, Union
|
|
9
|
-
|
|
10
|
-
from alembic import op
|
|
11
|
-
import sqlalchemy as sa
|
|
12
|
-
${imports if imports else ""}
|
|
13
|
-
|
|
14
|
-
# revision identifiers, used by Alembic.
|
|
15
|
-
revision: str = ${repr(up_revision)}
|
|
16
|
-
down_revision: Union[str, None] = ${repr(down_revision)}
|
|
17
|
-
branch_labels: Union[str, Sequence[str], None] = ${repr(branch_labels)}
|
|
18
|
-
depends_on: Union[str, Sequence[str], None] = ${repr(depends_on)}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
def upgrade() -> None:
|
|
22
|
-
${upgrades if upgrades else "pass"}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
def downgrade() -> None:
|
|
26
|
-
${downgrades if downgrades else "pass"}
|
|
1
|
+
"""${message}
|
|
2
|
+
|
|
3
|
+
Revision ID: ${up_revision}
|
|
4
|
+
Revises: ${down_revision | comma,n}
|
|
5
|
+
Create Date: ${create_date}
|
|
6
|
+
|
|
7
|
+
"""
|
|
8
|
+
from typing import Sequence, Union
|
|
9
|
+
|
|
10
|
+
from alembic import op
|
|
11
|
+
import sqlalchemy as sa
|
|
12
|
+
${imports if imports else ""}
|
|
13
|
+
|
|
14
|
+
# revision identifiers, used by Alembic.
|
|
15
|
+
revision: str = ${repr(up_revision)}
|
|
16
|
+
down_revision: Union[str, None] = ${repr(down_revision)}
|
|
17
|
+
branch_labels: Union[str, Sequence[str], None] = ${repr(branch_labels)}
|
|
18
|
+
depends_on: Union[str, Sequence[str], None] = ${repr(depends_on)}
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def upgrade() -> None:
|
|
22
|
+
${upgrades if upgrades else "pass"}
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def downgrade() -> None:
|
|
26
|
+
${downgrades if downgrades else "pass"}
|
|
@@ -1,37 +1,37 @@
|
|
|
1
|
-
"""first alembic
|
|
2
|
-
|
|
3
|
-
Revision ID: bedcdc35b64a
|
|
4
|
-
Revises:
|
|
5
|
-
Create Date: 2025-03-01 17:00:43.670130
|
|
6
|
-
|
|
7
|
-
"""
|
|
8
|
-
from typing import Sequence, Union
|
|
9
|
-
|
|
10
|
-
from alembic import op
|
|
11
|
-
import sqlalchemy as sa
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
# revision identifiers, used by Alembic.
|
|
15
|
-
revision: str = 'bedcdc35b64a'
|
|
16
|
-
down_revision: Union[str, None] = None
|
|
17
|
-
branch_labels: Union[str, Sequence[str], None] = None
|
|
18
|
-
depends_on: Union[str, Sequence[str], None] = None
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
def upgrade() -> None:
|
|
22
|
-
# ### commands auto generated by Alembic - please adjust! ###
|
|
23
|
-
op.create_table('items',
|
|
24
|
-
sa.Column('id', sa.Integer(), nullable=False),
|
|
25
|
-
sa.Column('name', sa.String(), nullable=False),
|
|
26
|
-
sa.Column('description', sa.String(), nullable=True),
|
|
27
|
-
sa.Column('price', sa.Float(), nullable=False),
|
|
28
|
-
sa.Column('category', sa.String(), nullable=False),
|
|
29
|
-
sa.PrimaryKeyConstraint('id')
|
|
30
|
-
)
|
|
31
|
-
# ### end Alembic commands ###
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
def downgrade() -> None:
|
|
35
|
-
# ### commands auto generated by Alembic - please adjust! ###
|
|
36
|
-
op.drop_table('items')
|
|
37
|
-
# ### end Alembic commands ###
|
|
1
|
+
"""first alembic
|
|
2
|
+
|
|
3
|
+
Revision ID: bedcdc35b64a
|
|
4
|
+
Revises:
|
|
5
|
+
Create Date: 2025-03-01 17:00:43.670130
|
|
6
|
+
|
|
7
|
+
"""
|
|
8
|
+
from typing import Sequence, Union
|
|
9
|
+
|
|
10
|
+
from alembic import op
|
|
11
|
+
import sqlalchemy as sa
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
# revision identifiers, used by Alembic.
|
|
15
|
+
revision: str = 'bedcdc35b64a'
|
|
16
|
+
down_revision: Union[str, None] = None
|
|
17
|
+
branch_labels: Union[str, Sequence[str], None] = None
|
|
18
|
+
depends_on: Union[str, Sequence[str], None] = None
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def upgrade() -> None:
|
|
22
|
+
# ### commands auto generated by Alembic - please adjust! ###
|
|
23
|
+
op.create_table('items',
|
|
24
|
+
sa.Column('id', sa.Integer(), nullable=False),
|
|
25
|
+
sa.Column('name', sa.String(), nullable=False),
|
|
26
|
+
sa.Column('description', sa.String(), nullable=True),
|
|
27
|
+
sa.Column('price', sa.Float(), nullable=False),
|
|
28
|
+
sa.Column('category', sa.String(), nullable=False),
|
|
29
|
+
sa.PrimaryKeyConstraint('id')
|
|
30
|
+
)
|
|
31
|
+
# ### end Alembic commands ###
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def downgrade() -> None:
|
|
35
|
+
# ### commands auto generated by Alembic - please adjust! ###
|
|
36
|
+
op.drop_table('items')
|
|
37
|
+
# ### end Alembic commands ###
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
# --------------------------------------------------------------------------
|
|
2
|
-
# API router connector module
|
|
3
|
-
# --------------------------------------------------------------------------
|
|
4
|
-
|
|
5
|
-
from fastapi import APIRouter
|
|
6
|
-
|
|
7
|
-
from src.api.routes import items
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
api_router = APIRouter()
|
|
11
|
-
api_router.include_router(items.router)
|
|
1
|
+
# --------------------------------------------------------------------------
|
|
2
|
+
# API router connector module
|
|
3
|
+
# --------------------------------------------------------------------------
|
|
4
|
+
|
|
5
|
+
from fastapi import APIRouter
|
|
6
|
+
|
|
7
|
+
from src.api.routes import items
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
api_router = APIRouter()
|
|
11
|
+
api_router.include_router(items.router)
|
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
# --------------------------------------------------------------------------
|
|
2
|
-
# API router session dependency module
|
|
3
|
-
# --------------------------------------------------------------------------
|
|
4
|
-
from collections.abc import Generator
|
|
5
|
-
|
|
6
|
-
from sqlmodel import Session
|
|
7
|
-
|
|
8
|
-
from src.core.db import engine
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
def get_db() -> Generator[Session, None, None]:
|
|
12
|
-
"""
|
|
13
|
-
Dependency for database session.
|
|
14
|
-
|
|
15
|
-
Yields:
|
|
16
|
-
Database session that will be automatically closed after request completion
|
|
17
|
-
"""
|
|
18
|
-
with Session(engine) as session:
|
|
19
|
-
yield session
|
|
1
|
+
# --------------------------------------------------------------------------
|
|
2
|
+
# API router session dependency module
|
|
3
|
+
# --------------------------------------------------------------------------
|
|
4
|
+
from collections.abc import Generator
|
|
5
|
+
|
|
6
|
+
from sqlmodel import Session
|
|
7
|
+
|
|
8
|
+
from src.core.db import engine
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def get_db() -> Generator[Session, None, None]:
|
|
12
|
+
"""
|
|
13
|
+
Dependency for database session.
|
|
14
|
+
|
|
15
|
+
Yields:
|
|
16
|
+
Database session that will be automatically closed after request completion
|
|
17
|
+
"""
|
|
18
|
+
with Session(engine) as session:
|
|
19
|
+
yield session
|
|
@@ -1,109 +1,109 @@
|
|
|
1
|
-
# --------------------------------------------------------------------------
|
|
2
|
-
# Item CRUD Endpoint
|
|
3
|
-
# --------------------------------------------------------------------------
|
|
4
|
-
from typing import List
|
|
5
|
-
from collections.abc import Generator
|
|
6
|
-
|
|
7
|
-
from fastapi import APIRouter, Depends, HTTPException
|
|
8
|
-
from sqlmodel import Session
|
|
9
|
-
|
|
10
|
-
from src.api.deps import get_db
|
|
11
|
-
from src.crud.items import create_item, delete_item, get_item, get_items, update_item
|
|
12
|
-
from src.schemas.items import ItemBase, ItemCreate, ItemResponse
|
|
13
|
-
|
|
14
|
-
router = APIRouter()
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
@router.get("/items", response_model=List[ItemResponse])
|
|
18
|
-
def read_items(skip: int = 0, limit: int = 100, db: Session = Depends(get_db)):
|
|
19
|
-
"""
|
|
20
|
-
Retrieve a list of items with optional pagination.
|
|
21
|
-
|
|
22
|
-
Args:
|
|
23
|
-
skip: Number of records to skip
|
|
24
|
-
limit: Maximum number of records to return
|
|
25
|
-
db: Database session dependency
|
|
26
|
-
|
|
27
|
-
Returns:
|
|
28
|
-
List of items
|
|
29
|
-
"""
|
|
30
|
-
return get_items(db, skip=skip, limit=limit)
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
@router.get("/items/{item_id}", response_model=ItemResponse)
|
|
34
|
-
def read_item(item_id: int, db: Session = Depends(get_db)):
|
|
35
|
-
"""
|
|
36
|
-
Retrieve a specific item by ID.
|
|
37
|
-
|
|
38
|
-
Args:
|
|
39
|
-
item_id: ID of the item to retrieve
|
|
40
|
-
db: Database session dependency
|
|
41
|
-
|
|
42
|
-
Returns:
|
|
43
|
-
The requested item
|
|
44
|
-
|
|
45
|
-
Raises:
|
|
46
|
-
HTTPException: If item is not found
|
|
47
|
-
"""
|
|
48
|
-
db_item = get_item(db, item_id=item_id)
|
|
49
|
-
if db_item is None:
|
|
50
|
-
raise HTTPException(status_code=404, detail="Item not found")
|
|
51
|
-
return db_item
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
@router.post("/items", response_model=ItemResponse, status_code=201)
|
|
55
|
-
def create_new_item(item: ItemCreate, db: Session = Depends(get_db)):
|
|
56
|
-
"""
|
|
57
|
-
Create a new item.
|
|
58
|
-
|
|
59
|
-
Args:
|
|
60
|
-
item: Item data from request body
|
|
61
|
-
db: Database session dependency
|
|
62
|
-
|
|
63
|
-
Returns:
|
|
64
|
-
The created item with its new ID
|
|
65
|
-
"""
|
|
66
|
-
return create_item(db, item.model_dump())
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
@router.put("/items/{item_id}", response_model=ItemResponse)
|
|
70
|
-
def update_existing_item(item_id: int, item: ItemCreate, db: Session = Depends(get_db)):
|
|
71
|
-
"""
|
|
72
|
-
Update an existing item.
|
|
73
|
-
|
|
74
|
-
Args:
|
|
75
|
-
item_id: ID of the item to update
|
|
76
|
-
item: Updated item data from request body
|
|
77
|
-
db: Database session dependency
|
|
78
|
-
|
|
79
|
-
Returns:
|
|
80
|
-
The updated item
|
|
81
|
-
|
|
82
|
-
Raises:
|
|
83
|
-
HTTPException: If item is not found
|
|
84
|
-
"""
|
|
85
|
-
db_item = update_item(db, item_id=item_id, item_data=item.model_dump())
|
|
86
|
-
if db_item is None:
|
|
87
|
-
raise HTTPException(status_code=404, detail="Item not found")
|
|
88
|
-
return db_item
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
@router.delete("/items/{item_id}")
|
|
92
|
-
def delete_existing_item(item_id: int, db: Session = Depends(get_db)):
|
|
93
|
-
"""
|
|
94
|
-
Delete an item.
|
|
95
|
-
|
|
96
|
-
Args:
|
|
97
|
-
item_id: ID of the item to delete
|
|
98
|
-
db: Database session dependency
|
|
99
|
-
|
|
100
|
-
Returns:
|
|
101
|
-
Success message
|
|
102
|
-
|
|
103
|
-
Raises:
|
|
104
|
-
HTTPException: If item is not found
|
|
105
|
-
"""
|
|
106
|
-
success = delete_item(db, item_id=item_id)
|
|
107
|
-
if not success:
|
|
108
|
-
raise HTTPException(status_code=404, detail="Item not found")
|
|
109
|
-
return {"message": "Item deleted successfully"}
|
|
1
|
+
# --------------------------------------------------------------------------
|
|
2
|
+
# Item CRUD Endpoint
|
|
3
|
+
# --------------------------------------------------------------------------
|
|
4
|
+
from typing import List
|
|
5
|
+
from collections.abc import Generator
|
|
6
|
+
|
|
7
|
+
from fastapi import APIRouter, Depends, HTTPException
|
|
8
|
+
from sqlmodel import Session
|
|
9
|
+
|
|
10
|
+
from src.api.deps import get_db
|
|
11
|
+
from src.crud.items import create_item, delete_item, get_item, get_items, update_item
|
|
12
|
+
from src.schemas.items import ItemBase, ItemCreate, ItemResponse
|
|
13
|
+
|
|
14
|
+
router = APIRouter()
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
@router.get("/items", response_model=List[ItemResponse])
|
|
18
|
+
def read_items(skip: int = 0, limit: int = 100, db: Session = Depends(get_db)):
|
|
19
|
+
"""
|
|
20
|
+
Retrieve a list of items with optional pagination.
|
|
21
|
+
|
|
22
|
+
Args:
|
|
23
|
+
skip: Number of records to skip
|
|
24
|
+
limit: Maximum number of records to return
|
|
25
|
+
db: Database session dependency
|
|
26
|
+
|
|
27
|
+
Returns:
|
|
28
|
+
List of items
|
|
29
|
+
"""
|
|
30
|
+
return get_items(db, skip=skip, limit=limit)
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
@router.get("/items/{item_id}", response_model=ItemResponse)
|
|
34
|
+
def read_item(item_id: int, db: Session = Depends(get_db)):
|
|
35
|
+
"""
|
|
36
|
+
Retrieve a specific item by ID.
|
|
37
|
+
|
|
38
|
+
Args:
|
|
39
|
+
item_id: ID of the item to retrieve
|
|
40
|
+
db: Database session dependency
|
|
41
|
+
|
|
42
|
+
Returns:
|
|
43
|
+
The requested item
|
|
44
|
+
|
|
45
|
+
Raises:
|
|
46
|
+
HTTPException: If item is not found
|
|
47
|
+
"""
|
|
48
|
+
db_item = get_item(db, item_id=item_id)
|
|
49
|
+
if db_item is None:
|
|
50
|
+
raise HTTPException(status_code=404, detail="Item not found")
|
|
51
|
+
return db_item
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
@router.post("/items", response_model=ItemResponse, status_code=201)
|
|
55
|
+
def create_new_item(item: ItemCreate, db: Session = Depends(get_db)):
|
|
56
|
+
"""
|
|
57
|
+
Create a new item.
|
|
58
|
+
|
|
59
|
+
Args:
|
|
60
|
+
item: Item data from request body
|
|
61
|
+
db: Database session dependency
|
|
62
|
+
|
|
63
|
+
Returns:
|
|
64
|
+
The created item with its new ID
|
|
65
|
+
"""
|
|
66
|
+
return create_item(db, item.model_dump())
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
@router.put("/items/{item_id}", response_model=ItemResponse)
|
|
70
|
+
def update_existing_item(item_id: int, item: ItemCreate, db: Session = Depends(get_db)):
|
|
71
|
+
"""
|
|
72
|
+
Update an existing item.
|
|
73
|
+
|
|
74
|
+
Args:
|
|
75
|
+
item_id: ID of the item to update
|
|
76
|
+
item: Updated item data from request body
|
|
77
|
+
db: Database session dependency
|
|
78
|
+
|
|
79
|
+
Returns:
|
|
80
|
+
The updated item
|
|
81
|
+
|
|
82
|
+
Raises:
|
|
83
|
+
HTTPException: If item is not found
|
|
84
|
+
"""
|
|
85
|
+
db_item = update_item(db, item_id=item_id, item_data=item.model_dump())
|
|
86
|
+
if db_item is None:
|
|
87
|
+
raise HTTPException(status_code=404, detail="Item not found")
|
|
88
|
+
return db_item
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
@router.delete("/items/{item_id}")
|
|
92
|
+
def delete_existing_item(item_id: int, db: Session = Depends(get_db)):
|
|
93
|
+
"""
|
|
94
|
+
Delete an item.
|
|
95
|
+
|
|
96
|
+
Args:
|
|
97
|
+
item_id: ID of the item to delete
|
|
98
|
+
db: Database session dependency
|
|
99
|
+
|
|
100
|
+
Returns:
|
|
101
|
+
Success message
|
|
102
|
+
|
|
103
|
+
Raises:
|
|
104
|
+
HTTPException: If item is not found
|
|
105
|
+
"""
|
|
106
|
+
success = delete_item(db, item_id=item_id)
|
|
107
|
+
if not success:
|
|
108
|
+
raise HTTPException(status_code=404, detail="Item not found")
|
|
109
|
+
return {"message": "Item deleted successfully"}
|