Skip to content

Commit cc4f283

Browse files
committed
feat: all columns string attribute added to user type service
1 parent fd5202b commit cc4f283

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

src/services/userTypeService.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from functools import reduce
12
from fastapi.responses import JSONResponse
23
from psycopg2.errors import UniqueViolation
34
from fastapi.datastructures import QueryParams
@@ -13,9 +14,10 @@ class UserTypeService:
1314
def __init__(self) -> None:
1415
self.table: str = "tipo_usuario"
1516
self.columns: list[str] = retrieve_table_columns(self.table)
17+
self.all_columns = reduce(lambda acc, elem: acc + ", " + str(elem), self.columns)
1618

1719
def all(self, query_params: QueryParams) -> JSONResponse:
18-
query = f"SELECT id, nome FROM {self.table}"
20+
query = f"SELECT {self.all_columns} FROM {self.table}"
1921
page = int(query_params.get("page", 1))
2022
rows_per_page = int(query_params.get("rows_per_page", 10))
2123
sort = query_params.get("sort_by", None)
@@ -37,7 +39,7 @@ def view(self, user_type_id: int) -> JSONResponse:
3739

3840
try:
3941
with PgDatabase() as db:
40-
db.cursor.execute(f"SELECT id, nome FROM {self.table} WHERE id = %s", (user_type_id,))
42+
db.cursor.execute(f"SELECT {self.all_columns} FROM {self.table} WHERE id = %s", (user_type_id,))
4143
row = db.cursor.fetchone()
4244

4345
if row is None:

0 commit comments

Comments
 (0)