Repository: LuisLuii/fastapi-crud-template-generator (language: python)

Issue:
fix template issue



Discussion / hints:

Fix patch:
diff --git a/src/fastapi_quickcrud_codegen/model/template/route/find_many.jinja2 b/src/fastapi_quickcrud_codegen/model/template/route/find_many.jinja2
index b851901..bfe8c4e 100644
--- a/src/fastapi_quickcrud_codegen/model/template/route/find_many.jinja2
+++ b/src/fastapi_quickcrud_codegen/model/template/route/find_many.jinja2
@@ -34,8 +34,14 @@
     sql_executed_result_without_paginate = {{ 'await ' if is_async else '' }}session.execute(stmt)
     total = len(sql_executed_result_without_paginate.fetchall())
 
+    response_format = {
+            "total": 0,
+            "result": []
+        }
     if total < 1:
-        return Response(status_code=HTTPStatus.NO_CONTENT, headers={"x-total-count": str(0)})
+        response_data = parse_obj_as({{ model_name }}FindManyItemListResponseModel, response_format)
+        response.headers["x-total-count"] = str(0)
+        return response_data
 
     stmt = stmt.limit(limit).offset(offset)
 
@@ -50,10 +56,8 @@
             temp[column] = getattr(result_value, column)
         response_data_list.append(temp)
 
-    response_format = {
-        "total": total,
-        "result": response_data_list
-    }
-    response_data = parse_obj_as(SampleTableFindManyItemListResponseModel, response_format)
+    response_format["total"] = total
+    response_format["result"] = response_data_list
+    response_data = parse_obj_as({{ model_name }}FindManyItemListResponseModel, response_format)
     response.headers["x-total-count"] = str(len(response_data_list))
     return response_data
diff --git a/tutorial/generate_project_with_memory_db.py b/tutorial/generate_project_with_memory_db.py
index 1d8977e..1cb204f 100644
--- a/tutorial/generate_project_with_memory_db.py
+++ b/tutorial/generate_project_with_memory_db.py
@@ -5,7 +5,7 @@
 metadata = Base.metadata
 
 
-class SampleTable(Base):
+class TestingTable(Base):
     __tablename__ = 'test_build_myself_memory'
     primary_key = Column(Integer, primary_key=True, autoincrement=True, comment="hello")
     bool_value = Column(Boolean, nullable=False, default=False)
@@ -25,7 +25,7 @@ class SampleTable(Base):
     varchar_value = Column(String)
 
 
-class SampleTableTwo(Base):
+class TestingTableTwo(Base):
     primary_key_of_table = "primary_key"
     unique_fields = ['primary_key']
     __tablename__ = 'test_build_myself_memory_two'
@@ -42,7 +42,7 @@ class SampleTableTwo(Base):
 crud_router_builder(
     db_model_list=[
         {
-            "db_model": SampleTable,
+            "db_model": TestingTable,
             "prefix": "/my_first_api",
             "tags": ["sample api"],
             "exclude_columns": ['bytea_value'],
@@ -51,7 +51,7 @@ class SampleTableTwo(Base):
         },
 
         {
-            "db_model": SampleTableTwo,
+            "db_model": TestingTableTwo,
             "prefix": "/my_second_api",
             "tags": ["sample api"],
             "exclude_columns": ['bytea_value'],


Test patch:
diff --git a/test/test_memory_db_async_find_many.py b/test/test_memory_db_async_find_many.py
index c4a9456..2616aa7 100644
--- a/test/test_memory_db_async_find_many.py
+++ b/test/test_memory_db_async_find_many.py
@@ -492,8 +492,14 @@ async def get_many(response: Response,
     sql_executed_result_without_paginate = await session.execute(stmt)
     total = len(sql_executed_result_without_paginate.fetchall())
 
+    response_format = {
+            "total": 0,
+            "result": []
+        }
     if total < 1:
-        return Response(status_code=HTTPStatus.NO_CONTENT, headers={"x-total-count": str(0)})
+        response_data = parse_obj_as(SampleTableTwoFindManyItemListResponseModel, response_format)
+        response.headers["x-total-count"] = str(0)
+        return response_data
 
     stmt = stmt.limit(limit).offset(offset)
 
@@ -508,11 +514,9 @@ async def get_many(response: Response,
             temp[column] = getattr(result_value, column)
         response_data_list.append(temp)
 
-    response_format = {
-        "total": total,
-        "result": response_data_list
-    }
-    response_data = parse_obj_as(SampleTableFindManyItemListResponseModel, response_format)
+    response_format["total"] = total
+    response_format["result"] = response_data_list
+    response_data = parse_obj_as(SampleTableTwoFindManyItemListResponseModel, response_format)
     response.headers["x-total-count"] = str(len(response_data_list))
     return response_data'''
         validate_route("test_build_myself_memory_two", route_test_build_myself_memory_two_expected)
@@ -570,8 +574,14 @@ async def get_many(response: Response,
     sql_executed_result_without_paginate = await session.execute(stmt)
     total = len(sql_executed_result_without_paginate.fetchall())
 
+    response_format = {
+            "total": 0,
+            "result": []
+        }
     if total < 1:
-        return Response(status_code=HTTPStatus.NO_CONTENT, headers={"x-total-count": str(0)})
+        response_data = parse_obj_as(SampleTableFindManyItemListResponseModel, response_format)
+        response.headers["x-total-count"] = str(0)
+        return response_data
 
     stmt = stmt.limit(limit).offset(offset)
 
@@ -586,10 +596,8 @@ async def get_many(response: Response,
             temp[column] = getattr(result_value, column)
         response_data_list.append(temp)
 
-    response_format = {
-        "total": total,
-        "result": response_data_list
-    }
+    response_format["total"] = total
+    response_format["result"] = response_data_list
     response_data = parse_obj_as(SampleTableFindManyItemListResponseModel, response_format)
     response.headers["x-total-count"] = str(len(response_data_list))
     return response_data'''
diff --git a/test/test_memory_db_sync_find_many.py b/test/test_memory_db_sync_find_many.py
index 8748a5b..199fec6 100644
--- a/test/test_memory_db_sync_find_many.py
+++ b/test/test_memory_db_sync_find_many.py
@@ -492,8 +492,14 @@ def get_many(response: Response,
     sql_executed_result_without_paginate = session.execute(stmt)
     total = len(sql_executed_result_without_paginate.fetchall())
 
+    response_format = {
+            "total": 0,
+            "result": []
+        }
     if total < 1:
-        return Response(status_code=HTTPStatus.NO_CONTENT, headers={"x-total-count": str(0)})
+        response_data = parse_obj_as(SampleTableTwoFindManyItemListResponseModel, response_format)
+        response.headers["x-total-count"] = str(0)
+        return response_data
 
     stmt = stmt.limit(limit).offset(offset)
 
@@ -508,11 +514,9 @@ def get_many(response: Response,
             temp[column] = getattr(result_value, column)
         response_data_list.append(temp)
 
-    response_format = {
-        "total": total,
-        "result": response_data_list
-    }
-    response_data = parse_obj_as(SampleTableFindManyItemListResponseModel, response_format)
+    response_format["total"] = total
+    response_format["result"] = response_data_list
+    response_data = parse_obj_as(SampleTableTwoFindManyItemListResponseModel, response_format)
     response.headers["x-total-count"] = str(len(response_data_list))
     return response_data'''
         validate_route("test_build_myself_memory_two", route_test_build_myself_memory_two_expected)
@@ -570,8 +574,14 @@ def get_many(response: Response,
     sql_executed_result_without_paginate = session.execute(stmt)
     total = len(sql_executed_result_without_paginate.fetchall())
 
+    response_format = {
+            "total": 0,
+            "result": []
+        }
     if total < 1:
-        return Response(status_code=HTTPStatus.NO_CONTENT, headers={"x-total-count": str(0)})
+        response_data = parse_obj_as(SampleTableFindManyItemListResponseModel, response_format)
+        response.headers["x-total-count"] = str(0)
+        return response_data
 
     stmt = stmt.limit(limit).offset(offset)
 
@@ -586,10 +596,8 @@ def get_many(response: Response,
             temp[column] = getattr(result_value, column)
         response_data_list.append(temp)
 
-    response_format = {
-        "total": total,
-        "result": response_data_list
-    }
+    response_format["total"] = total
+    response_format["result"] = response_data_list
     response_data = parse_obj_as(SampleTableFindManyItemListResponseModel, response_format)
     response.headers["x-total-count"] = str(len(response_data_list))
     return response_data'''
diff --git a/test/test_postgresql_db_async_find_many.py b/test/test_postgresql_db_async_find_many.py
index d3040e8..b10cdfe 100644
--- a/test/test_postgresql_db_async_find_many.py
+++ b/test/test_postgresql_db_async_find_many.py
@@ -521,8 +521,14 @@ async def get_many(response: Response,
     sql_executed_result_without_paginate = await session.execute(stmt)
     total = len(sql_executed_result_without_paginate.fetchall())
 
+    response_format = {
+            "total": 0,
+            "result": []
+        }
     if total < 1:
-        return Response(status_code=HTTPStatus.NO_CONTENT, headers={"x-total-count": str(0)})
+        response_data = parse_obj_as(SampleTableTwoFindManyItemListResponseModel, response_format)
+        response.headers["x-total-count"] = str(0)
+        return response_data
 
     stmt = stmt.limit(limit).offset(offset)
 
@@ -537,11 +543,9 @@ async def get_many(response: Response,
             temp[column] = getattr(result_value, column)
         response_data_list.append(temp)
 
-    response_format = {
-        "total": total,
-        "result": response_data_list
-    }
-    response_data = parse_obj_as(SampleTableFindManyItemListResponseModel, response_format)
+    response_format["total"] = total
+    response_format["result"] = response_data_list
+    response_data = parse_obj_as(SampleTableTwoFindManyItemListResponseModel, response_format)
     response.headers["x-total-count"] = str(len(response_data_list))
     return response_data'''
         validate_route("test_build_myself_two", route_test_build_myself_two_expected)
@@ -599,8 +603,14 @@ async def get_many(response: Response,
     sql_executed_result_without_paginate = await session.execute(stmt)
     total = len(sql_executed_result_without_paginate.fetchall())
 
+    response_format = {
+            "total": 0,
+            "result": []
+        }
     if total < 1:
-        return Response(status_code=HTTPStatus.NO_CONTENT, headers={"x-total-count": str(0)})
+        response_data = parse_obj_as(SampleTableFindManyItemListResponseModel, response_format)
+        response.headers["x-total-count"] = str(0)
+        return response_data
 
     stmt = stmt.limit(limit).offset(offset)
 
@@ -615,10 +625,8 @@ async def get_many(response: Response,
             temp[column] = getattr(result_value, column)
         response_data_list.append(temp)
 
-    response_format = {
-        "total": total,
-        "result": response_data_list
-    }
+    response_format["total"] = total
+    response_format["result"] = response_data_list
     response_data = parse_obj_as(SampleTableFindManyItemListResponseModel, response_format)
     response.headers["x-total-count"] = str(len(response_data_list))
     return response_data'''
diff --git a/test/test_postgresql_db_sync_find_many.py b/test/test_postgresql_db_sync_find_many.py
index a60a29b..a9b81a8 100644
--- a/test/test_postgresql_db_sync_find_many.py
+++ b/test/test_postgresql_db_sync_find_many.py
@@ -526,8 +526,14 @@ def get_many(response: Response,
     sql_executed_result_without_paginate = session.execute(stmt)
     total = len(sql_executed_result_without_paginate.fetchall())
 
+    response_format = {
+            "total": 0,
+            "result": []
+        }
     if total < 1:
-        return Response(status_code=HTTPStatus.NO_CONTENT, headers={"x-total-count": str(0)})
+        response_data = parse_obj_as(SampleTableTwoFindManyItemListResponseModel, response_format)
+        response.headers["x-total-count"] = str(0)
+        return response_data
 
     stmt = stmt.limit(limit).offset(offset)
 
@@ -542,11 +548,9 @@ def get_many(response: Response,
             temp[column] = getattr(result_value, column)
         response_data_list.append(temp)
 
-    response_format = {
-        "total": total,
-        "result": response_data_list
-    }
-    response_data = parse_obj_as(SampleTableFindManyItemListResponseModel, response_format)
+    response_format["total"] = total
+    response_format["result"] = response_data_list
+    response_data = parse_obj_as(SampleTableTwoFindManyItemListResponseModel, response_format)
     response.headers["x-total-count"] = str(len(response_data_list))
     return response_data'''
         validate_route("test_build_myself_two", route_test_build_myself_two_expected)
@@ -604,8 +608,14 @@ def get_many(response: Response,
     sql_executed_result_without_paginate = session.execute(stmt)
     total = len(sql_executed_result_without_paginate.fetchall())
 
+    response_format = {
+            "total": 0,
+            "result": []
+        }
     if total < 1:
-        return Response(status_code=HTTPStatus.NO_CONTENT, headers={"x-total-count": str(0)})
+        response_data = parse_obj_as(SampleTableFindManyItemListResponseModel, response_format)
+        response.headers["x-total-count"] = str(0)
+        return response_data
 
     stmt = stmt.limit(limit).offset(offset)
 
@@ -620,10 +630,8 @@ def get_many(response: Response,
             temp[column] = getattr(result_value, column)
         response_data_list.append(temp)
 
-    response_format = {
-        "total": total,
-        "result": response_data_list
-    }
+    response_format["total"] = total
+    response_format["result"] = response_data_list
     response_data = parse_obj_as(SampleTableFindManyItemListResponseModel, response_format)
     response.headers["x-total-count"] = str(len(response_data_list))
     return response_data'''