Skip to content

Commit

Permalink
Merge pull request #36 from LuisLuii/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
LuisLuii authored Jan 5, 2024
2 parents ffc4e79 + cab30c5 commit 533599f
Show file tree
Hide file tree
Showing 19 changed files with 311 additions and 393 deletions.
2 changes: 1 addition & 1 deletion src/fastapi_quickcrud_codegen/model/crud_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def build_find_many_route(self, *, is_async: bool, path: str, file_name: str, mo

self.import_helper.add(import_=set([
f"{model_name}FindManyResponseModel",
f"{model_name}FindManyRequestBodyModel",
f"{model_name}FindManyQueryParamModel",
f"{model_name}FindManyItemListResponseModel",
f"{model_name}"]
), from_=f"model.{file_name}")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
@api.get("{{ path }}", status_code=200, response_model={{ model_name }}FindManyItemListResponseModel)
{{ 'async ' if is_async else '' }}def get_many(
response: Response,
query=Depends({{ model_name }}FindManyRequestBodyModel),
query=Depends({{ model_name }}FindManyQueryParamModel),
session=Depends(db_session)):
filter_args = query.__dict__
limit = filter_args.pop('limit', None)
Expand Down
10 changes: 5 additions & 5 deletions src/fastapi_quickcrud_codegen/utils/schema_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ def find_many(self) -> Tuple:
i['column_type'],
f'Query({i["column_default"]}, description={i["column_description"]})'))

self.code_gen.build_dataclass(class_name=self.class_name + "FindManyRequestBodyModel", fields=request_fields,
self.code_gen.build_dataclass(class_name=self.class_name + "FindManyQueryParamModel", fields=request_fields,
value_of_list_to_str_columns=self.uuid_type_columns, filter_none=True)
self.code_gen.build_base_model(class_name=self.class_name + "FindManyResponseModel", fields=response_fields)

Expand Down Expand Up @@ -632,7 +632,7 @@ def update_one(self) -> Tuple:
if i['column_name'] not in [self.primary_key_str]:
request_body_fields.append((i['column_name'],
i['column_type'],
f"Body(..., description={i['column_description']})"))
f"Body(None, description={i['column_description']})"))

request_query_fields = []
for i in query_param:
Expand All @@ -649,7 +649,7 @@ def update_one(self) -> Tuple:
self.code_gen.build_dataclass(class_name=self.class_name + "UpdateOneRequestBodyModel",
fields=request_body_fields,
value_of_list_to_str_columns=self.uuid_type_columns,
filter_none=True)
filter_none=False)

# I have removed filter none and valuexxx for response model
self.code_gen.build_base_model(class_name=self.class_name + "UpdateOneResponseModel",
Expand Down Expand Up @@ -682,7 +682,7 @@ def update_many(self) -> Tuple:
if i['column_name'] not in [self.primary_key_str]:
request_body_fields.append((i['column_name'],
i['column_type'],
f"Body(..., description={i['column_description']})"))
f"Body(None, description={i['column_description']})"))

request_query_fields = []
for i in query_param:
Expand All @@ -698,7 +698,7 @@ def update_many(self) -> Tuple:
self.code_gen.build_dataclass(class_name=self.class_name + "UpdateManyRequestBodyModel",
fields=request_body_fields,
value_of_list_to_str_columns=self.uuid_type_columns,
filter_none=True)
filter_none=False)

self.code_gen.build_base_model(class_name=self.class_name + "UpdateManyResponseItemModel",
fields=response_fields)
Expand Down
6 changes: 3 additions & 3 deletions test/special_case/test_get_desceiption.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ def __post_init__(self):
@dataclass
class TestUuidPrimaryFindManyRequestBodyModel:
class TestUuidPrimaryFindManyQueryParamModel:
primary_key____str_____matching_pattern: Optional[List[PGSQLMatchingPatternInString]] = Query([MatchingPatternInStringBase.case_sensitive], description=None)
primary_key____str: Optional[List[uuid.UUID]] = Query(None, description="hello")
primary_key: Optional[str] = Query(None, description=None)
Expand Down Expand Up @@ -339,7 +339,7 @@ class Config:
from sqlalchemy.sql.elements import BinaryExpression
from common.utils import find_query_builder
from common.sql_session import db_session
from model.test_uuid_primary import TestUuidPrimary, TestUuidPrimaryFindManyItemListResponseModel, TestUuidPrimaryFindManyRequestBodyModel, TestUuidPrimaryFindManyResponseModel
from model.test_uuid_primary import TestUuidPrimary, TestUuidPrimaryFindManyItemListResponseModel, TestUuidPrimaryFindManyQueryParamModel, TestUuidPrimaryFindManyResponseModel
from pydantic import parse_obj_as
from common.http_exception import UnknownColumn, UnknownOrderType
from common.typing import Ordering
Expand All @@ -350,7 +350,7 @@ class Config:
@api.get("", status_code=200, response_model=TestUuidPrimaryFindManyItemListResponseModel)
async def get_many(
response: Response,
query=Depends(TestUuidPrimaryFindManyRequestBodyModel),
query=Depends(TestUuidPrimaryFindManyQueryParamModel),
session=Depends(db_session)):
filter_args = query.__dict__
limit = filter_args.pop('limit', None)
Expand Down
88 changes: 43 additions & 45 deletions test/special_case/test_memory_db_async_default_crud_method.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ def __post_init__(self):
@dataclass
class TestUuidPrimaryFindManyRequestBodyModel:
class TestUuidPrimaryFindManyQueryParamModel:
primary_key____str_____matching_pattern: Optional[List[PGSQLMatchingPatternInString]] = Query([MatchingPatternInStringBase.case_sensitive], description=None)
primary_key____str: Optional[List[uuid.UUID]] = Query(None, description=None)
primary_key: Optional[str] = Query(None, description=None)
Expand Down Expand Up @@ -1110,33 +1110,32 @@ def __post_init__(self):
@dataclass
class TestUuidPrimaryUpdateManyRequestBodyModel:
bool_value: bool = Body(..., description=None)
float4_value: float = Body(..., description=None)
float8_value: float = Body(..., description=None)
int2_value: int = Body(..., description=None)
int4_value: int = Body(..., description=None)
char_value: str = Body(..., description=None)
date_value: date = Body(..., description=None)
int8_value: int = Body(..., description=None)
interval_value: timedelta = Body(..., description=None)
json_value: dict = Body(..., description=None)
jsonb_value: Union[dict, list] = Body(..., description=None)
numeric_value: Decimal = Body(..., description=None)
text_value: str = Body(..., description=None)
time_value: time = Body(..., description=None)
timestamp_value: datetime = Body(..., description=None)
timestamptz_value: datetime = Body(..., description=None)
timetz_value: time = Body(..., description=None)
varchar_value: str = Body(..., description=None)
array_value: List[int] = Body(..., description=None)
array_str__value: List[str] = Body(..., description=None)
bool_value: bool = Body(None, description=None)
float4_value: float = Body(None, description=None)
float8_value: float = Body(None, description=None)
int2_value: int = Body(None, description=None)
int4_value: int = Body(None, description=None)
char_value: str = Body(None, description=None)
date_value: date = Body(None, description=None)
int8_value: int = Body(None, description=None)
interval_value: timedelta = Body(None, description=None)
json_value: dict = Body(None, description=None)
jsonb_value: Union[dict, list] = Body(None, description=None)
numeric_value: Decimal = Body(None, description=None)
text_value: str = Body(None, description=None)
time_value: time = Body(None, description=None)
timestamp_value: datetime = Body(None, description=None)
timestamptz_value: datetime = Body(None, description=None)
timetz_value: time = Body(None, description=None)
varchar_value: str = Body(None, description=None)
array_value: List[int] = Body(None, description=None)
array_str__value: List[str] = Body(None, description=None)
def __post_init__(self):
"""
auto gen by FastApi quick CRUD
"""
value_of_list_to_str(self, ['primary_key'])
filter_none(self)
class TestUuidPrimaryUpdateManyResponseItemModel(BaseModel):
Expand Down Expand Up @@ -1272,33 +1271,32 @@ def __post_init__(self):
@dataclass
class TestUuidPrimaryUpdateOneRequestBodyModel:
bool_value: bool = Body(..., description=None)
float4_value: float = Body(..., description=None)
float8_value: float = Body(..., description=None)
int2_value: int = Body(..., description=None)
int4_value: int = Body(..., description=None)
char_value: str = Body(..., description=None)
date_value: date = Body(..., description=None)
int8_value: int = Body(..., description=None)
interval_value: timedelta = Body(..., description=None)
json_value: dict = Body(..., description=None)
jsonb_value: Union[dict, list] = Body(..., description=None)
numeric_value: Decimal = Body(..., description=None)
text_value: str = Body(..., description=None)
time_value: time = Body(..., description=None)
timestamp_value: datetime = Body(..., description=None)
timestamptz_value: datetime = Body(..., description=None)
timetz_value: time = Body(..., description=None)
varchar_value: str = Body(..., description=None)
array_value: List[int] = Body(..., description=None)
array_str__value: List[str] = Body(..., description=None)
bool_value: bool = Body(None, description=None)
float4_value: float = Body(None, description=None)
float8_value: float = Body(None, description=None)
int2_value: int = Body(None, description=None)
int4_value: int = Body(None, description=None)
char_value: str = Body(None, description=None)
date_value: date = Body(None, description=None)
int8_value: int = Body(None, description=None)
interval_value: timedelta = Body(None, description=None)
json_value: dict = Body(None, description=None)
jsonb_value: Union[dict, list] = Body(None, description=None)
numeric_value: Decimal = Body(None, description=None)
text_value: str = Body(None, description=None)
time_value: time = Body(None, description=None)
timestamp_value: datetime = Body(None, description=None)
timestamptz_value: datetime = Body(None, description=None)
timetz_value: time = Body(None, description=None)
varchar_value: str = Body(None, description=None)
array_value: List[int] = Body(None, description=None)
array_str__value: List[str] = Body(None, description=None)
def __post_init__(self):
"""
auto gen by FastApi quick CRUD
"""
value_of_list_to_str(self, ['primary_key'])
filter_none(self)
class TestUuidPrimaryUpdateOneResponseModel(BaseModel):
Expand Down Expand Up @@ -1602,7 +1600,7 @@ class Config:
from sqlalchemy.sql.elements import BinaryExpression
from common.utils import clean_input_fields, find_query_builder
from common.sql_session import db_session
from model.test_uuid_primary import TestUuidPrimary, TestUuidPrimaryCreateManyItemListRequestModel, TestUuidPrimaryCreateManyItemListResponseModel, TestUuidPrimaryDeleteManyItemListResponseModel, TestUuidPrimaryDeleteManyRequestQueryModel, TestUuidPrimaryDeleteOneRequestQueryModel, TestUuidPrimaryDeleteOneResponseModel, TestUuidPrimaryFindManyItemListResponseModel, TestUuidPrimaryFindManyRequestBodyModel, TestUuidPrimaryFindManyResponseModel, TestUuidPrimaryFindOneRequestBodyModel, TestUuidPrimaryFindOneResponseModel, TestUuidPrimaryPatchManyItemListResponseModel, TestUuidPrimaryPatchManyRequestBodyModel, TestUuidPrimaryPatchManyRequestQueryModel, TestUuidPrimaryPatchOneRequestBodyModel, TestUuidPrimaryPatchOneRequestQueryModel, TestUuidPrimaryPatchOneResponseModel, TestUuidPrimaryPrimaryKeyModel, TestUuidPrimaryUpdateManyItemListResponseModel, TestUuidPrimaryUpdateManyRequestBodyModel, TestUuidPrimaryUpdateManyRequestQueryModel, TestUuidPrimaryUpdateOneRequestBodyModel, TestUuidPrimaryUpdateOneRequestQueryModel, TestUuidPrimaryUpdateOneResponseModel
from model.test_uuid_primary import TestUuidPrimary, TestUuidPrimaryCreateManyItemListRequestModel, TestUuidPrimaryCreateManyItemListResponseModel, TestUuidPrimaryDeleteManyItemListResponseModel, TestUuidPrimaryDeleteManyRequestQueryModel, TestUuidPrimaryDeleteOneRequestQueryModel, TestUuidPrimaryDeleteOneResponseModel, TestUuidPrimaryFindManyItemListResponseModel, TestUuidPrimaryFindManyQueryParamModel, TestUuidPrimaryFindManyResponseModel, TestUuidPrimaryFindOneRequestBodyModel, TestUuidPrimaryFindOneResponseModel, TestUuidPrimaryPatchManyItemListResponseModel, TestUuidPrimaryPatchManyRequestBodyModel, TestUuidPrimaryPatchManyRequestQueryModel, TestUuidPrimaryPatchOneRequestBodyModel, TestUuidPrimaryPatchOneRequestQueryModel, TestUuidPrimaryPatchOneResponseModel, TestUuidPrimaryPrimaryKeyModel, TestUuidPrimaryUpdateManyItemListResponseModel, TestUuidPrimaryUpdateManyRequestBodyModel, TestUuidPrimaryUpdateManyRequestQueryModel, TestUuidPrimaryUpdateOneRequestBodyModel, TestUuidPrimaryUpdateOneRequestQueryModel, TestUuidPrimaryUpdateOneResponseModel
from pydantic import parse_obj_as
from common.http_exception import UnknownColumn, UnknownOrderType
from common.typing import Ordering
Expand All @@ -1614,7 +1612,7 @@ class Config:
@api.get("", status_code=200, response_model=TestUuidPrimaryFindManyItemListResponseModel)
async def get_many(
response: Response,
query=Depends(TestUuidPrimaryFindManyRequestBodyModel),
query=Depends(TestUuidPrimaryFindManyQueryParamModel),
session=Depends(db_session)):
filter_args = query.__dict__
limit = filter_args.pop('limit', None)
Expand Down
Loading

0 comments on commit 533599f

Please sign in to comment.