1+ from functools import reduce
12from fastapi .responses import JSONResponse
23from psycopg2 .errors import UniqueViolation
34from 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