From 75ecb00a945e9b19add35dd0e2b734e6bc96ff5c Mon Sep 17 00:00:00 2001 From: gerardoe Date: Wed, 8 Apr 2026 15:05:29 -0700 Subject: [PATCH] adision de bases para trabajo completo de back-v1.0.0 --- .env | 9 +- README.md | 6 + .../__pycache__/csv_mapper.cpython-311.pyc | Bin 0 -> 3523 bytes .../__pycache__/db_adapter.cpython-311.pyc | Bin 0 -> 2459 bytes .../__pycache__/extractCsv.cpython-311.pyc | Bin 0 -> 4222 bytes app/helpers/csv_mapper.py | 56 +++++++++ app/helpers/db_adapter.py | 42 +++++++ app/helpers/extractCsv.py | 81 ++++++++++++ .../coments/__pycache__/route.cpython-311.pyc | Bin 0 -> 6073 bytes .../__pycache__/schema.cpython-311.pyc | Bin 0 -> 1643 bytes .../__pycache__/services.cpython-311.pyc | Bin 0 -> 4345 bytes app/modules/coments/route.py | 116 +++++++++++++++++ app/modules/coments/schema.py | 2 +- app/modules/coments/services.py | 63 ++++++++++ .../__pycache__/route.cpython-311.pyc | Bin 0 -> 6211 bytes .../__pycache__/schema.cpython-311.pyc | Bin 0 -> 1806 bytes .../__pycache__/service.cpython-311.pyc | Bin 0 -> 4522 bytes app/modules/configuration/route.py | 116 +++++++++++++++++ app/modules/configuration/schema.py | 2 +- .../modules/configuration/service.py | 9 +- .../__pycache__/models.cpython-311.pyc | Bin 3087 -> 3087 bytes app/modules/credits/route.py | 116 +++++++++++++++++ app/modules/credits/schema.py | 40 +++++- .../modules/credits/service.py | 10 +- .../edos/__pycache__/models.cpython-311.pyc | Bin 2098 -> 2098 bytes .../edos/__pycache__/route.cpython-311.pyc | Bin 0 -> 3447 bytes .../edos/__pycache__/schema.cpython-311.pyc | Bin 0 -> 1848 bytes .../edos/__pycache__/service.cpython-311.pyc | Bin 0 -> 3374 bytes app/modules/edos/models.py | 2 +- app/modules/edos/route.py | 77 ++++++++++++ app/modules/edos/schema.py | 31 ++++- app/modules/edos/service.py | 74 +++++++++++ app/modules/efos/schema.py | 30 ++++- app/modules/feed/route.py | 116 +++++++++++++++++ app/modules/feed/schema.py | 29 ++++- .../modules/feed/service.py | 10 +- app/modules/files/schema.py | 25 +++- app/modules/files/service.py | 0 app/modules/interactions/schema.py | 24 +++- app/modules/invoices/schema.py | 20 ++- .../__pycache__/models.cpython-311.pyc | Bin 2813 -> 2813 bytes app/modules/license/models.py | 2 +- app/modules/license/schema.py | 23 +++- .../modules/license/service.py | 6 +- .../__pycache__/models.cpython-311.pyc | Bin 3013 -> 2844 bytes .../__pycache__/route.cpython-311.pyc | Bin 0 -> 6119 bytes .../__pycache__/schema.cpython-311.pyc | Bin 0 -> 1960 bytes .../__pycache__/service.cpython-311.pyc | Bin 0 -> 4608 bytes app/modules/location/models.py | 3 - app/modules/location/route.py | 116 +++++++++++++++++ app/modules/location/schema.py | 34 +++++ app/modules/location/service.py | 65 +++++++++- app/modules/moves/schema.py | 56 ++++++++- .../__pycache__/models.cpython-311.pyc | Bin 3418 -> 3417 bytes .../__pycache__/route.cpython-311.pyc | Bin 0 -> 6125 bytes .../__pycache__/schema.cpython-311.pyc | Bin 0 -> 2636 bytes .../__pycache__/service.cpython-311.pyc | Bin 0 -> 4613 bytes app/modules/suppliers/models.py | 2 +- app/modules/suppliers/route.py | 116 +++++++++++++++++ app/modules/suppliers/schema.py | 42 +++++++ app/modules/suppliers/service.py | 66 +++++++++- main.py | 18 ++- output/generated/routers/branches_router.py | 116 ----------------- output/generated/routers/client_router.py | 117 ------------------ output/generated/routers/coments_router.py | 116 ----------------- .../generated/routers/configuration_router.py | 116 ----------------- output/generated/routers/credits_router.py | 116 ----------------- output/generated/routers/edos_router.py | 116 ----------------- output/generated/routers/efos_router.py | 116 ----------------- output/generated/routers/feed_router.py | 116 ----------------- output/generated/routers/files_router.py | 116 ----------------- output/generated/routers/invoices_router.py | 116 ----------------- output/generated/routers/license_router.py | 116 ----------------- output/generated/routers/locations_router.py | 116 ----------------- output/generated/routers/moves_router.py | 116 ----------------- output/generated/routers/suppliers_router.py | 116 ----------------- output/generated/services/branches_service.py | 67 ---------- output/generated/services/client_service.py | 67 ---------- output/generated/services/coments_service.py | 67 ---------- output/generated/services/edos_service.py | 67 ---------- output/generated/services/efos_service.py | 67 ---------- output/generated/services/files_service.py | 67 ---------- output/generated/services/invoices_service.py | 67 ---------- .../generated/services/locations_service.py | 67 ---------- output/generated/services/moves_service.py | 67 ---------- .../generated/services/suppliers_service.py | 67 ---------- requerimiento_minimos.txt | 2 +- requirements.txt | 4 +- test_csv_extractor.py | 24 ++++ 89 files changed, 1630 insertions(+), 2350 deletions(-) create mode 100644 app/helpers/__pycache__/csv_mapper.cpython-311.pyc create mode 100644 app/helpers/__pycache__/db_adapter.cpython-311.pyc create mode 100644 app/helpers/__pycache__/extractCsv.cpython-311.pyc create mode 100644 app/helpers/csv_mapper.py create mode 100644 app/helpers/db_adapter.py create mode 100644 app/helpers/extractCsv.py create mode 100644 app/modules/coments/__pycache__/route.cpython-311.pyc create mode 100644 app/modules/coments/__pycache__/schema.cpython-311.pyc create mode 100644 app/modules/coments/__pycache__/services.cpython-311.pyc create mode 100644 app/modules/configuration/__pycache__/route.cpython-311.pyc create mode 100644 app/modules/configuration/__pycache__/schema.cpython-311.pyc create mode 100644 app/modules/configuration/__pycache__/service.cpython-311.pyc rename output/generated/services/configuration_service.py => app/modules/configuration/service.py (91%) rename output/generated/services/credits_service.py => app/modules/credits/service.py (88%) create mode 100644 app/modules/edos/__pycache__/route.cpython-311.pyc create mode 100644 app/modules/edos/__pycache__/schema.cpython-311.pyc create mode 100644 app/modules/edos/__pycache__/service.cpython-311.pyc create mode 100644 app/modules/edos/service.py rename output/generated/services/feed_service.py => app/modules/feed/service.py (89%) create mode 100644 app/modules/files/service.py rename output/generated/services/license_service.py => app/modules/license/service.py (96%) create mode 100644 app/modules/location/__pycache__/route.cpython-311.pyc create mode 100644 app/modules/location/__pycache__/schema.cpython-311.pyc create mode 100644 app/modules/location/__pycache__/service.cpython-311.pyc create mode 100644 app/modules/suppliers/__pycache__/route.cpython-311.pyc create mode 100644 app/modules/suppliers/__pycache__/schema.cpython-311.pyc create mode 100644 app/modules/suppliers/__pycache__/service.cpython-311.pyc delete mode 100644 output/generated/routers/branches_router.py delete mode 100644 output/generated/routers/client_router.py delete mode 100644 output/generated/routers/coments_router.py delete mode 100644 output/generated/routers/configuration_router.py delete mode 100644 output/generated/routers/credits_router.py delete mode 100644 output/generated/routers/edos_router.py delete mode 100644 output/generated/routers/efos_router.py delete mode 100644 output/generated/routers/feed_router.py delete mode 100644 output/generated/routers/files_router.py delete mode 100644 output/generated/routers/invoices_router.py delete mode 100644 output/generated/routers/license_router.py delete mode 100644 output/generated/routers/locations_router.py delete mode 100644 output/generated/routers/moves_router.py delete mode 100644 output/generated/routers/suppliers_router.py delete mode 100644 output/generated/services/branches_service.py delete mode 100644 output/generated/services/client_service.py delete mode 100644 output/generated/services/coments_service.py delete mode 100644 output/generated/services/edos_service.py delete mode 100644 output/generated/services/efos_service.py delete mode 100644 output/generated/services/files_service.py delete mode 100644 output/generated/services/invoices_service.py delete mode 100644 output/generated/services/locations_service.py delete mode 100644 output/generated/services/moves_service.py delete mode 100644 output/generated/services/suppliers_service.py create mode 100644 test_csv_extractor.py diff --git a/.env b/.env index 383bdef..a9a16c5 100644 --- a/.env +++ b/.env @@ -1,4 +1,11 @@ # .env -DATABASE_URL=postgresql://postgres:postgres@localhost:5432/postgres \ No newline at end of file +DATABASE_URL=postgresql://postgres:postgres@localhost:5432/postgres + + + +CSV_DOWNLOAD_TIMEOUT=30 +CSV_MAX_SIZE_MB=10 +API_VERSION=v1 +LOG_LEVEL=INFO diff --git a/README.md b/README.md index e79493d..c711f08 100644 --- a/README.md +++ b/README.md @@ -24,3 +24,9 @@ una vez importado el model, lo lee, lo pasa por la logica en la que se descratan - puntos no claros de uso Diot - se pidio que no se agregara multiempresas o multitenant, aunque hay la posibilida de hacerlo, asi como el que se pudiera facilitar la actualizacion de las listas de efos, edos. + +`notas de Gerardo` +se quedaron implementadas los servicios crud de las funciones que seran publicos, ajustados a el tipo de usuario ('Root', 'Admin') +lo mas dificil de implementar para el back va a ser, implementar las funciones de ajuste "automatico" de cargado de files, con un url, desde las listas, del sat y las publicaciones del diario. + +si el tiempo nos cae encima (que es lo mas seguro, voy a concentrarme en trabajar en las listas de el sat(edos, efos y creditos), para tratar de dejar enpoints funcionales). \ No newline at end of file diff --git a/app/helpers/__pycache__/csv_mapper.cpython-311.pyc b/app/helpers/__pycache__/csv_mapper.cpython-311.pyc new file mode 100644 index 0000000000000000000000000000000000000000..2ce6224aeb82830a3661e94eca5368deefcfcec6 GIT binary patch literal 3523 zcmb7H|8LvI6+eoiELoDj$(H5V>6j*Nqu7x%BwL)sO`6(HV<&O!cqvdd0YU31hZ#j` zN6ML188Eg0bB6xl1|95nDXIot>LEp8VEbvnfC2djBtw`90tNyM1G?W7xC09Rw0C4I zOLhu)r{m+hyZ7GRz2p1b)7QaZJ%aN1^MA^HK7{^78{5VGlG%J4m?eY}W)zfS;!MgF zccs`k%g{cT;!bgKjzKQ;F2d}6gxybE2t9?zDRB?xCQ;P$AKHwvmiwx#8?W7ww-*-QO@uwA;xDWJNq_y&T&hklFF(kr^D&|u#CacrDrYf_%DkUUcB(ppg4Y8M> z5_Ji~2ru$_;*OLOt$_0ulCq>=t1+FKQsjh~kTq4%MZ@x_nUq8{D?r37?a~sms8~K- zHZr!5)$9leSW3#OY{)a3)s&PHcf{(Rh8-aRYe_3uk+7RJv(oWx`J^~QR}uAFjR}25 zNN7qXr3$K;lCtcW7PHtJmj<(uF)cMkBpyo&Kd7k&k*6}Vl4?kqE^zRqv(jgOQEh=l zjX)m=j6M4s-622A+lvAzUQ5d00DfB0rbGogws*!)Ui?MoFzAeLdx@G&Kl^f8Rz*5k zC7bzwZ4X_)loC$Z9Pxdv8U8(kIA2oMtuM1X+}A)Kanm9&j9TmXCUg7y7N>rIF#QL&CL-Bjo~4|*04Nu&nmXKG?7&!>LFoj&g<+z!WIkB zVEO2#?I{WUcE~{>Iz4%wmbb}kRHte8uCoVz+#~JO!Um8Z=26*$TEh$8=b_Frs`s6> z$--PY=rGh3c4g$7 z24FV&`q%r0*ZPLdNaym%qlT5h3)Xca{5=A)IJ%rGw)XxPCT*|w@85l;{&DCih9^ou zLldRYL>aNoXU*2GrRxu`=SPdJeWljEf?faJ+EF;rzcLC0YO(c9sr5|3uH|OBz!uaL zS!g6YbqwdYzutDBV9chaL^UE*P~}^QEc(HcNDk#eac`-`49xt}wnJRlH3`{5jset& z(R*BBQp}u-K{?l}v1gz5J+-+9%uz?@(B0T;&-F8-ZfA}Avzgz{gLV{wqZvo-T(!sm zGy4H+D!5dwTlPZb z+>oD0gdP;+W?tGbWVq$M-R~doP95*Y5P>NzqZ)PuCZsKipPquDR@LwVLWAKf7=tr+kS2=~c z!fJ<$CFVF-k4f;CB<9?OgyNm!lv+n^c?TTv^JEA_Xqur<11Yl%!^{lBiuaNiwD0>@4A`6cAJ!d?Qvd(} literal 0 HcmV?d00001 diff --git a/app/helpers/__pycache__/db_adapter.cpython-311.pyc b/app/helpers/__pycache__/db_adapter.cpython-311.pyc new file mode 100644 index 0000000000000000000000000000000000000000..89113103b6d3e46ef54aa74acf34df7b52cf87c2 GIT binary patch literal 2459 zcmaJ?-D?zA6uzxVt zU{ieXAuXX*5t6o{U8HD>E%?xfKG*&MyRy_}Kq!<_e4C&J@u}y|B)gd=_0G)i-gED{ z=bm%!IcM&6bhIL9((T{P0STc$8L`>Kjlt71FjzqtVa`H%F308h9M3VDw}iZy6N9l} zNqIRZbBIT$5f-l@EZyM|x(8p_axpBQN150YMrL?VJZn0xCytwjo8i26hd7Q|u+J6@ z-2z%XH9mRX*w`9$4RziCas?5T<1otcn9B*6zlL%m7KlXTy^TFsB=WR~rEB8m(O%2= zyJJ`{x`ZwasvD!XRnv9|bydS6#8$EH>T1DObrnw;TtgTFyATrKd-@u{3Uars-GP~V z@P(~}w8k1nU@|w6;VF0*c|4wCwmHO_b{LQPqIX0u7K862VigH>M(~uThdO49^Ilxj zO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x2UfiUUyps`%X&u) z@5q{WeAPRyzxR>;@sG0Ju;C4-httFBULT;=@1=!|m@W6~<^FH$o0kW^=(y35M|<2p z3oY8yRJt=)-;m~VE#lqCt;o%bw=d?AvjPSLXmK<>lo`)?8g3#th%sn(u>E-v|0RNuM~M^+gO{B*SI6 zb)O%Qr$P6;`rE*L_RmVTt>0+thtHf}ynFK2$(tj$M>0Z2Soe#7VC+LMv(nE7s1^v5Z5oq(7oQ}^ssNZSKOaxOTpxUaew u+<7}qb?4Eu=rQ4aw=HlWS9R*>kGrmQE%14J4+SxM7Ck1s@17&D!uns)8O+ZB literal 0 HcmV?d00001 diff --git a/app/helpers/csv_mapper.py b/app/helpers/csv_mapper.py new file mode 100644 index 0000000..0519aa4 --- /dev/null +++ b/app/helpers/csv_mapper.py @@ -0,0 +1,56 @@ +from typing import List, Dict, Any +from app.modules.edos.schema import EdosUpload + +class CSVMapper: + """ Mapper: filter and mapping only necesary data, based on a schema""" + + FIELD_MAPPING = { + 'csv_column_name': 'schema_field', + 'No.' : 'publicacion_sat', + 'RFC' : 'numero', + 'Nombre del Contribuyente' : 'razon_social', + 'Situación del contribuyente' : 'situacion', + 'Número y fecha de oficio global definitivo SAT' : 'numero_definitivo', + 'Publicación página SAT definitivo' : 'fecha_definitivo', + 'Número y fecha de oficio global definitivo DOF' : 'numero_def_dof', + 'Publicación DOF definitivo' : 'fecha_def_dof', + 'Número y fecha de oficio global de sentencia favorable SAT' : 'publicacion_dof', + 'Publicación página SAT sentencia favorable' : 'numero_fav_sat', + } + + REQUIRED_FIELD = [ 'publicacion_sat', 'numero', 'razon_social', 'situacion'] #Campos obligatorios + + @staticmethod + def filter_by_schema(raw_rows: List[Dict]) -> List[Dict]: + """ Filter only fields defined on schema""" + filtered = [] + + for row in raw_rows: + mapped_row = {} + for csv_field, schema_field in CSVMapper.FIELD_MAPPING.items(): + if csv_field in row and row[csv_field]: + mapped_row[schema_field] = CSVMapper._clean_value( + row[csv_field], schema_field + ) + if all(field in mapped_row for field in CSVMapper.REQUIRED_FIELD): + filtered.append(mapped_row) + else: + print(f"omited fields: {mapped_row}") + return filtered + + @staticmethod + def _clean_value(value: str, field_type: str) -> Any: + """ Cleanen and typified values""" + if not value or value.strip() == '': + return None + + if 'date' in field_type: + from datetime import datetime + return datetime.strptime(value.strip(), '%Y-%m-%d') + elif 'amount' in field_type or 'price' in field_type: + return float(value.strip().replace(',','.')) + elif 'int' in field_type.lower(): + return int(value.strip()) + else: + return value.strip() + \ No newline at end of file diff --git a/app/helpers/db_adapter.py b/app/helpers/db_adapter.py new file mode 100644 index 0000000..e81fbba --- /dev/null +++ b/app/helpers/db_adapter.py @@ -0,0 +1,42 @@ +from typing import List, Dict +from database import sessionLocal +from app.modules.edos.models import EDOS + +class DBAdapter: + """ Adapter: insert cleen data on a db""" + + def __inti__(self): + self.db = sessionLocal() + + def insert_filtered_data(self, mapped_rows: List[Dict]) -> Dict: + """ Insert only data filtered and mapped""" + results = { + 'total_processed': len(mapped_rows), + 'inserted': 0, + 'errors': [], + 'duplicates_skiped': 0 + } + for row in mapped_rows: + try: + #verified dupled data + existing = self.db.query(EDOS).filter_by( + unique_field=row.get('unique_field') + ).first() + + if existing: + results['duplicates_skiped'] += 1 + continue + + instance = EDOS(**row) + self.db.add(instance) + self.db.commit() + results['inserted'] += 1 + except Exception as e: + self.db.rollback() + results['errors'].append({ + 'row': row, + 'error': str(e) + }) + self.db.close() + return results + \ No newline at end of file diff --git a/app/helpers/extractCsv.py b/app/helpers/extractCsv.py new file mode 100644 index 0000000..04b3007 --- /dev/null +++ b/app/helpers/extractCsv.py @@ -0,0 +1,81 @@ +import csv +import requests +from io import StringIO +# +from typing import List, Dict, Any +import os +from dotenv import load_dotenv + +load_dotenv() + + +class Settings: + """configuration""" + CSV_DOWNLOAD_TIMEOUT = int(os.getenv('CSV_DOWNLOAD_TIMEOUT', 30)) + CSV_MAX_SIZE_MB = int(os.getenv('CSV_MAX_SIZE_MB', 10)) + +settings = Settings() + + +class CSVExtractor: + """Extract raw data of CSV""" + + @staticmethod + def download_csv(url: str) -> str: + """ Download CSV of URL""" + try: + + response = requests.get(url, timeout=30) + response.raise_for_status() + + encoding = response.encoding or 'utf-8' + content = response.text + return content, encoding + except Exception as e: + raise Exception(f"Error Download CSV: {str(e)}") + + + @staticmethod + def read_csv(content: str) -> List[Dict[str, Any]]: + """ Converts CSV to list of dictionary""" + csv_file = StringIO(content) + #detect delimiter auto + sample = csv_file.read(1024) + csv_file.seek(0) + try: + dialect = csv.Sniffer().sniff(sample) + reader =csv.DictReader(csv_file, dialect=dialect) + except: + csv_file.seek(0) + reader = csv.DictReader(csv_file) + + rows = [row for row in reader] + + if rows: + clean_row = {} + + for key, value in rows[0].items(): + + if key is not None: + clean_key = key.strip().replace('"', '').replace("'", "").replace('\ufeff', '') + else: + clean_key = '' + + clean_row[clean_key] = value + + for i, row in enumerate(rows): + new_row = {} + for old_key, value in row.items(): + if old_key is not None: + new_key = old_key.strip().replace('"', '').replace("'", "").replace('\ufeff', '') + else: + new_key = '' + #FIX: manage value None for avoid error strip + if value is not None and isinstance(value, str): + new_value = value.strip() + else: + new_value = value + + new_row[new_key] = value + rows[i] = new_row + return rows diff --git a/app/modules/coments/__pycache__/route.cpython-311.pyc b/app/modules/coments/__pycache__/route.cpython-311.pyc new file mode 100644 index 0000000000000000000000000000000000000000..7b4ecf33732db4589837d2091aa9a6d1800a8679 GIT binary patch literal 6073 zcmc&&-ESMm5#Qt8@l&Em$@-!`eDXK#M2cf4ia(l~v1BJmET{fRYbJ$o;;rO!cqFrT zv@Kam1*bq&pbrX~pnj{LTpJPE1ZV+0^db5WjsQ^*2LupM6o}uLx+nrab!Lx8i5BB1 zb%CDlmb1IFGqXFhzuDCvT3f>eo;$bxrpMX|`8!s;hxb6`(XvR$?}$b;AxjJ)Ef~JE z&k)n1A*CflPRoWr?H91$mkk)fbkGQ;L%c3#!$u?>;k1-(FDebvfH+#L_WN z`?GPQJ>AafK(@o!k>0`SV7AlfN_TNO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KAk9lnQ?C4!lq+u|<;ow*4Jr5VWqw>z=uLngJvUPi#HXXq zMhLRquzU<*;CoW3>laUcQgY#j2P5WF9=_~VpuD8Y@JwFIrS4!amu`eJx1hT+Zdyy7N5-1!Vap5e8{iPhMKO$s+KIA$=++YJ9Fz&5AV$xOteg8@b5IjIar!S1BE{%`zD}*CL)^|ibXYu15&-jj9P_4{W4x4zFLWFT5wc#&Jo_~`^ z)&s(hqg{AVd>lOKF2buU4OKjqo1cPz-~u2B74nw-L*5D*x0}5cvdeCKD`d!S_O6pY zyYa1%gLdQFtYz3H4R3`|`}^Js8MPbV^-%j#@12A9-?)Fm4vm&Vqvg=(qQ4U9Tsr>i zlfOB+7_9n&7yC-Wdu8E0=;=r-@4vI}Mu|wQw|7@%-tH%nXf?peAZcma%lFY1 literal 0 HcmV?d00001 diff --git a/app/modules/coments/__pycache__/schema.cpython-311.pyc b/app/modules/coments/__pycache__/schema.cpython-311.pyc new file mode 100644 index 0000000000000000000000000000000000000000..04967ed127810f95d7e633a46ed699f2c51cace9 GIT binary patch literal 1643 zcmah}KX2Pc6u%>nA}Lvx-NdOQBSVV>g_e3Rf(}X3B91KsO}Y>$2u62F3GhhuNCovq z0~s=O(3Wq|qUblsr%;xFxTOIyWs_k~nfl&QmMY0Wk9R-5d%t&&@6Snpw%bhtTz4=lfVBT>CGgB<4|(sUFoH2%?CkK>2uB#9108eb}%E z=|~P{A)D7_0_RU)`m5~>Y&7)W?AwVImaA6eYqbEhi26- z^Zh}F!R7n;;1?mIuZJh91%?LDQT_;^{LfRhHp_$Z;Pjws?~Dh(|2$z`m~UBkZGWR% zK73Wo`C3rBm)@5e0k_wT^G$dy8o?=)(3+QUG{n~Sd$!sFGqsKI8N%lX#xu4`?Og(T z%drZJ3@YZ8-_^EgwiLzuI@|_k5yi@Nm|X#GLu^cUX6^k^x(9MBqG!LV~$VCMG zeR|UGHCCf`;VbGo!Vbbp61Px?fVt*(02WDqYIyGI z)Vjc2of@|wAzOEjM4m^_#XKQb){1`5SuYW)p_zc6wer!xTwT+BQ#}*K za%7*pyYRu?-juAv z_~999FBa4WrT&zx!}#b7wHFJDS@imptixEIq4r`yH7MOipQ|vA(dRb$T%}BZ{sq&u BZQ1|; literal 0 HcmV?d00001 diff --git a/app/modules/coments/__pycache__/services.cpython-311.pyc b/app/modules/coments/__pycache__/services.cpython-311.pyc new file mode 100644 index 0000000000000000000000000000000000000000..09b135f208393e6a44571fa80466730a9c8515de GIT binary patch literal 4345 zcmd59U1%J~dG`1A?pAm8#+K5PWu0O>`0QFPNn8gv4%m|GTC$`Ni9nB(V|_ca*WSI8 zXZI{iITaK9APdt7zsOJmYB7$3Q|L>;PleXd=RI@8$AG~Q^3b;n>O=5TzuDdUS)JOn z&_d>BzxigqZ@&5Y{^maG>q{UgUw-tJ*;Ekvnsr)543RAtkPT!YgR_v$!PEMqKfHHiHV3}=fyWCLN8 z=M0qRv0!jmGP`l~U7{T)dJC}0;NdXHx-#e~gKQ+e7QdamlMKj-wZ!_*Yszq48TORnMmpmunJtiuXd>KY!8D59 z_sj0k*YRHg*%3by4Y?H8~9;5nR5vqcdc9Wf*8C+D# z$6QtL_55;Ac+_mEoW-SLx#SYvDCcA-$Pfyge{dH~sGwtwG?eHH@d~xz|=IN2Knl@h7#-C{uPqm4fcA>6aSdBH({Y}Kh zfA(D4>kYkC(~j4* zx+X4RC%b@&Z8~K@bfRbVqFd1|b6F=@?6^1^8t)v-hWJL&su;LXf&Av?R5ApDedi$i z7&gp6mVprfR3v2!6K1|tGF@ytGzQaj*Ck{(W7-2Cr*z!L5255WM%vFNC4TY*R+|s zHsh%?FZweZ=3Volv2ND-->mn)3BfmW@LA@_)69`t=4d^0lzC~+2e&6y$JX~eS6^8_ zcW-v{U`;(#R}Xo9eX&#YKG6y89j|U%7MxOokM*}Su*M&-SN|sgoB!{;I*tsnDiqqD z?e2nm2+Ngt3yXRf@VEW2%6FwAq0sg_@Kv=nySt4_@_n_ho8H2!+u{$0N^kE+E_2kd z96;pAiU{klcSTRxzD^{~NmcQ8=+kY_q>tf2xg!2XT;vwf4dGX4kuzi?W^xcAlpsQo z*I}9EqyH){V9T`4(zdAZi{*WO_RH#4w!>hxg2u@#joHDocX>GU%@&_g1}?~wMOSCf zC7k=wzYizmFl>*;O{V}6%Dj#VOI%d0xW!U=ktPgmVHX<(9kOx@zqr&1G&J6R##03X zlXX!qUWMnK|8`?ZyDRW;*kL}?9bW>G?R35UaTX=BojULb<^LUDF4VNCx;EvhQ%zBc zk8zFc!PRqhb?Es>?*4FX>_&aDb_)PtLEMzddfcKWgI4V{Ks)6UejGoE_pJ19+w&18sz zc4fT5cf9l|PdVkVi2IkfPwyV;PtUn!jn@H;L|ykDuqG`?4VGfi9#WG zCIhY(3fCYRg%s6+|QP#ghe#MG68uN02NGlv>jkw=Dg&m44hRMh)vb!P60Q_hUQO#-#msTpw|KINo+LhPtv4!*(7M#BxpLI%^evHPRkBDolDb{ zbIsDN;$>_vjh2ZW+?xnQD!WSyX6X`PwoYU7I$ZC9No3Z`z(1DJ@ZZX4=(wzpEhl&k z@5tb=RrEk9?0N%Lu%H=SdsG!Km3M*_-X&*&h5ey(z68(|IF4(e*Su(Lpdl|>8)(pr k)&?5!qP2lWy=ZM9?0sKt%5QOS&As4THujGl2>zY_6BXXYUH||9 literal 0 HcmV?d00001 diff --git a/app/modules/coments/route.py b/app/modules/coments/route.py index e69de29..83947ff 100644 --- a/app/modules/coments/route.py +++ b/app/modules/coments/route.py @@ -0,0 +1,116 @@ +from fastapi import APIRouter, Depends, HTTPException, Query, Header, status +from fastapi.security import HTTPAuthorizationCredentials, HTTPBearer +from sqlalchemy.orm import Session +from typing import Optional, List +# +from database import get_db +from app.core.auth import get_current_user +from app.modules.users.models import Users # Modelo base de usuario +from app.modules.coments.models import Coments +from app.modules.coments.schema import Commentupdate, CommentCreate, CommentResponse, MessageResponse +from app.modules.coments.services import ComentsService + +router = APIRouter(prefix="/coments", tags=["coments"]) +security = HTTPBearer() + +#================ Create ==================== +@router.post("/create", response_model=CommentResponse, status_code=status.HTTP_201_CREATED) +async def create_coments( + data: CommentCreate, + db: Session = Depends(get_db), + current_user: Users = Depends(get_current_user) +): + """Create a coments - Requires authentication""" + + if not current_user: + raise HTTPException(status_code=401, detail="User not found - invalid token") + + if current_user.tipo_usuario not in ["root", "admin"]: + raise HTTPException(status_code=403, detail="You don't have permission to create coments") + + try: + result = ComentsService.create_coments(db=db, data=data) + return result + except ValueError as e: + raise HTTPException(status_code=400, detail=str(e)) + +#================ Get ==================== +@router.get("/", response_model=List[CommentResponse]) +def get_comentss( + db: Session = Depends(get_db), + current_user: Users = Depends(get_current_user), + skip: int = Query(0, ge=0, description="Number of records to skip"), + limit: int = Query(100, ge=1, le=1000, description="Max number of records to return") +): + """Get list with pagination - requires authentication""" + + if not current_user: + raise HTTPException(status_code=401, detail="Authentication required") + + return ComentsService.get_coments(db=db, skip=skip, limit=limit) + +#================ Get by ID ==================== +@router.get("/{{{entity_name}}_id}", response_model=CommentResponse) +def get_coments_by_id( + coments_id: int, + db: Session = Depends(get_db), + current_user: Users = Depends(get_current_user) +): + """Get coments by ID - requires authentication""" + + if not current_user: + raise HTTPException(status_code=401, detail="Authentication required") + + try: + result = ComentsService.get_coments(db=db, coments_id=coments_id, current_user=current_user) + return result + except ValueError as e: + raise HTTPException(status_code=404, detail=str(e)) + +#================ Update ==================== +@router.patch("/update/{{{entity_name}}_id}", response_model=CommentResponse) +async def update_coments( + coments_id: int, + data: Commentupdate , + db: Session = Depends(get_db), + current_user: Users = Depends(get_current_user) +): + """Update existing coments - requires authentication""" + + if not current_user: + raise HTTPException(status_code=401, detail="Authentication required") + + if current_user.tipo_usuario not in ["root", "admin"]: + raise HTTPException(status_code=403, detail="You don't have permission to update coments") + + try: + result = ComentsService.update_coments( + db=db, + coments_id=coments_id, + data=data, + current_user=current_user + ) + return result + except ValueError as e: + raise HTTPException(status_code=404, detail=str(e)) + +#================ Delete ==================== +@router.delete("/delete/{{{entity_name}}_id}", response_model=MessageResponse, status_code=status.HTTP_200_OK) +async def delete_coments( + coments_id: int, + db: Session = Depends(get_db), + current_user: Users = Depends(get_current_user) +): + """Delete coments by ID - requires authentication""" + + if not current_user: + raise HTTPException(status_code=401, detail="Authentication required") + + if current_user.tipo_usuario not in ["root", "admin"]: + raise HTTPException(status_code=403, detail="You don't have permission to delete coments") + + try: + result = ComentsService.delete_coments(db=db, coments_id=coments_id, current_user=current_user) + return {"message": "coments deleted successfully"} + except ValueError as e: + raise HTTPException(status_code=404, detail=str(e)) \ No newline at end of file diff --git a/app/modules/coments/schema.py b/app/modules/coments/schema.py index 27448b1..24776d3 100644 --- a/app/modules/coments/schema.py +++ b/app/modules/coments/schema.py @@ -6,7 +6,7 @@ import re from enum import Enum class CommentCreate(BaseModel): - texto: str = Field(..., max(380), min(30)) + texto: str user_id: Optional[int] feed_id: Optional[int] is_active: bool = True diff --git a/app/modules/coments/services.py b/app/modules/coments/services.py index e69de29..7f89713 100644 --- a/app/modules/coments/services.py +++ b/app/modules/coments/services.py @@ -0,0 +1,63 @@ +from sqlalchemy.orm import Session +from datetime import datetime +from typing import Optional +from fastapi import HTTPException +from app.modules.coments.models import Coments +from app.modules.coments.schema import CommentCreate, CommentResponse, Commentupdate, MessageResponse + + +class ComentsService: + @staticmethod + def create_coments(db: Session, data: CommentCreate): + new_coments = Coments(**data.dict()) + db.add(new_coments) + db.commit() + db.refresh(new_coments) + return new_coments + + @staticmethod + def get_coments(db: Session, coments_id: int, current_user): + coments = db.query(Coments).filter(Coments.id == coments_id).first() + if not coments: + raise ValueError("coments no encontrado") + return coments + + @staticmethod + def update_coments(db: Session, coments_id: int, data:Commentupdate , current_user): + coments = db.query(Coments).filter(Coments.id == coments_id).first() + if not coments: + raise ValueError("coments no encontrado") + + if current_user.role not in ["ROOT", "ADMIN"]: + raise ValueError("No tienes permisos para actualizar este coments") + + update_data = data.dict(exclude_unset=True) + for key, value in update_data.items(): + setattr(coments, key, value) + + db.commit() + db.refresh(coments) + return coments + + @staticmethod + def delete_coments(db: Session, coments_id: int, current_user): + coments = db.query(Coments).filter(Coments.id == coments_id).first() + if not coments: + raise ValueError("coments no encontrado") + + if current_user.role not in ["ROOT", "ADMIN"]: + raise ValueError("No tienes permisos para eliminar este coments") + + try: + coments.is_active = False + coments.deleted_at = datetime.utcnow() + coments.deleted_by = current_user.id + db.commit() + db.refresh(coments) + except Exception as e: + db.rollback() + raise ValueError(f"Error al eliminar el coments: {e}") + + return {"message": "coments eliminado correctamente"} + + \ No newline at end of file diff --git a/app/modules/configuration/__pycache__/route.cpython-311.pyc b/app/modules/configuration/__pycache__/route.cpython-311.pyc new file mode 100644 index 0000000000000000000000000000000000000000..a10d8fce7d782aa6bab6e2014a52698a4e8d4f07 GIT binary patch literal 6211 zcmc&2OKcm*b(Xu!zbI1HkJQKOzv;x1Wh-%FyGdx-ae~N-;!jZ1Mbs5{B(1YcGP6tD zqA5pk3RDGpP|y_dtvX*hnfD$2wyn*N;Mu$IH}!`Og#Jzk^@q*C;K4GF(3eO-3a25ROLDp^>C*Wm zuM0^*7n7pyPP#cd@6tTFH|f=VNgo^YnqLnj1FSD-LA@>6riYRtHWsyZJ)8`)zFUjv z9mx*X_h{Sn&SWR+d$lgTJK4?pKCMUZP4?>1WK@qOV|rh*kHP&~zdn#0;E)SpP6;T% zS#G86t_z{B;Hy5#L74O1g~3;K5K3;xgLkCHu&JYja1^_*?5KlQ+V8^tzk;v&04)~| z-{k-XUlXju37c^#VH{H;IG}Xk&Kb9|?Pua+GVBBycGYP#|00asCv09Z)E5L5xt3ESAU20_j?^Xu!?isJLeUtQio+!P9qyMeM zaB4e%=f9^xVOREtL)yydq41wH}kCbl|8r*tmZ&{`~p_v z-2dK9GQ6bhJCEY~?^9NBx9v+zzI!f{GcmC}r*Iah6~k_O=fZ`_)7MitYpR*FEq;*0 zWZrhagJlKK+=eNeIV0|}`zc-`XU=7anwKf=7{Lloo2slCwx7MrOty_>(lhF8jxb(v!4B2{ zSw%Ln9jcDbVI!MK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d1nK%eS@6Xj(>tsBpCUeB?b*J(V{|5{9(kH@*ag!QF!6%4pnrp0|unTdm$Q z+G#o8GTLFade>2(<$TNNfaQE!L5^9-@s`n?^{lsyPFl`)-Pf@cwPFXp9=1kKTE4NO zZ>;1STXdHLT}#J)apIRJ7QGcWa(RE=cdKvd(w&>%zFHbfF7_3<%O&nI%xsG-@4LPC z^WiUs%ds7|_gOm+7h^|Cu_F~vgo8^RG-ZExg@@mDZ+k_gKv>kfG0kv(;F0Sm9Hr=@ z82c&1*sa*o*d5`{MQ1RLnGMjLZovjJz%pI60lJK> HWsdtF$Q3D~ literal 0 HcmV?d00001 diff --git a/app/modules/configuration/__pycache__/schema.cpython-311.pyc b/app/modules/configuration/__pycache__/schema.cpython-311.pyc new file mode 100644 index 0000000000000000000000000000000000000000..d5ddefa67598e2b1b3d53b0a965abf1863b99906 GIT binary patch literal 1806 zcma)6&2Jk;6rb6hwRimyC$uFYQN_WB;7cQJfI<(1@*yRTMCoOPwAy-xbfx`bX5BUt zm9`Q>960!Z)cyq^#DBnFVPDW{Pe`1&IZ94F@!qT*W4jW}zWMph`;FhuZ|2SZ(rz~h zw1aQ|2tG3i`3nd0X3d<--@$o7IN>xT5p`)~xJG2UX2e`ZF>ZubWVx31&9D~L-MaQ! zXuCG>R_H_xw?TN9pQCBe>MsE4SLnwrsizm9MN3iTAFJB*IeV;nri{qUdy?` z*?rR6_#0o*W2N(vuf$2hMOfPRB0mW4XR@?D2}Hz}!R%kN?Mf(YVLPF&*wY?f;ZCakxvXNwv)4q*gLeT^|^jJ?LN z8RM)mmS$>hLo^|Gy_yGt?Xq>0#9s$zM^b>0e(9(vOT9;l%4Tkw$hkXILY8ekA@!Ad zl1Tn#=>*F22U+k~^jf9ud9fb}&np|A7bSccqTlkoZ-#zYF|q}^qzzD-3O2Rld43!x znU7niJWsZf-$3XfY~oDzFiFB+$tC#Y)jJ1%n(AJ?K^+XVgrU?q4%Fb0i2OV0xolzr z1P8j30QtY3;_Yt!`43N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5-SR5lc!OnSwqC9i0a<{-e- z6mL*Mm}2NCTGC;(Y^Tj3dprDH(+$t1;%=99-B69}6>P4K=85T_9}k_bXs;IZ+%lnd z;D(k|IOc**L|Rke-_vOQpVMf-v}r3gEdSa44KRz&sQMR0kKDf=>Tdn32wu+%>1}_u zACfZwp?^26zXGXo48v5>Yfdm%(SQ@oRdm=1<|-O=g1L%LIKf;+SDbIlHSst@556<~ N%4`4UOM1PV_&3O?5Ci}K literal 0 HcmV?d00001 diff --git a/app/modules/configuration/route.py b/app/modules/configuration/route.py index e69de29..2ce7777 100644 --- a/app/modules/configuration/route.py +++ b/app/modules/configuration/route.py @@ -0,0 +1,116 @@ +from fastapi import APIRouter, Depends, HTTPException, Query, Header, status +from fastapi.security import HTTPAuthorizationCredentials, HTTPBearer +from sqlalchemy.orm import Session +from typing import Optional, List +# +from database import get_db +from app.core.auth import get_current_user +from app.modules.users.models import Users # Modelo base de usuario +from app.modules.configuration.models import Configuration +from app.modules.configuration.schema import Configupdate, ConfigResponse, ConfigCreate, MessageResponse +from app.modules.configuration.service import ConfigurationService + +router = APIRouter(prefix="/configuration", tags=["configuration"]) +security = HTTPBearer() + +#================ Create ==================== +@router.post("/create", response_model=ConfigResponse, status_code=status.HTTP_201_CREATED) +async def create_configuration( + data: ConfigCreate , + db: Session = Depends(get_db), + current_user: Users = Depends(get_current_user) +): + """Create a configuration - Requires authentication""" + + if not current_user: + raise HTTPException(status_code=401, detail="User not found - invalid token") + + if current_user.tipo_usuario not in ["root", "admin"]: + raise HTTPException(status_code=403, detail="You don't have permission to create configuration") + + try: + result = ConfigurationService.create_configuration(db=db, data=data) + return result + except ValueError as e: + raise HTTPException(status_code=400, detail=str(e)) + +#================ Get ==================== +@router.get("/", response_model=List[ConfigResponse]) +def get_configurations( + db: Session = Depends(get_db), + current_user: Users = Depends(get_current_user), + skip: int = Query(0, ge=0, description="Number of records to skip"), + limit: int = Query(100, ge=1, le=1000, description="Max number of records to return") +): + """Get list with pagination - requires authentication""" + + if not current_user: + raise HTTPException(status_code=401, detail="Authentication required") + + return ConfigurationService.get_configuration(db=db, skip=skip, limit=limit) + +#================ Get by ID ==================== +@router.get("/{{{entity_name}}_id}", response_model=ConfigResponse) +def get_configuration_by_id( + configuration_id: int, + db: Session = Depends(get_db), + current_user: Users = Depends(get_current_user) +): + """Get configuration by ID - requires authentication""" + + if not current_user: + raise HTTPException(status_code=401, detail="Authentication required") + + try: + result = ConfigurationService.get_configuration(db=db, configuration_id=configuration_id, current_user=current_user) + return result + except ValueError as e: + raise HTTPException(status_code=404, detail=str(e)) + +#================ Update ==================== +@router.patch("/update/{{{entity_name}}_id}", response_model=ConfigResponse) +async def update_configuration( + configuration_id: int, + data: Configupdate, + db: Session = Depends(get_db), + current_user: Users = Depends(get_current_user) +): + """Update existing configuration - requires authentication""" + + if not current_user: + raise HTTPException(status_code=401, detail="Authentication required") + + if current_user.tipo_usuario not in ["root", "admin"]: + raise HTTPException(status_code=403, detail="You don't have permission to update configuration") + + try: + result = ConfigurationService.update_configuration( + db=db, + configuration_id=configuration_id, + data=data, + current_user=current_user + ) + return result + except ValueError as e: + raise HTTPException(status_code=404, detail=str(e)) + +#================ Delete ==================== +@router.delete("/delete/{{{entity_name}}_id}", response_model=MessageResponse, status_code=status.HTTP_200_OK) +async def delete_configuration( + configuration_id: int, + db: Session = Depends(get_db), + current_user: Users = Depends(get_current_user) +): + """Delete configuration by ID - requires authentication""" + + if not current_user: + raise HTTPException(status_code=401, detail="Authentication required") + + if current_user.tipo_usuario not in ["root", "admin"]: + raise HTTPException(status_code=403, detail="You don't have permission to delete configuration") + + try: + result = ConfigurationService.delete_configuration(db=db, configuration_id=configuration_id, current_user=current_user) + return {"message": "configuration deleted successfully"} + except ValueError as e: + raise HTTPException(status_code=404, detail=str(e)) \ No newline at end of file diff --git a/app/modules/configuration/schema.py b/app/modules/configuration/schema.py index 8400551..300f01d 100644 --- a/app/modules/configuration/schema.py +++ b/app/modules/configuration/schema.py @@ -12,7 +12,7 @@ class ConfigCreate(BaseModel): smtp_user: Optional[str] = None smtp_password: Optional[str] = None is_active: bool = True -class Commentupdate(ConfigCreate): +class Configupdate(ConfigCreate): pass class ConfigResponse(ConfigCreate): created_at: datetime diff --git a/output/generated/services/configuration_service.py b/app/modules/configuration/service.py similarity index 91% rename from output/generated/services/configuration_service.py rename to app/modules/configuration/service.py index 90b6ff7..cc600ca 100644 --- a/output/generated/services/configuration_service.py +++ b/app/modules/configuration/service.py @@ -3,15 +3,12 @@ from datetime import datetime from typing import Optional from fastapi import HTTPException from app.modules.configuration.models import Configuration -from app.modules.configuration.schema import +from app.modules.configuration.schema import ConfigCreate, ConfigResponse, Configupdate, MessageResponse class ConfigurationService: @staticmethod - def create_configuration(db: Session, data: ): - - - + def create_configuration(db: Session, data: ConfigCreate): new_configuration = Configuration(**data.dict()) db.add(new_configuration) @@ -27,7 +24,7 @@ class ConfigurationService: return configuration @staticmethod - def update_configuration(db: Session, configuration_id: int, data: , current_user): + def update_configuration(db: Session, configuration_id: int, data: Configupdate , current_user): configuration = db.query(Configuration).filter(Configuration.id == configuration_id).first() if not configuration: raise ValueError("configuration no encontrado") diff --git a/app/modules/credits/__pycache__/models.cpython-311.pyc b/app/modules/credits/__pycache__/models.cpython-311.pyc index b551feaf1440d51fff3bd1b277e74a698c616fba..aad218ae6e8c87e148d1a781fb3362f5b83d0339 100644 GIT binary patch delta 20 acmeB|=$GJL&dbZi00gBe*EVvq@BjcYumqq0 delta 20 acmeB|=$GJL&dbZi00h#-XE$=Q@BjcWX9P?D diff --git a/app/modules/credits/route.py b/app/modules/credits/route.py index e69de29..33ebf7d 100644 --- a/app/modules/credits/route.py +++ b/app/modules/credits/route.py @@ -0,0 +1,116 @@ +from fastapi import APIRouter, Depends, HTTPException, Query, Header, status +from fastapi.security import HTTPAuthorizationCredentials, HTTPBearer +from sqlalchemy.orm import Session +from typing import Optional, List +# +from database import get_db +from app.core.auth import get_current_user +from app.modules.users.models import Users # Modelo base de usuario +from app.modules.credits.models import Credits +from app.modules.credits.schema import CreditsCreate, CreditsResponse, CreditsUpdate, MessageResponse +from app.modules.credits.service import CreditsService + +router = APIRouter(prefix="/credits", tags=["credits"]) +security = HTTPBearer() + +#================ Create ==================== +@router.post("/create", response_model=CreditsResponse, status_code=status.HTTP_201_CREATED) +async def create_credits( + data: CreditsCreate, + db: Session = Depends(get_db), + current_user: Users = Depends(get_current_user) +): + """Create a credits - Requires authentication""" + + if not current_user: + raise HTTPException(status_code=401, detail="User not found - invalid token") + + if current_user.tipo_usuario not in ["root", "admin"]: + raise HTTPException(status_code=403, detail="You don't have permission to create credits") + + try: + result = CreditsService.create_credits(db=db, data=data) + return result + except ValueError as e: + raise HTTPException(status_code=400, detail=str(e)) + +#================ Get ==================== +@router.get("/", response_model=List[CreditsResponse]) +def get_creditss( + db: Session = Depends(get_db), + current_user: Users = Depends(get_current_user), + skip: int = Query(0, ge=0, description="Number of records to skip"), + limit: int = Query(100, ge=1, le=1000, description="Max number of records to return") +): + """Get list with pagination - requires authentication""" + + if not current_user: + raise HTTPException(status_code=401, detail="Authentication required") + + return CreditsService.get_creditss(db=db, skip=skip, limit=limit) + +#================ Get by ID ==================== +@router.get("/{{{entity_name}}_id}", response_model=CreditsResponse) +def get_credits_by_id( + credits_id: int, + db: Session = Depends(get_db), + current_user: Users = Depends(get_current_user) +): + """Get credits by ID - requires authentication""" + + if not current_user: + raise HTTPException(status_code=401, detail="Authentication required") + + try: + result = CreditsService.get_credits(db=db, credits_id=credits_id, current_user=current_user) + return result + except ValueError as e: + raise HTTPException(status_code=404, detail=str(e)) + +#================ Update ==================== +@router.patch("/update/{{{entity_name}}_id}", response_model=CreditsResponse) +async def update_credits( + credits_id: int, + data: CreditsUpdate, + db: Session = Depends(get_db), + current_user: Users = Depends(get_current_user) +): + """Update existing credits - requires authentication""" + + if not current_user: + raise HTTPException(status_code=401, detail="Authentication required") + + if current_user.tipo_usuario not in ["root", "admin"]: + raise HTTPException(status_code=403, detail="You don't have permission to update credits") + + try: + result = CreditsService.update_credits( + db=db, + credits_id=credits_id, + data=data, + current_user=current_user + ) + return result + except ValueError as e: + raise HTTPException(status_code=404, detail=str(e)) + +#================ Delete ==================== +@router.delete("/delete/{{{entity_name}}_id}", response_model=MessageResponse ,status_code=status.HTTP_200_OK) +async def delete_credits( + credits_id: int, + db: Session = Depends(get_db), + current_user: Users = Depends(get_current_user) +): + """Delete credits by ID - requires authentication""" + + if not current_user: + raise HTTPException(status_code=401, detail="Authentication required") + + if current_user.tipo_usuario not in ["root", "admin"]: + raise HTTPException(status_code=403, detail="You don't have permission to delete credits") + + try: + result = CreditsService.delete_credits(db=db, credits_id=credits_id, current_user=current_user) + return {"message": "credits deleted successfully"} + except ValueError as e: + raise HTTPException(status_code=404, detail=str(e)) \ No newline at end of file diff --git a/app/modules/credits/schema.py b/app/modules/credits/schema.py index efc50a4..bd6ddde 100644 --- a/app/modules/credits/schema.py +++ b/app/modules/credits/schema.py @@ -3,4 +3,42 @@ from datetime import datetime from typing import Optional # import re -from enum import Enum \ No newline at end of file +from enum import Enum + +class Supuestos(Enum): + CANCELADOS ="cancelados" + CONDONADOS ="condonados" + FIRMES ="firmes" + SENTENCIAS ="sentencias" + EXIGIBLES ="exigibles" + RETORNO_INVERSIONES ="retorno_inversiones" + FRACCION_X ="fraccion_x" + FRACCION_VII ="fraccion_vii" + NO_LOCALIZADOS ="no_localizados" + +class CreditsCreate(BaseModel): + title:str + rfc : str + razon_social : str + tipo_persona : str + supuesto : Supuestos + fecha_prim_publicacion : datetime + fecha_ley : datetime + fecha_cancelacion : datetime + fecha_csd : datetime + entidad_federativa : str + monto : Optional[int] = None + motivo : Optional[str] = None + location_id : int + + +class CreditsUpdate(CreditsCreate): + pass + +class CreditsResponse(CreditsCreate): + creted_at: datetime + updated_at: Optional[datetime] + uploader_at : Optional[datetime] + +class MessageResponse(BaseModel): + message: str \ No newline at end of file diff --git a/output/generated/services/credits_service.py b/app/modules/credits/service.py similarity index 88% rename from output/generated/services/credits_service.py rename to app/modules/credits/service.py index 5a2deb1..1d30769 100644 --- a/output/generated/services/credits_service.py +++ b/app/modules/credits/service.py @@ -3,16 +3,12 @@ from datetime import datetime from typing import Optional from fastapi import HTTPException from app.modules.credits.models import Credits -from app.modules.credits.schema import +from app.modules.credits.schema import CreditsCreate, CreditsUpdate, CerditsResponse, MessageResponse class CreditsService: @staticmethod - def create_credits(db: Session, data: ): - - - - + def create_credits(db: Session, data:CreditsCreate ): new_credits = Credits(**data.dict()) db.add(new_credits) db.commit() @@ -27,7 +23,7 @@ class CreditsService: return credits @staticmethod - def update_credits(db: Session, credits_id: int, data: , current_user): + def update_credits(db: Session, credits_id: int, data:CreditsUpdate , current_user): credits = db.query(Credits).filter(Credits.id == credits_id).first() if not credits: raise ValueError("credits no encontrado") diff --git a/app/modules/edos/__pycache__/models.cpython-311.pyc b/app/modules/edos/__pycache__/models.cpython-311.pyc index 1efdb9cc709e44f55e15bdeef76647f925c4f1da..509dd083e522526f5b21b433326cdaf81f31da5e 100644 GIT binary patch delta 47 zcmdlaut|V-IWI340}$+-do8nOBd;Ozm3ynYcnOh#OxNH@+fny!k(?F%tk# Cst&3E delta 45 zcmdlaut|V-IWI340}zx4oz1M>$ZN>V$h_H}c^eZ~=ml|;i{d6%#7#E;XEkO502!DK A9RL6T diff --git a/app/modules/edos/__pycache__/route.cpython-311.pyc b/app/modules/edos/__pycache__/route.cpython-311.pyc new file mode 100644 index 0000000000000000000000000000000000000000..4abc7574baf76dcbea4fb03776a12c83320433e1 GIT binary patch literal 3447 zcmb7{Uu@gP8NiR?ACZzJ*|J^Rwc{|c(L|kXd5KWeZsEOLJx*9WePc zZwhIFWBPz0no?Tw^Slu><+N-nX~hhsL%vQh!e&>xi$eiKI4ojmmD>s441y|~!r=%}NQ{J50z-QZ&`JPDKNs&qd3#@% z?mjeLtUVrh>;Vtmp9`HHaL*D-#Gf*s3Bgn5FP^_-0Sg7@Sf`F5J&35$Bh@%Z^Hv+Dw*vjvB08ONeU zIjQC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Ya1WsWL-_nBAH`vqbIeJ+b#)A!%_!t{si-W* zq-*3>RWTrpOH)pyXxuJTiRwf!StyWd*%35(zCiRj!{LcyR!O-SZkdEufRFOeDuC}n zFebCD#Y_!-ik3qUK=yD;&LDG#h2L&1N(}}3y$zbB@Ddxa7&0T<_G{tbh))p?*I4k# z2Iadvwth^sd;Ag?@WlpvaY38li(B61pFuUw5HKtQypdT33-{TXU`C>5d`J8o<_~SL zb$*N7K?E0ZcMN-TTjQ4aT8JF3@iR(4Q{{B&!FSTY};Oz zUPMNhB7rO=&D6HO7TKMpy(KLp-S31wluCIeD1#BDAB2V4P2BG_T zv1dw`487PZ@{}NMH`qcVqKmZMK zxG4@>;_!1G^}N)SUjDMLA?2DfLtQqU4S8A&@AORlD`)xy^E zI1OVD_BK1S>%VSv4mUf8?_TkSom(re_pfNHnw381Lqi;CiX)advazqrMSLQ?(bsSH z{@9j!?4vpB$haHj4yIk?qg48N5+%}BdTh;Hzw*T!pHDu?jy%qeG_vQL+4GIQ3(dX@ zpaf`$xu%%2#GEUjuH$znH`+U06iS@8k7U*}>u1(8%_FBij6Y58w+@V~UjgJpBRSek zj#|l4mq#5C50iL}@jAWw=kYJ%jqFG>3q4=;p^=3ti@p`<`oo#k!t?uljl-+gAK7GOJy1aaf)$I@U!8fr>I zjjof;u9H^R$w$-nPll`?o&BW0K2#s858cmxlKnE|CL$eeF7i>L?Yrk`lsx1jHVXM^ zAur4QYvKCX3ct!*>3)EQm}!a`OU&3}x77k$-2X&8`dB>L5PO zxgoM dict: + """ flow download and parsing, filter and adapt""" + + + try: + # X - EXTRACT + print(f"📥 Descargando CSV: {csv_url}") + + # ✅ Ahora download_csv retorna (content, encoding) + content, encoding = CSVExtractor.download_csv(csv_url) + print(f" ✅ Descargado {len(content)} bytes, encoding: {encoding}") + + # Parsear CSV + raw_rows = CSVExtractor.read_csv(content) + print(f" ✅ Parseadas {len(raw_rows)} filas") + + if not raw_rows: + return { + 'total_extracted': 0, + 'total_mapped': 0, + 'inserted': 0, + 'errors': ['No se encontraron datos en el CSV'] + } + + # Mostrar columnas encontradas + print(f" 📋 Columnas: {list(raw_rows[0].keys())}") + + # M - MAP (si tienes mapper) + # Por ahora, usar datos crudos + mapped_rows = raw_rows + + if max_rows: + mapped_rows = mapped_rows[:max_rows] + print(f" 🔒 Limitado a {max_rows} filas") + + # A - ADAPT + if not dry_run: + print(f" 💾 Insertando {len(mapped_rows)} filas en BD") + # Aquí iría la inserción en BD + + return { + 'total_extracted': len(raw_rows), + 'total_mapped': len(mapped_rows), + 'inserted': len(mapped_rows) if not dry_run else 0, + 'dry_run': dry_run, + 'columns': list(raw_rows[0].keys()) if raw_rows else [], + 'sample': raw_rows[:2] if raw_rows else [] + } + + except Exception as e: + print(f"❌ Error: {str(e)}") + import traceback + traceback.print_exc() + raise diff --git a/app/modules/efos/schema.py b/app/modules/efos/schema.py index efc50a4..d668b37 100644 --- a/app/modules/efos/schema.py +++ b/app/modules/efos/schema.py @@ -1,6 +1,32 @@ from pydantic import BaseModel, EmailStr, Field, validator -from datetime import datetime +from datetime import datetime, date from typing import Optional # import re -from enum import Enum \ No newline at end of file +from enum import Enum + +class Situacion(Enum): + DEFINITIVO ="definitivo" + DESVIRTUADO ="desvituado" + PRESUNTO ="presunto" + SENTENCIA_FAVORABLE ="sentencia_favorable" + +class EfosBase(BaseModel): + numero: int + rfc : str + nombre_contribuyente: str + situacion: Situacion + publi_presuntos_sat: str + publi_desvirtuados_sat: date + publi_definitivos_sat: date + publi_favorable_sat: date + +class EfosResponse(EfosBase): + cretaed_at : datetime + updated_at: Optional[datetime] = None + + loader_by: int + +class messageResponse(BaseModel): + message: str + \ No newline at end of file diff --git a/app/modules/feed/route.py b/app/modules/feed/route.py index e69de29..aa9154a 100644 --- a/app/modules/feed/route.py +++ b/app/modules/feed/route.py @@ -0,0 +1,116 @@ +from fastapi import APIRouter, Depends, HTTPException, Query, Header, status +from fastapi.security import HTTPAuthorizationCredentials, HTTPBearer +from sqlalchemy.orm import Session +from typing import Optional, List +# +from database import get_db +from app.core.auth import get_current_user +from app.modules.users.models import Users # Modelo base de usuario +from app.modules.feed.models import Feed +from app.modules.feed.schema import FeedUpdate, FeedCreate, FeedResponse, messageResponse +from app.modules.feed.service import FeedService + +router = APIRouter(prefix="/feed", tags=["feed"]) +security = HTTPBearer() + +#================ Create ==================== +@router.post("/create", response_model=FeedResponse, status_code=status.HTTP_201_CREATED) +async def create_feed( + data: FeedCreate, + db: Session = Depends(get_db), + current_user: Users = Depends(get_current_user) +): + """Create a feed - Requires authentication""" + + if not current_user: + raise HTTPException(status_code=401, detail="User not found - invalid token") + + if current_user.tipo_usuario not in ["root", "admin"]: + raise HTTPException(status_code=403, detail="You don't have permission to create feed") + + try: + result = FeedService.create_feed(db=db, data=data) + return result + except ValueError as e: + raise HTTPException(status_code=400, detail=str(e)) + +#================ Get ==================== +@router.get("/", response_model=List[FeedResponse]) +def get_feeds( + db: Session = Depends(get_db), + current_user: Users = Depends(get_current_user), + skip: int = Query(0, ge=0, description="Number of records to skip"), + limit: int = Query(100, ge=1, le=1000, description="Max number of records to return") +): + """Get list with pagination - requires authentication""" + + if not current_user: + raise HTTPException(status_code=401, detail="Authentication required") + + return FeedService.get_feeds(db=db, skip=skip, limit=limit) + +#================ Get by ID ==================== +@router.get("/{{{entity_name}}_id}", response_model=FeedResponse) +def get_feed_by_id( + feed_id: int, + db: Session = Depends(get_db), + current_user: Users = Depends(get_current_user) +): + """Get feed by ID - requires authentication""" + + if not current_user: + raise HTTPException(status_code=401, detail="Authentication required") + + try: + result = FeedService.get_feed(db=db, feed_id=feed_id, current_user=current_user) + return result + except ValueError as e: + raise HTTPException(status_code=404, detail=str(e)) + +#================ Update ==================== +@router.patch("/update/{{{entity_name}}_id}", response_model=FeedResponse) +async def update_feed( + feed_id: int, + data: FeedUpdate, + db: Session = Depends(get_db), + current_user: Users = Depends(get_current_user) +): + """Update existing feed - requires authentication""" + + if not current_user: + raise HTTPException(status_code=401, detail="Authentication required") + + if current_user.tipo_usuario not in ["root", "admin"]: + raise HTTPException(status_code=403, detail="You don't have permission to update feed") + + try: + result = FeedService.update_feed( + db=db, + feed_id=feed_id, + data=data, + current_user=current_user + ) + return result + except ValueError as e: + raise HTTPException(status_code=404, detail=str(e)) + +#================ Delete ==================== +@router.delete("/delete/{{{entity_name}}_id}", response_model= messageResponse, status_code=status.HTTP_200_OK) +async def delete_feed( + feed_id: int, + db: Session = Depends(get_db), + current_user: Users = Depends(get_current_user) +): + """Delete feed by ID - requires authentication""" + + if not current_user: + raise HTTPException(status_code=401, detail="Authentication required") + + if current_user.tipo_usuario not in ["root", "admin"]: + raise HTTPException(status_code=403, detail="You don't have permission to delete feed") + + try: + result = FeedService.delete_feed(db=db, feed_id=feed_id, current_user=current_user) + return {"message": "feed deleted successfully"} + except ValueError as e: + raise HTTPException(status_code=404, detail=str(e)) \ No newline at end of file diff --git a/app/modules/feed/schema.py b/app/modules/feed/schema.py index efc50a4..a14d36d 100644 --- a/app/modules/feed/schema.py +++ b/app/modules/feed/schema.py @@ -1,6 +1,31 @@ from pydantic import BaseModel, EmailStr, Field, validator -from datetime import datetime +from datetime import datetime, date from typing import Optional # import re -from enum import Enum \ No newline at end of file +from enum import Enum + +class FeedBase(BaseModel): + title: str + body: Optional[str] = None + document_url: str + publication_date: date + is_important : bool = False + +class FeedCreate(FeedBase): + user_id: int + file_id: Optional[int] = None + +class FeedUpdate(BaseModel): + body: str + +class FeedResponse(FeedBase): + created_at: datetime + updated_at: Optional[datetime] =None + created_by : Optional[int] = None + updated_by : Optional[int] = None + +class messageResponse(BaseModel): + message: str + + diff --git a/output/generated/services/feed_service.py b/app/modules/feed/service.py similarity index 89% rename from output/generated/services/feed_service.py rename to app/modules/feed/service.py index 8af60aa..6c1c50d 100644 --- a/output/generated/services/feed_service.py +++ b/app/modules/feed/service.py @@ -3,16 +3,12 @@ from datetime import datetime from typing import Optional from fastapi import HTTPException from app.modules.feed.models import Feed -from app.modules.feed.schema import +from app.modules.feed.schema import FeedCreate, FeedResponse, FeedUpdate, messageResponse class FeedService: @staticmethod - def create_feed(db: Session, data: ): - - - - + def create_feed(db: Session, data: FeedCreate ): new_feed = Feed(**data.dict()) db.add(new_feed) db.commit() @@ -27,7 +23,7 @@ class FeedService: return feed @staticmethod - def update_feed(db: Session, feed_id: int, data: , current_user): + def update_feed(db: Session, feed_id: int, data: FeedUpdate , current_user): feed = db.query(Feed).filter(Feed.id == feed_id).first() if not feed: raise ValueError("feed no encontrado") diff --git a/app/modules/files/schema.py b/app/modules/files/schema.py index efc50a4..c4c1210 100644 --- a/app/modules/files/schema.py +++ b/app/modules/files/schema.py @@ -1,6 +1,27 @@ from pydantic import BaseModel, EmailStr, Field, validator -from datetime import datetime +from datetime import datetime, date from typing import Optional # import re -from enum import Enum \ No newline at end of file +from enum import Enum + +class FileBase(BaseModel): + title: str + summary: str + document_url : str + file_type : str + file_size : str + feed_id: str + +class FileCreate(FileBase): + feed_id: int + +class FileResponse(FileBase): + cretaed_at: datetime + updated_at: Optional[datetime] = None + uploader_by: int + updated_by: Optional[int] = None + +class messageResponse(BaseModel): + message: str + diff --git a/app/modules/files/service.py b/app/modules/files/service.py new file mode 100644 index 0000000..e69de29 diff --git a/app/modules/interactions/schema.py b/app/modules/interactions/schema.py index efc50a4..eeeda41 100644 --- a/app/modules/interactions/schema.py +++ b/app/modules/interactions/schema.py @@ -1,6 +1,26 @@ from pydantic import BaseModel, EmailStr, Field, validator -from datetime import datetime +from datetime import datetime, date from typing import Optional # import re -from enum import Enum \ No newline at end of file +from enum import Enum + + +class Interacction(Enum): + LIKE = "like" + DONT_LIKE = "dont_like" + APPROVED = "approved" + DISAPRROVE = "disapproved" + NONE = "none" + + +class InteractionBase(BaseModel): + type_interactions: Interacction = "none" + +class InteractionCreate(InteractionBase): + feed_id: int + user_id: int + +class InteractionResponse(InteractionBase): + pass + diff --git a/app/modules/invoices/schema.py b/app/modules/invoices/schema.py index efc50a4..04a9071 100644 --- a/app/modules/invoices/schema.py +++ b/app/modules/invoices/schema.py @@ -3,4 +3,22 @@ from datetime import datetime from typing import Optional # import re -from enum import Enum \ No newline at end of file +from enum import Enum + + +class InvoceRecept(BaseModel): + emisor: str + receptor: str + uuid: str + total: int + tipo: str + date: Optional[datetime] + +class InvoceResponse(InvoceRecept): + verified_at: datetime + verified_by: Optional[int] + +class MessageResponse(BaseModel): + message : str + + diff --git a/app/modules/license/__pycache__/models.cpython-311.pyc b/app/modules/license/__pycache__/models.cpython-311.pyc index f28e181eb43d3aecf8adb2b894f267c43a11e200..ad8cc6ca27f20ed42c558981c98803b4adab40fb 100644 GIT binary patch delta 47 zcmew>`d5^9IWI340}$xtU(00P$Q#By*_BCXb1AbVE0@XzLHmn>_E!Y$H_zZmWdZ;` CrVVuf delta 45 zcmew>`d5^9IWI340}yzXoy}y~$Q#DY$hqK1YmqIWI340}!0fzn00lkyn?I(Q2|aW9;NjjOvruGMY@j$}GglJvoF)d$K$e zn>cR@a|-hsj%CaY46A_{0;2dPpJSGsT+hTd`7*PJtpF24DoZMF3KLKzCz?t@kQ@*T zr7*4GTE+-81&AR4C@P#KGMR^2Q&E(lsxW3vX)%y0ut{von1Ch$F$6@3gWSU?0VX9u zWW5wnt#k@+3LmOUuqc0u02Wcf6d^34!YLwHL`74?P({;Nqhx?)%ch8@Fs_kU#^izG zJUOtGBt!~DMjk99g+)dIEF(QRfkkBVA(kjcMy1KJY~EZ&azHN^DFBJh6WIh98N(+p zVt1YVn_XtIHiyjSXpVb~j1H5nxTZ2KczG$)vm~6@++=cj_Qn# Uj2{@VlM`4zf@QwokOvzJ0Ir~JZ2$lO delta 709 zcmbOuc2t~qIWI340}!kTI-5CbBd;zaW5;A`##p9Q*2!xa-G!Oguq|U^U|0>r5D>*Z z`2eG~G!GL)DoZMB3Z^{o`54zmer6Vzr1Pt=~G4V2^7yU49~g2KczG$)vm~U cvLn|lM=eH2#t#hG$q6hU!7^WP$b*dq0JMCYSpWb4 diff --git a/app/modules/location/__pycache__/route.cpython-311.pyc b/app/modules/location/__pycache__/route.cpython-311.pyc new file mode 100644 index 0000000000000000000000000000000000000000..4c0f9ff557f86616a4a6b4fdc4727103162a7541 GIT binary patch literal 6119 zcmc&&-ESMm5#Qt8@mmxrSzn|ipTEt-mi(1Cj+C^FC4V4}ocaqj(^Nh2R`S_*B(rz4 zEm;Z#w?$Q;4+@&1?o;#R+OW_jKnwVx57vKh1c-t-Ab^0PK>WtkMG^R^Ge;gNTC}6o z1$w$$&hF0c%$Y_YYP&1et!FJ>Q6cd`8!tJ$LWE}lVzTe-x7r=oJMpm&FP-B zN9WVLE~EurOpCfV?d7oFqxp1y+OG%F0jJJuK|PcXIkcdK^|o}I9!W=>x~R45(R9?I zy;@A~NOw52PwUjTq_;SmlR;eAOpC2z`OOPB z%;llcyBxH^x2~U}r;1j?uMCo4X*{}*h=~eoaxRO}uzbn9M;Hy5o4Io&FkO2L5EkBJ?BYs?_(5|^xA>c`=`(43MOT?Z;a+?Rx#|hQx`70KYlYq^QM~1 z+Tsril+D`SQ&d)f&1;ylSum0wyC3;d1@lUdsdF;&9%odcSyPoY!wzEaJ5*+rB{|!7 zo*D*lz%c(=XI@#eg)^#QLZ^3znv=>DP*J2Z1;${O$%5ew6)(cC0iA&}xr`&mND6k? zt-K=})Q-5di+M#hsU3Ce=ctj-Wr3qz2LNcP-m&rI!*>yET=YqqUE5Z)cNzmDw zXLMS=bClv1z4zP0GW5molIuJlk#k0aUpW)lwyyt42M-i@bta*&6csGs-5K{y(wdZPG zk9lsMtoWKGEb#OEd9s6;ewUw+orLXJ5Sn!Jo1sSkywHqd8#Pb@3&O|34ekcH$zLWn zxMXl{A9xLHrX)-C9hde?=jcZT6*gCr!NJg{s-}PZ2`qYU5M4sb=1gfiSI8>Bu4b>x znyN@56=vN_on3 z)p1dnL#o=hp-|Gp24F_k4~4o6<0q0{hFfWeO*NkbS1rg)&9QE5idIKY)|X=kFUeYg zjx&~HHgA|LDLOM%=N!Z_URY{DGi{CEKU!HQfgMlO~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c_1Cnu z!aJ-ZW2otPi5q|6-b8S3peT2ARe1Py_68fPd*gOHJSgo1?9F(^gYDZ%GPPA~#XuCMy2tTO!bd(x7mp!S7nIw<2Prmjt2}A5t*9w^C<7?vJyhpoRBzi%WC)36Yo2Y<0dIE9zS{JeO`^9nRo2`)N0iUw6~^z z_`hj{{Dp(E84GgtE0E`e6HWsXQiq0`qlLPohsv7xn;)&#A!F=v~zN2K5W z8z0eU(*DRx#PNuWKw1w&&kr7@u{1vMMZl%~%nN+(rK7k{r3FN!ekhQiMyWpfT&{HlIe;Wpt5DmP|Spwxm0UQW-V14 z8Lz{l8nSsb8hB_8S0!tM(Ri4~6KNzVn3rter!W{q?$?ntlQb40l`TJUxrn?t4aG2( zby&=qh+Xkj#eIm|kme0i|Cu=H*QDjTLoXDrE9MkZq_JYMC_L9LDBJ|#kCUFBY71%%$4v@Wc z<*jaZlpRfv@(R3A=1OjH1`M$pEzZMwRGkf8gX&wdTUP%w zkwmcFLe>YdfXZ{%gKCZ=Ji-Ns^DatW=A2Ec9OPxr*#t@+--4yYw-L4xY6$2$wh-@Kq15^e%XB7l{eb$c_0{et!KZtsWQ@7;SdhW&!wdu3qj`__!@K)+x+nDAfY zBC#-oK33{SA%N|w4N%pOQ`kjKw#!|7toG}qudlCtZJqaFmKXu!Ne7@>XU?qb%nA2Vb*NEg95@X+zFPhvYC;* z{aSXM9Z%uTjtj$>+wVv#ns9HJ`hyq^#|#1g24WKd&w(`4N#qZosG}gY7``+DJ|i){ ztHqnUi%jj4aR{NjC&eWBY zTeHt`~!i~$!Y)q literal 0 HcmV?d00001 diff --git a/app/modules/location/__pycache__/service.cpython-311.pyc b/app/modules/location/__pycache__/service.cpython-311.pyc new file mode 100644 index 0000000000000000000000000000000000000000..17aa2db0d31678b1a4057e85a61ed0667404eee9 GIT binary patch literal 4608 zcmd57&-6`uVgm*ncl6fG;V)R2}Ffe|bvuv@!995HwNk<@TqTxzbh&~ z1zI4(**9-yzIpTW=Dj!kxT7PCAR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g2&4GAgW^C+U&KZQ+D`AF44g#T)2~WCVR_$cu zC?h8si7~>Aj0X?Gp4OZ&8*}~+*-$(h=f&sm^P))_g8);B^FdMNM*O&}i+S&}iN0Sp&A5>ic?cgu|rjRaJ7` zaTWR1_FR3VD)~(^4Rf)-iB2!jiX;d^8NKd(Q!b-H&!5Zapy$uqD0Gwm%4omm&)evb o=g;3pU>PMme=eifJbx~u32(1lk&g*X&wJA^c>BM%ESsm delta 38 scmca9bxVqOIWI340}yZ*oXynR$lJ%r!kt=CGI<{3GDf-0u1q4_0M5n=TmS$7 diff --git a/app/modules/suppliers/__pycache__/route.cpython-311.pyc b/app/modules/suppliers/__pycache__/route.cpython-311.pyc new file mode 100644 index 0000000000000000000000000000000000000000..f5886f4df6565023fa505144e5beaf936d9a0540 GIT binary patch literal 6125 zcmc&&-ESMm5#Rgbw_jGfjmPZzZ37M>2ay z+oGjFa0*lf`kY@+LlWQYFn*c4~hdx;U!4V(|;(!1GiURQ)Qx`?xr_LO|M2mKm zxN=)$ltM2f7~9ZJX{qB`3+Ht%IU=5Qk=o3 zctc1DhL{o!DJ2=6l!wE9UiTWll+W;|{BB*)14b|vbZJo!86Bw(Bb*AmbxH3uBB_W= zd-SN$mFjY7uikC!NbPWGpWb8irg~l4ulE`KseWT1HDJV2F(aOeyX^se&=^V$afBz7 zQ-f+~o?Gj<%@guDeAOp441NCFQ2D&xL{iVu;m_nobrYe6=>YXy-dS&2>%0x?{~W&R z19R~-a+`xT_%^k5wYJUiYJ~QyQ5sac=#Dv$+Wj->F&%b+4kPtBHvg(SC}=UzXj1zAdW|)qZtAjj8dq!P_FN2EOVuC)TxAhv;r~nC_nQsn2cEe$NxN zm+8QNt1;}_PLSE$wOw1}?ghE~>bh?JRY#s#ZiL1fvVH3AEwcB6?8Ii7bz0p+uG}9PcE}(Tr+39jDHndvEG`n&vDm zn{lKc(ymzO2(y~N86&Gw-3eCrXC@6bM+C`=!>hASX!EMl4LkrVc;WjP zzK8#W;%&kKS}y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o=m^;=zy8i)g*agb~ literal 0 HcmV?d00001 diff --git a/app/modules/suppliers/__pycache__/schema.cpython-311.pyc b/app/modules/suppliers/__pycache__/schema.cpython-311.pyc new file mode 100644 index 0000000000000000000000000000000000000000..92cca68d2a0afbc35f787947811202d4d92ae83f GIT binary patch literal 2636 zcma)8-D}%c6u+{rWLdUjCvn?!ZAw?Vf?>3K*vp`7q-~m|G&Zy;48ahJben4E!;_S< z>|rQl>^TpE?l0IFd)c32!#2cy8tiFr4#`s=#?HC2ty)fD($UXH=XWffdp@rHbF--v zIR5zdPxm*OkiYR}dMFd+^j}b35r;UEM|{bU{EAWWWkdFZ^t-blI!= znxXkMqvq>|E^O4R8+GtgyoTR2ni8pyE#j!(5vR(UKf$|yg)2XdCBbRH)tFS`T7uJo ztFu;#YYVOcTyue27TgkWE!Hl5Z$)rz;FcHOx9ZTRq`UGDhSpVh?Vc60ozP((*EW62 z^`0gXS01{|b9n8g<++ZPgb~;8hrx4q|AA{KU5RU8WQpsuuFSRmAaTRM@;F77%NxOA z4}9omaNygM42TbDa&!6)D6a@3hU5^V;z)+hTC6N_;!J?3>`(C(bdA+X6HPZ|%pP44tP16sZ0}u6vX?}TNc@swKZQS4P_ck7L zee<*3CmX#-n@{>&-Fn==xAFKFa*DCNzIn$Q48)Z`CB73+0s+l_!F=oX;4oSOR{?cU z;&p&@c4n>1>8IK9dip49UPvF}8C{^F# zOjBl>Dl`@Rs;D`dQDqw3)x@0+HLvsLG_NsMoy*a4n=7y?*W-HpB8(D|N8X66ufxEM zL)(S2HlMq(ZFwe?bB{&5W;4$lya)rvo73!=3Djwq*WB2&?8JS^dfi&Ig3De-=m2mz zhQ?}{rWFKXVqwd~rWsM>MM7_)6Wt3#FIq#R$QpJ^bae`CP~rhVk?)jbdNbWlw~w~7 zMrTM-MzoVHzoD;Q98#1Ky_j__4JpcqUdmc4X)o;^^|H?OAw?O{>)E9%>Gm-l(kmb% zfuQ8UU>xU{5MzH!39)dZgpLd)pnPdsg8LD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D3 zIm*aMMq-RGCv%er>0}%u?6Lj^-SXv+=Bh1uEfRU<4*~>XSbCIx&OL>B+h~fV+VIh;Y zTUQO$NMFL{@@STr?&;Iuq6#X>>4e2d+7Ew+Mr(hCMm?uzBiOL27wi{6EGAd2D$~`T zt0ceTp36U}%05M=;ce`nqSXzwB5)j6Mz1^HRLf|<@z*js;P~q{3f*vjWwhV%*KKsr p@z-x7u#5&Be=VaQIR08jZ##R{O5hmBG`%e8wmga literal 0 HcmV?d00001 diff --git a/app/modules/suppliers/models.py b/app/modules/suppliers/models.py index c422c2c..ea744ef 100644 --- a/app/modules/suppliers/models.py +++ b/app/modules/suppliers/models.py @@ -7,7 +7,7 @@ import enum class SupplierType(str, enum.Enum): NACIONAL = "nacional" - EXTRANJERO = "exttranjero" + EXTRANJERO = "extranjero" GLOBAL = "global" diff --git a/app/modules/suppliers/route.py b/app/modules/suppliers/route.py index e69de29..7e99c5f 100644 --- a/app/modules/suppliers/route.py +++ b/app/modules/suppliers/route.py @@ -0,0 +1,116 @@ +from fastapi import APIRouter, Depends, HTTPException, Query, Header, status +from fastapi.security import HTTPAuthorizationCredentials, HTTPBearer +from sqlalchemy.orm import Session +from typing import Optional, List +# +from database import get_db +from app.core.auth import get_current_user +from app.modules.users.models import Users # Modelo base de usuario +from app.modules.suppliers.models import Suppliers +from app.modules.suppliers.schema import SupplierCreate, SupplierResponse, SupplierUpdate, messageResponse +from app.modules.suppliers.service import SuppliersService + +router = APIRouter(prefix="/suppliers", tags=["suppliers"]) +security = HTTPBearer() + +#================ Create ==================== +@router.post("/create", response_model=SupplierResponse, status_code=status.HTTP_201_CREATED) +async def create_suppliers( + data: SupplierCreate, + db: Session = Depends(get_db), + current_user: Users = Depends(get_current_user) +): + """Create a suppliers - Requires authentication""" + + if not current_user: + raise HTTPException(status_code=401, detail="User not found - invalid token") + + if current_user.tipo_usuario not in ["root", "admin"]: + raise HTTPException(status_code=403, detail="You don't have permission to create suppliers") + + try: + result = SuppliersService.create_suppliers(db=db, data=data) + return result + except ValueError as e: + raise HTTPException(status_code=400, detail=str(e)) + +#================ Get ==================== +@router.get("/", response_model=List[SupplierResponse]) +def get_supplierss( + db: Session = Depends(get_db), + current_user: Users = Depends(get_current_user), + skip: int = Query(0, ge=0, description="Number of records to skip"), + limit: int = Query(100, ge=1, le=1000, description="Max number of records to return") +): + """Get list with pagination - requires authentication""" + + if not current_user: + raise HTTPException(status_code=401, detail="Authentication required") + + return SuppliersService.get_suppliers(db=db, skip=skip, limit=limit) + +#================ Get by ID ==================== +@router.get("/{{{entity_name}}_id}", response_model=SupplierResponse) +def get_suppliers_by_id( + suppliers_id: int, + db: Session = Depends(get_db), + current_user: Users = Depends(get_current_user) +): + """Get suppliers by ID - requires authentication""" + + if not current_user: + raise HTTPException(status_code=401, detail="Authentication required") + + try: + result = SuppliersService.get_suppliers(db=db, suppliers_id=suppliers_id, current_user=current_user) + return result + except ValueError as e: + raise HTTPException(status_code=404, detail=str(e)) + +#================ Update ==================== +@router.patch("/update/{{{entity_name}}_id}", response_model=SupplierResponse) +async def update_suppliers( + suppliers_id: int, + data: SupplierUpdate, + db: Session = Depends(get_db), + current_user: Users = Depends(get_current_user) +): + """Update existing suppliers - requires authentication""" + + if not current_user: + raise HTTPException(status_code=401, detail="Authentication required") + + if current_user.tipo_usuario not in ["root", "admin"]: + raise HTTPException(status_code=403, detail="You don't have permission to update suppliers") + + try: + result = SuppliersService.update_suppliers( + db=db, + suppliers_id=suppliers_id, + data=data, + current_user=current_user + ) + return result + except ValueError as e: + raise HTTPException(status_code=404, detail=str(e)) + +#================ Delete ==================== +@router.delete("/delete/{{{entity_name}}_id}", response_model=messageResponse, status_code=status.HTTP_200_OK) +async def delete_suppliers( + suppliers_id: int, + db: Session = Depends(get_db), + current_user: Users = Depends(get_current_user) +): + """Delete suppliers by ID - requires authentication""" + + if not current_user: + raise HTTPException(status_code=401, detail="Authentication required") + + if current_user.tipo_usuario not in ["root", "admin"]: + raise HTTPException(status_code=403, detail="You don't have permission to delete suppliers") + + try: + result = SuppliersService.delete_suppliers(db=db, suppliers_id=suppliers_id, current_user=current_user) + return {"message": "suppliers deleted successfully"} + except ValueError as e: + raise HTTPException(status_code=404, detail=str(e)) \ No newline at end of file diff --git a/app/modules/suppliers/schema.py b/app/modules/suppliers/schema.py index e69de29..c583884 100644 --- a/app/modules/suppliers/schema.py +++ b/app/modules/suppliers/schema.py @@ -0,0 +1,42 @@ +from pydantic import BaseModel, EmailStr, Field, validator, ConfigDict +from datetime import datetime +from typing import Optional, Dict, Any +# +import re +from enum import Enum +# + + + +class SupplierType(Enum): + NACIONAL = "nacional" + EXTRANJERO = "extranjero" + GLOBAL = "global" + +class SuppliersBase(BaseModel): + rfc: str + email : EmailStr + short_name : str + razon_social : str + fiscal_number : str + cellphone: str + supplier_type : SupplierType + is_active : bool = True + +class SupplierCreate(SuppliersBase): + location_id: int + client_id: int + +class SupplierUpdate(SuppliersBase): + pass + +class SupplierResponse(SupplierCreate): + id: int + created_at: datetime + updated_at: Optional[datetime] + deleted_at: Optional[datetime] + created_by: int + updated_by: Optional[int] + deleted_by: Optional[int] +class messageResponse(BaseModel): + message : str \ No newline at end of file diff --git a/app/modules/suppliers/service.py b/app/modules/suppliers/service.py index efc50a4..67fa639 100644 --- a/app/modules/suppliers/service.py +++ b/app/modules/suppliers/service.py @@ -3,4 +3,68 @@ from datetime import datetime from typing import Optional # import re -from enum import Enum \ No newline at end of file +from enum import Enum + +from sqlalchemy.orm import Session +from datetime import datetime +from typing import Optional +from fastapi import HTTPException +from app.modules.suppliers.models import Suppliers +from app.modules.suppliers.schema import SupplierCreate, SupplierUpdate + + +class SuppliersService: + @staticmethod + def create_suppliers(db: Session, data:SupplierCreate ): + new_suppliers = Suppliers(**data.dict()) + db.add(new_suppliers) + db.commit() + db.refresh(new_suppliers) + return new_suppliers + + @staticmethod + def get_suppliers(db: Session, suppliers_id: int, current_user): + suppliers = db.query(Suppliers).filter(Suppliers.id == suppliers_id).first() + if not suppliers: + raise ValueError("suppliers no encontrado") + return suppliers + + @staticmethod + def update_suppliers(db: Session, suppliers_id: int, data:SupplierUpdate , current_user): + suppliers = db.query(Suppliers).filter(Suppliers.id == suppliers_id).first() + if not suppliers: + raise ValueError("suppliers no encontrado") + + if current_user.role not in ["ROOT", "ADMIN"]: + raise ValueError("No tienes permisos para actualizar este suppliers") + + update_data = data.dict(exclude_unset=True) + for key, value in update_data.items(): + setattr(suppliers, key, value) + + db.commit() + db.refresh(suppliers) + return suppliers + + @staticmethod + def delete_suppliers(db: Session, suppliers_id: int, current_user): + suppliers = db.query(Suppliers).filter(Suppliers.id == suppliers_id).first() + if not suppliers: + raise ValueError("suppliers no encontrado") + + if current_user.role not in ["ROOT", "ADMIN"]: + raise ValueError("No tienes permisos para eliminar este suppliers") + + try: + suppliers.is_active = False + suppliers.deleted_at = datetime.utcnow() + suppliers.deleted_by = current_user.id + db.commit() + db.refresh(suppliers) + except Exception as e: + db.rollback() + raise ValueError(f"Error al eliminar el suppliers: {e}") + + return {"message": "suppliers eliminado correctamente"} + + \ No newline at end of file diff --git a/main.py b/main.py index d39f554..10f3f46 100644 --- a/main.py +++ b/main.py @@ -9,6 +9,17 @@ from database import test_connection from app.modules.users.route import router as user_router from app.modules.clients.route import router as client_router from app.modules.branches.route import router as branches_router +# +from app.modules.coments.route import router as comments_router +from app.modules.configuration.route import router as configuration_router +# +from app.modules.suppliers.route import router as suppliers_router +from app.modules.location.route import router as location_router +from app.modules.edos.route import router as Edos_router + + + + logging.basicConfig(level=logging.INFO, @@ -60,4 +71,9 @@ async def root(): app.include_router(user_router) app.include_router(client_router) -app.include_router(branches_router) \ No newline at end of file +app.include_router(branches_router) +app.include_router(comments_router) +app.include_router(configuration_router) +app.include_router(suppliers_router) +app.include_router(location_router) +app.include_router(Edos_router) diff --git a/output/generated/routers/branches_router.py b/output/generated/routers/branches_router.py deleted file mode 100644 index 03b041f..0000000 --- a/output/generated/routers/branches_router.py +++ /dev/null @@ -1,116 +0,0 @@ -from fastapi import APIRouter, Depends, HTTPException, Query, Header, status -from fastapi.security import HTTPAuthorizationCredentials, HTTPBearer -from sqlalchemy.orm import Session -from typing import Optional, List -# -from database import get_db -from app.core.auth import get_current_user -from app.models.user import User # Modelo base de usuario -from app.modules.branches.models import Branches -from app.modules.branches.schema import , Response -from app.modules.branches.services import BranchesService - -router = APIRouter(prefix="/branches", tags=["branches"]) -security = HTTPBearer() - -#================ Create ==================== -@router.post("/create", response_model=Response, status_code=status.HTTP_201_CREATED) -async def create_branches( - data: , - db: Session = Depends(get_db), - current_user: User = Depends(get_current_user) -): - """Create a branches - Requires authentication""" - - if not current_user: - raise HTTPException(status_code=401, detail="User not found - invalid token") - - if current_user.tipo_usuario not in ["root", "admin"]: - raise HTTPException(status_code=403, detail="You don't have permission to create branches") - - try: - result = BranchesService.create_branches(db=db, data=data) - return result - except ValueError as e: - raise HTTPException(status_code=400, detail=str(e)) - -#================ Get ==================== -@router.get("/", response_model=List[Response]) -def get_branchess( - db: Session = Depends(get_db), - current_user: User = Depends(get_current_user), - skip: int = Query(0, ge=0, description="Number of records to skip"), - limit: int = Query(100, ge=1, le=1000, description="Max number of records to return") -): - """Get list with pagination - requires authentication""" - - if not current_user: - raise HTTPException(status_code=401, detail="Authentication required") - - return BranchesService.get_branchess(db=db, skip=skip, limit=limit) - -#================ Get by ID ==================== -@router.get("/{{{entity_name}}_id}", response_model=Response) -def get_branches_by_id( - branches_id: int, - db: Session = Depends(get_db), - current_user: User = Depends(get_current_user) -): - """Get branches by ID - requires authentication""" - - if not current_user: - raise HTTPException(status_code=401, detail="Authentication required") - - try: - result = BranchesService.get_branches(db=db, branches_id=branches_id, current_user=current_user) - return result - except ValueError as e: - raise HTTPException(status_code=404, detail=str(e)) - -#================ Update ==================== -@router.patch("/update/{{{entity_name}}_id}", response_model=Response) -async def update_branches( - branches_id: int, - data: , - db: Session = Depends(get_db), - current_user: User = Depends(get_current_user) -): - """Update existing branches - requires authentication""" - - if not current_user: - raise HTTPException(status_code=401, detail="Authentication required") - - if current_user.tipo_usuario not in ["root", "admin"]: - raise HTTPException(status_code=403, detail="You don't have permission to update branches") - - try: - result = BranchesService.update_branches( - db=db, - branches_id=branches_id, - data=data, - current_user=current_user - ) - return result - except ValueError as e: - raise HTTPException(status_code=404, detail=str(e)) - -#================ Delete ==================== -@router.delete("/delete/{{{entity_name}}_id}", status_code=status.HTTP_200_OK) -async def delete_branches( - branches_id: int, - db: Session = Depends(get_db), - current_user: User = Depends(get_current_user) -): - """Delete branches by ID - requires authentication""" - - if not current_user: - raise HTTPException(status_code=401, detail="Authentication required") - - if current_user.tipo_usuario not in ["root", "admin"]: - raise HTTPException(status_code=403, detail="You don't have permission to delete branches") - - try: - result = BranchesService.delete_branches(db=db, branches_id=branches_id, current_user=current_user) - return {"message": "branches deleted successfully"} - except ValueError as e: - raise HTTPException(status_code=404, detail=str(e)) \ No newline at end of file diff --git a/output/generated/routers/client_router.py b/output/generated/routers/client_router.py deleted file mode 100644 index d8969e1..0000000 --- a/output/generated/routers/client_router.py +++ /dev/null @@ -1,117 +0,0 @@ -from fastapi import APIRouter, Depends, HTTPException, Query, Header, status -from fastapi.security import HTTPAuthorizationCredentials, HTTPBearer -from sqlalchemy.orm import Session -from typing import Optional, List -# -from database import get_db -from app.core.auth import get_current_user -from app.models.user import User # Modelo base de usuario -from app.modules.client.models import Client -from app.modules.client.schema import , Response -from app.modules.client.services import ClientService - -router = APIRouter(prefix="/client", tags=["client"]) -security = HTTPBearer() - -#================ Create ==================== -@router.post("/create", response_model=Response, status_code=status.HTTP_201_CREATED) -async def create_client( - data: , - db: Session = Depends(get_db), - current_user: User = Depends(get_current_user) -): - """Create a client - Requires authentication""" - - if not current_user: - raise HTTPException(status_code=401, detail="User not found - invalid token") - - if current_user.tipo_usuario not in ["root", "admin"]: - raise HTTPException(status_code=403, detail="You don't have permission to create client") - - try: - result = ClientService.create_client(db=db, data=data) - - return result - except ValueError as e: - raise HTTPException(status_code=400, detail=str(e)) - -#================ Get ==================== -@router.get("/", response_model=List[Response]) -def get_clients( - db: Session = Depends(get_db), - current_user: User = Depends(get_current_user), - skip: int = Query(0, ge=0, description="Number of records to skip"), - limit: int = Query(100, ge=1, le=1000, description="Max number of records to return") -): - """Get list with pagination - requires authentication""" - - if not current_user: - raise HTTPException(status_code=401, detail="Authentication required") - - return ClientService.get_clients(db=db, skip=skip, limit=limit) - -#================ Get by ID ==================== -@router.get("/client_id}", response_model=Response) -def get_client_by_id( - client_id: int, - db: Session = Depends(get_db), - current_user: User = Depends(get_current_user) -): - """Get client by ID - requires authentication""" - - if not current_user: - raise HTTPException(status_code=401, detail="Authentication required") - - try: - result = ClientService.get_client(db=db, client_id=client_id, current_user=current_user) - return result - except ValueError as e: - raise HTTPException(status_code=404, detail=str(e)) - -#================ Update ==================== -@router.patch("/update/client_id}", response_model=Response) -async def update_client( - client_id: int, - data: , - db: Session = Depends(get_db), - current_user: User = Depends(get_current_user) -): - """Update existing client - requires authentication""" - - if not current_user: - raise HTTPException(status_code=401, detail="Authentication required") - - if current_user.tipo_usuario not in ["root", "admin"]: - raise HTTPException(status_code=403, detail="You don't have permission to update client") - - try: - result = ClientService.update_client( - db=db, - client_id=client_id, - data=data, - current_user=current_user - ) - return result - except ValueError as e: - raise HTTPException(status_code=404, detail=str(e)) - -#================ Delete ==================== -@router.delete("/delete/client_id}", status_code=status.HTTP_200_OK) -async def delete_client( - client_id: int, - db: Session = Depends(get_db), - current_user: User = Depends(get_current_user) -): - """Delete client by ID - requires authentication""" - - if not current_user: - raise HTTPException(status_code=401, detail="Authentication required") - - if current_user.tipo_usuario not in ["root", "admin"]: - raise HTTPException(status_code=403, detail="You don't have permission to delete client") - - try: - result = ClientService.delete_client(db=db, client_id=client_id, current_user=current_user) - return {"message": "client deleted successfully"} - except ValueError as e: - raise HTTPException(status_code=404, detail=str(e)) \ No newline at end of file diff --git a/output/generated/routers/coments_router.py b/output/generated/routers/coments_router.py deleted file mode 100644 index 5a1756f..0000000 --- a/output/generated/routers/coments_router.py +++ /dev/null @@ -1,116 +0,0 @@ -from fastapi import APIRouter, Depends, HTTPException, Query, Header, status -from fastapi.security import HTTPAuthorizationCredentials, HTTPBearer -from sqlalchemy.orm import Session -from typing import Optional, List -# -from database import get_db -from app.core.auth import get_current_user -from app.models.user import User # Modelo base de usuario -from app.modules.coments.models import Coments -from app.modules.coments.schema import , Response -from app.modules.coments.services import ComentsService - -router = APIRouter(prefix="/coments", tags=["coments"]) -security = HTTPBearer() - -#================ Create ==================== -@router.post("/create", response_model=Response, status_code=status.HTTP_201_CREATED) -async def create_coments( - data: , - db: Session = Depends(get_db), - current_user: User = Depends(get_current_user) -): - """Create a coments - Requires authentication""" - - if not current_user: - raise HTTPException(status_code=401, detail="User not found - invalid token") - - if current_user.tipo_usuario not in ["root", "admin"]: - raise HTTPException(status_code=403, detail="You don't have permission to create coments") - - try: - result = ComentsService.create_coments(db=db, data=data) - return result - except ValueError as e: - raise HTTPException(status_code=400, detail=str(e)) - -#================ Get ==================== -@router.get("/", response_model=List[Response]) -def get_comentss( - db: Session = Depends(get_db), - current_user: User = Depends(get_current_user), - skip: int = Query(0, ge=0, description="Number of records to skip"), - limit: int = Query(100, ge=1, le=1000, description="Max number of records to return") -): - """Get list with pagination - requires authentication""" - - if not current_user: - raise HTTPException(status_code=401, detail="Authentication required") - - return ComentsService.get_comentss(db=db, skip=skip, limit=limit) - -#================ Get by ID ==================== -@router.get("/{{{entity_name}}_id}", response_model=Response) -def get_coments_by_id( - coments_id: int, - db: Session = Depends(get_db), - current_user: User = Depends(get_current_user) -): - """Get coments by ID - requires authentication""" - - if not current_user: - raise HTTPException(status_code=401, detail="Authentication required") - - try: - result = ComentsService.get_coments(db=db, coments_id=coments_id, current_user=current_user) - return result - except ValueError as e: - raise HTTPException(status_code=404, detail=str(e)) - -#================ Update ==================== -@router.patch("/update/{{{entity_name}}_id}", response_model=Response) -async def update_coments( - coments_id: int, - data: , - db: Session = Depends(get_db), - current_user: User = Depends(get_current_user) -): - """Update existing coments - requires authentication""" - - if not current_user: - raise HTTPException(status_code=401, detail="Authentication required") - - if current_user.tipo_usuario not in ["root", "admin"]: - raise HTTPException(status_code=403, detail="You don't have permission to update coments") - - try: - result = ComentsService.update_coments( - db=db, - coments_id=coments_id, - data=data, - current_user=current_user - ) - return result - except ValueError as e: - raise HTTPException(status_code=404, detail=str(e)) - -#================ Delete ==================== -@router.delete("/delete/{{{entity_name}}_id}", status_code=status.HTTP_200_OK) -async def delete_coments( - coments_id: int, - db: Session = Depends(get_db), - current_user: User = Depends(get_current_user) -): - """Delete coments by ID - requires authentication""" - - if not current_user: - raise HTTPException(status_code=401, detail="Authentication required") - - if current_user.tipo_usuario not in ["root", "admin"]: - raise HTTPException(status_code=403, detail="You don't have permission to delete coments") - - try: - result = ComentsService.delete_coments(db=db, coments_id=coments_id, current_user=current_user) - return {"message": "coments deleted successfully"} - except ValueError as e: - raise HTTPException(status_code=404, detail=str(e)) \ No newline at end of file diff --git a/output/generated/routers/configuration_router.py b/output/generated/routers/configuration_router.py deleted file mode 100644 index b3f9980..0000000 --- a/output/generated/routers/configuration_router.py +++ /dev/null @@ -1,116 +0,0 @@ -from fastapi import APIRouter, Depends, HTTPException, Query, Header, status -from fastapi.security import HTTPAuthorizationCredentials, HTTPBearer -from sqlalchemy.orm import Session -from typing import Optional, List -# -from database import get_db -from app.core.auth import get_current_user -from app.models.user import User # Modelo base de usuario -from app.modules.configuration.models import Configuration -from app.modules.configuration.schema import , Response -from app.modules.configuration.services import ConfigurationService - -router = APIRouter(prefix="/configuration", tags=["configuration"]) -security = HTTPBearer() - -#================ Create ==================== -@router.post("/create", response_model=Response, status_code=status.HTTP_201_CREATED) -async def create_configuration( - data: , - db: Session = Depends(get_db), - current_user: User = Depends(get_current_user) -): - """Create a configuration - Requires authentication""" - - if not current_user: - raise HTTPException(status_code=401, detail="User not found - invalid token") - - if current_user.tipo_usuario not in ["root", "admin"]: - raise HTTPException(status_code=403, detail="You don't have permission to create configuration") - - try: - result = ConfigurationService.create_configuration(db=db, data=data) - return result - except ValueError as e: - raise HTTPException(status_code=400, detail=str(e)) - -#================ Get ==================== -@router.get("/", response_model=List[Response]) -def get_configurations( - db: Session = Depends(get_db), - current_user: User = Depends(get_current_user), - skip: int = Query(0, ge=0, description="Number of records to skip"), - limit: int = Query(100, ge=1, le=1000, description="Max number of records to return") -): - """Get list with pagination - requires authentication""" - - if not current_user: - raise HTTPException(status_code=401, detail="Authentication required") - - return ConfigurationService.get_configurations(db=db, skip=skip, limit=limit) - -#================ Get by ID ==================== -@router.get("/{{{entity_name}}_id}", response_model=Response) -def get_configuration_by_id( - configuration_id: int, - db: Session = Depends(get_db), - current_user: User = Depends(get_current_user) -): - """Get configuration by ID - requires authentication""" - - if not current_user: - raise HTTPException(status_code=401, detail="Authentication required") - - try: - result = ConfigurationService.get_configuration(db=db, configuration_id=configuration_id, current_user=current_user) - return result - except ValueError as e: - raise HTTPException(status_code=404, detail=str(e)) - -#================ Update ==================== -@router.patch("/update/{{{entity_name}}_id}", response_model=Response) -async def update_configuration( - configuration_id: int, - data: , - db: Session = Depends(get_db), - current_user: User = Depends(get_current_user) -): - """Update existing configuration - requires authentication""" - - if not current_user: - raise HTTPException(status_code=401, detail="Authentication required") - - if current_user.tipo_usuario not in ["root", "admin"]: - raise HTTPException(status_code=403, detail="You don't have permission to update configuration") - - try: - result = ConfigurationService.update_configuration( - db=db, - configuration_id=configuration_id, - data=data, - current_user=current_user - ) - return result - except ValueError as e: - raise HTTPException(status_code=404, detail=str(e)) - -#================ Delete ==================== -@router.delete("/delete/{{{entity_name}}_id}", status_code=status.HTTP_200_OK) -async def delete_configuration( - configuration_id: int, - db: Session = Depends(get_db), - current_user: User = Depends(get_current_user) -): - """Delete configuration by ID - requires authentication""" - - if not current_user: - raise HTTPException(status_code=401, detail="Authentication required") - - if current_user.tipo_usuario not in ["root", "admin"]: - raise HTTPException(status_code=403, detail="You don't have permission to delete configuration") - - try: - result = ConfigurationService.delete_configuration(db=db, configuration_id=configuration_id, current_user=current_user) - return {"message": "configuration deleted successfully"} - except ValueError as e: - raise HTTPException(status_code=404, detail=str(e)) \ No newline at end of file diff --git a/output/generated/routers/credits_router.py b/output/generated/routers/credits_router.py deleted file mode 100644 index b448a00..0000000 --- a/output/generated/routers/credits_router.py +++ /dev/null @@ -1,116 +0,0 @@ -from fastapi import APIRouter, Depends, HTTPException, Query, Header, status -from fastapi.security import HTTPAuthorizationCredentials, HTTPBearer -from sqlalchemy.orm import Session -from typing import Optional, List -# -from database import get_db -from app.core.auth import get_current_user -from app.models.user import User # Modelo base de usuario -from app.modules.credits.models import Credits -from app.modules.credits.schema import , Response -from app.modules.credits.services import CreditsService - -router = APIRouter(prefix="/credits", tags=["credits"]) -security = HTTPBearer() - -#================ Create ==================== -@router.post("/create", response_model=Response, status_code=status.HTTP_201_CREATED) -async def create_credits( - data: , - db: Session = Depends(get_db), - current_user: User = Depends(get_current_user) -): - """Create a credits - Requires authentication""" - - if not current_user: - raise HTTPException(status_code=401, detail="User not found - invalid token") - - if current_user.tipo_usuario not in ["root", "admin"]: - raise HTTPException(status_code=403, detail="You don't have permission to create credits") - - try: - result = CreditsService.create_credits(db=db, data=data) - return result - except ValueError as e: - raise HTTPException(status_code=400, detail=str(e)) - -#================ Get ==================== -@router.get("/", response_model=List[Response]) -def get_creditss( - db: Session = Depends(get_db), - current_user: User = Depends(get_current_user), - skip: int = Query(0, ge=0, description="Number of records to skip"), - limit: int = Query(100, ge=1, le=1000, description="Max number of records to return") -): - """Get list with pagination - requires authentication""" - - if not current_user: - raise HTTPException(status_code=401, detail="Authentication required") - - return CreditsService.get_creditss(db=db, skip=skip, limit=limit) - -#================ Get by ID ==================== -@router.get("/{{{entity_name}}_id}", response_model=Response) -def get_credits_by_id( - credits_id: int, - db: Session = Depends(get_db), - current_user: User = Depends(get_current_user) -): - """Get credits by ID - requires authentication""" - - if not current_user: - raise HTTPException(status_code=401, detail="Authentication required") - - try: - result = CreditsService.get_credits(db=db, credits_id=credits_id, current_user=current_user) - return result - except ValueError as e: - raise HTTPException(status_code=404, detail=str(e)) - -#================ Update ==================== -@router.patch("/update/{{{entity_name}}_id}", response_model=Response) -async def update_credits( - credits_id: int, - data: , - db: Session = Depends(get_db), - current_user: User = Depends(get_current_user) -): - """Update existing credits - requires authentication""" - - if not current_user: - raise HTTPException(status_code=401, detail="Authentication required") - - if current_user.tipo_usuario not in ["root", "admin"]: - raise HTTPException(status_code=403, detail="You don't have permission to update credits") - - try: - result = CreditsService.update_credits( - db=db, - credits_id=credits_id, - data=data, - current_user=current_user - ) - return result - except ValueError as e: - raise HTTPException(status_code=404, detail=str(e)) - -#================ Delete ==================== -@router.delete("/delete/{{{entity_name}}_id}", status_code=status.HTTP_200_OK) -async def delete_credits( - credits_id: int, - db: Session = Depends(get_db), - current_user: User = Depends(get_current_user) -): - """Delete credits by ID - requires authentication""" - - if not current_user: - raise HTTPException(status_code=401, detail="Authentication required") - - if current_user.tipo_usuario not in ["root", "admin"]: - raise HTTPException(status_code=403, detail="You don't have permission to delete credits") - - try: - result = CreditsService.delete_credits(db=db, credits_id=credits_id, current_user=current_user) - return {"message": "credits deleted successfully"} - except ValueError as e: - raise HTTPException(status_code=404, detail=str(e)) \ No newline at end of file diff --git a/output/generated/routers/edos_router.py b/output/generated/routers/edos_router.py deleted file mode 100644 index 1e140af..0000000 --- a/output/generated/routers/edos_router.py +++ /dev/null @@ -1,116 +0,0 @@ -from fastapi import APIRouter, Depends, HTTPException, Query, Header, status -from fastapi.security import HTTPAuthorizationCredentials, HTTPBearer -from sqlalchemy.orm import Session -from typing import Optional, List -# -from database import get_db -from app.core.auth import get_current_user -from app.models.user import User # Modelo base de usuario -from app.modules.edos.models import EDOS -from app.modules.edos.schema import , Response -from app.modules.edos.services import EDOSService - -router = APIRouter(prefix="/edos", tags=["edos"]) -security = HTTPBearer() - -#================ Create ==================== -@router.post("/create", response_model=Response, status_code=status.HTTP_201_CREATED) -async def create_edos( - data: , - db: Session = Depends(get_db), - current_user: User = Depends(get_current_user) -): - """Create a edos - Requires authentication""" - - if not current_user: - raise HTTPException(status_code=401, detail="User not found - invalid token") - - if current_user.tipo_usuario not in ["root", "admin"]: - raise HTTPException(status_code=403, detail="You don't have permission to create edos") - - try: - result = EDOSService.create_edos(db=db, data=data) - return result - except ValueError as e: - raise HTTPException(status_code=400, detail=str(e)) - -#================ Get ==================== -@router.get("/", response_model=List[Response]) -def get_edoss( - db: Session = Depends(get_db), - current_user: User = Depends(get_current_user), - skip: int = Query(0, ge=0, description="Number of records to skip"), - limit: int = Query(100, ge=1, le=1000, description="Max number of records to return") -): - """Get list with pagination - requires authentication""" - - if not current_user: - raise HTTPException(status_code=401, detail="Authentication required") - - return EDOSService.get_edoss(db=db, skip=skip, limit=limit) - -#================ Get by ID ==================== -@router.get("/{{{entity_name}}_id}", response_model=Response) -def get_edos_by_id( - edos_id: int, - db: Session = Depends(get_db), - current_user: User = Depends(get_current_user) -): - """Get edos by ID - requires authentication""" - - if not current_user: - raise HTTPException(status_code=401, detail="Authentication required") - - try: - result = EDOSService.get_edos(db=db, edos_id=edos_id, current_user=current_user) - return result - except ValueError as e: - raise HTTPException(status_code=404, detail=str(e)) - -#================ Update ==================== -@router.patch("/update/{{{entity_name}}_id}", response_model=Response) -async def update_edos( - edos_id: int, - data: , - db: Session = Depends(get_db), - current_user: User = Depends(get_current_user) -): - """Update existing edos - requires authentication""" - - if not current_user: - raise HTTPException(status_code=401, detail="Authentication required") - - if current_user.tipo_usuario not in ["root", "admin"]: - raise HTTPException(status_code=403, detail="You don't have permission to update edos") - - try: - result = EDOSService.update_edos( - db=db, - edos_id=edos_id, - data=data, - current_user=current_user - ) - return result - except ValueError as e: - raise HTTPException(status_code=404, detail=str(e)) - -#================ Delete ==================== -@router.delete("/delete/{{{entity_name}}_id}", status_code=status.HTTP_200_OK) -async def delete_edos( - edos_id: int, - db: Session = Depends(get_db), - current_user: User = Depends(get_current_user) -): - """Delete edos by ID - requires authentication""" - - if not current_user: - raise HTTPException(status_code=401, detail="Authentication required") - - if current_user.tipo_usuario not in ["root", "admin"]: - raise HTTPException(status_code=403, detail="You don't have permission to delete edos") - - try: - result = EDOSService.delete_edos(db=db, edos_id=edos_id, current_user=current_user) - return {"message": "edos deleted successfully"} - except ValueError as e: - raise HTTPException(status_code=404, detail=str(e)) \ No newline at end of file diff --git a/output/generated/routers/efos_router.py b/output/generated/routers/efos_router.py deleted file mode 100644 index 20543e0..0000000 --- a/output/generated/routers/efos_router.py +++ /dev/null @@ -1,116 +0,0 @@ -from fastapi import APIRouter, Depends, HTTPException, Query, Header, status -from fastapi.security import HTTPAuthorizationCredentials, HTTPBearer -from sqlalchemy.orm import Session -from typing import Optional, List -# -from database import get_db -from app.core.auth import get_current_user -from app.models.user import User # Modelo base de usuario -from app.modules.efos.models import EFOS -from app.modules.efos.schema import , Response -from app.modules.efos.services import EFOSService - -router = APIRouter(prefix="/efos", tags=["efos"]) -security = HTTPBearer() - -#================ Create ==================== -@router.post("/create", response_model=Response, status_code=status.HTTP_201_CREATED) -async def create_efos( - data: , - db: Session = Depends(get_db), - current_user: User = Depends(get_current_user) -): - """Create a efos - Requires authentication""" - - if not current_user: - raise HTTPException(status_code=401, detail="User not found - invalid token") - - if current_user.tipo_usuario not in ["root", "admin"]: - raise HTTPException(status_code=403, detail="You don't have permission to create efos") - - try: - result = EFOSService.create_efos(db=db, data=data) - return result - except ValueError as e: - raise HTTPException(status_code=400, detail=str(e)) - -#================ Get ==================== -@router.get("/", response_model=List[Response]) -def get_efoss( - db: Session = Depends(get_db), - current_user: User = Depends(get_current_user), - skip: int = Query(0, ge=0, description="Number of records to skip"), - limit: int = Query(100, ge=1, le=1000, description="Max number of records to return") -): - """Get list with pagination - requires authentication""" - - if not current_user: - raise HTTPException(status_code=401, detail="Authentication required") - - return EFOSService.get_efoss(db=db, skip=skip, limit=limit) - -#================ Get by ID ==================== -@router.get("/{{{entity_name}}_id}", response_model=Response) -def get_efos_by_id( - efos_id: int, - db: Session = Depends(get_db), - current_user: User = Depends(get_current_user) -): - """Get efos by ID - requires authentication""" - - if not current_user: - raise HTTPException(status_code=401, detail="Authentication required") - - try: - result = EFOSService.get_efos(db=db, efos_id=efos_id, current_user=current_user) - return result - except ValueError as e: - raise HTTPException(status_code=404, detail=str(e)) - -#================ Update ==================== -@router.patch("/update/{{{entity_name}}_id}", response_model=Response) -async def update_efos( - efos_id: int, - data: , - db: Session = Depends(get_db), - current_user: User = Depends(get_current_user) -): - """Update existing efos - requires authentication""" - - if not current_user: - raise HTTPException(status_code=401, detail="Authentication required") - - if current_user.tipo_usuario not in ["root", "admin"]: - raise HTTPException(status_code=403, detail="You don't have permission to update efos") - - try: - result = EFOSService.update_efos( - db=db, - efos_id=efos_id, - data=data, - current_user=current_user - ) - return result - except ValueError as e: - raise HTTPException(status_code=404, detail=str(e)) - -#================ Delete ==================== -@router.delete("/delete/{{{entity_name}}_id}", status_code=status.HTTP_200_OK) -async def delete_efos( - efos_id: int, - db: Session = Depends(get_db), - current_user: User = Depends(get_current_user) -): - """Delete efos by ID - requires authentication""" - - if not current_user: - raise HTTPException(status_code=401, detail="Authentication required") - - if current_user.tipo_usuario not in ["root", "admin"]: - raise HTTPException(status_code=403, detail="You don't have permission to delete efos") - - try: - result = EFOSService.delete_efos(db=db, efos_id=efos_id, current_user=current_user) - return {"message": "efos deleted successfully"} - except ValueError as e: - raise HTTPException(status_code=404, detail=str(e)) \ No newline at end of file diff --git a/output/generated/routers/feed_router.py b/output/generated/routers/feed_router.py deleted file mode 100644 index 9adf2fe..0000000 --- a/output/generated/routers/feed_router.py +++ /dev/null @@ -1,116 +0,0 @@ -from fastapi import APIRouter, Depends, HTTPException, Query, Header, status -from fastapi.security import HTTPAuthorizationCredentials, HTTPBearer -from sqlalchemy.orm import Session -from typing import Optional, List -# -from database import get_db -from app.core.auth import get_current_user -from app.models.user import User # Modelo base de usuario -from app.modules.feed.models import Feed -from app.modules.feed.schema import , Response -from app.modules.feed.services import FeedService - -router = APIRouter(prefix="/feed", tags=["feed"]) -security = HTTPBearer() - -#================ Create ==================== -@router.post("/create", response_model=Response, status_code=status.HTTP_201_CREATED) -async def create_feed( - data: , - db: Session = Depends(get_db), - current_user: User = Depends(get_current_user) -): - """Create a feed - Requires authentication""" - - if not current_user: - raise HTTPException(status_code=401, detail="User not found - invalid token") - - if current_user.tipo_usuario not in ["root", "admin"]: - raise HTTPException(status_code=403, detail="You don't have permission to create feed") - - try: - result = FeedService.create_feed(db=db, data=data) - return result - except ValueError as e: - raise HTTPException(status_code=400, detail=str(e)) - -#================ Get ==================== -@router.get("/", response_model=List[Response]) -def get_feeds( - db: Session = Depends(get_db), - current_user: User = Depends(get_current_user), - skip: int = Query(0, ge=0, description="Number of records to skip"), - limit: int = Query(100, ge=1, le=1000, description="Max number of records to return") -): - """Get list with pagination - requires authentication""" - - if not current_user: - raise HTTPException(status_code=401, detail="Authentication required") - - return FeedService.get_feeds(db=db, skip=skip, limit=limit) - -#================ Get by ID ==================== -@router.get("/{{{entity_name}}_id}", response_model=Response) -def get_feed_by_id( - feed_id: int, - db: Session = Depends(get_db), - current_user: User = Depends(get_current_user) -): - """Get feed by ID - requires authentication""" - - if not current_user: - raise HTTPException(status_code=401, detail="Authentication required") - - try: - result = FeedService.get_feed(db=db, feed_id=feed_id, current_user=current_user) - return result - except ValueError as e: - raise HTTPException(status_code=404, detail=str(e)) - -#================ Update ==================== -@router.patch("/update/{{{entity_name}}_id}", response_model=Response) -async def update_feed( - feed_id: int, - data: , - db: Session = Depends(get_db), - current_user: User = Depends(get_current_user) -): - """Update existing feed - requires authentication""" - - if not current_user: - raise HTTPException(status_code=401, detail="Authentication required") - - if current_user.tipo_usuario not in ["root", "admin"]: - raise HTTPException(status_code=403, detail="You don't have permission to update feed") - - try: - result = FeedService.update_feed( - db=db, - feed_id=feed_id, - data=data, - current_user=current_user - ) - return result - except ValueError as e: - raise HTTPException(status_code=404, detail=str(e)) - -#================ Delete ==================== -@router.delete("/delete/{{{entity_name}}_id}", status_code=status.HTTP_200_OK) -async def delete_feed( - feed_id: int, - db: Session = Depends(get_db), - current_user: User = Depends(get_current_user) -): - """Delete feed by ID - requires authentication""" - - if not current_user: - raise HTTPException(status_code=401, detail="Authentication required") - - if current_user.tipo_usuario not in ["root", "admin"]: - raise HTTPException(status_code=403, detail="You don't have permission to delete feed") - - try: - result = FeedService.delete_feed(db=db, feed_id=feed_id, current_user=current_user) - return {"message": "feed deleted successfully"} - except ValueError as e: - raise HTTPException(status_code=404, detail=str(e)) \ No newline at end of file diff --git a/output/generated/routers/files_router.py b/output/generated/routers/files_router.py deleted file mode 100644 index 5c9db99..0000000 --- a/output/generated/routers/files_router.py +++ /dev/null @@ -1,116 +0,0 @@ -from fastapi import APIRouter, Depends, HTTPException, Query, Header, status -from fastapi.security import HTTPAuthorizationCredentials, HTTPBearer -from sqlalchemy.orm import Session -from typing import Optional, List -# -from database import get_db -from app.core.auth import get_current_user -from app.models.user import User # Modelo base de usuario -from app.modules.files.models import Files -from app.modules.files.schema import , Response -from app.modules.files.services import FilesService - -router = APIRouter(prefix="/files", tags=["files"]) -security = HTTPBearer() - -#================ Create ==================== -@router.post("/create", response_model=Response, status_code=status.HTTP_201_CREATED) -async def create_files( - data: , - db: Session = Depends(get_db), - current_user: User = Depends(get_current_user) -): - """Create a files - Requires authentication""" - - if not current_user: - raise HTTPException(status_code=401, detail="User not found - invalid token") - - if current_user.tipo_usuario not in ["root", "admin"]: - raise HTTPException(status_code=403, detail="You don't have permission to create files") - - try: - result = FilesService.create_files(db=db, data=data) - return result - except ValueError as e: - raise HTTPException(status_code=400, detail=str(e)) - -#================ Get ==================== -@router.get("/", response_model=List[Response]) -def get_filess( - db: Session = Depends(get_db), - current_user: User = Depends(get_current_user), - skip: int = Query(0, ge=0, description="Number of records to skip"), - limit: int = Query(100, ge=1, le=1000, description="Max number of records to return") -): - """Get list with pagination - requires authentication""" - - if not current_user: - raise HTTPException(status_code=401, detail="Authentication required") - - return FilesService.get_filess(db=db, skip=skip, limit=limit) - -#================ Get by ID ==================== -@router.get("/{{{entity_name}}_id}", response_model=Response) -def get_files_by_id( - files_id: int, - db: Session = Depends(get_db), - current_user: User = Depends(get_current_user) -): - """Get files by ID - requires authentication""" - - if not current_user: - raise HTTPException(status_code=401, detail="Authentication required") - - try: - result = FilesService.get_files(db=db, files_id=files_id, current_user=current_user) - return result - except ValueError as e: - raise HTTPException(status_code=404, detail=str(e)) - -#================ Update ==================== -@router.patch("/update/{{{entity_name}}_id}", response_model=Response) -async def update_files( - files_id: int, - data: , - db: Session = Depends(get_db), - current_user: User = Depends(get_current_user) -): - """Update existing files - requires authentication""" - - if not current_user: - raise HTTPException(status_code=401, detail="Authentication required") - - if current_user.tipo_usuario not in ["root", "admin"]: - raise HTTPException(status_code=403, detail="You don't have permission to update files") - - try: - result = FilesService.update_files( - db=db, - files_id=files_id, - data=data, - current_user=current_user - ) - return result - except ValueError as e: - raise HTTPException(status_code=404, detail=str(e)) - -#================ Delete ==================== -@router.delete("/delete/{{{entity_name}}_id}", status_code=status.HTTP_200_OK) -async def delete_files( - files_id: int, - db: Session = Depends(get_db), - current_user: User = Depends(get_current_user) -): - """Delete files by ID - requires authentication""" - - if not current_user: - raise HTTPException(status_code=401, detail="Authentication required") - - if current_user.tipo_usuario not in ["root", "admin"]: - raise HTTPException(status_code=403, detail="You don't have permission to delete files") - - try: - result = FilesService.delete_files(db=db, files_id=files_id, current_user=current_user) - return {"message": "files deleted successfully"} - except ValueError as e: - raise HTTPException(status_code=404, detail=str(e)) \ No newline at end of file diff --git a/output/generated/routers/invoices_router.py b/output/generated/routers/invoices_router.py deleted file mode 100644 index 91a341d..0000000 --- a/output/generated/routers/invoices_router.py +++ /dev/null @@ -1,116 +0,0 @@ -from fastapi import APIRouter, Depends, HTTPException, Query, Header, status -from fastapi.security import HTTPAuthorizationCredentials, HTTPBearer -from sqlalchemy.orm import Session -from typing import Optional, List -# -from database import get_db -from app.core.auth import get_current_user -from app.models.user import User # Modelo base de usuario -from app.modules.invoices.models import Invoices -from app.modules.invoices.schema import , Response -from app.modules.invoices.services import InvoicesService - -router = APIRouter(prefix="/invoices", tags=["invoices"]) -security = HTTPBearer() - -#================ Create ==================== -@router.post("/create", response_model=Response, status_code=status.HTTP_201_CREATED) -async def create_invoices( - data: , - db: Session = Depends(get_db), - current_user: User = Depends(get_current_user) -): - """Create a invoices - Requires authentication""" - - if not current_user: - raise HTTPException(status_code=401, detail="User not found - invalid token") - - if current_user.tipo_usuario not in ["root", "admin"]: - raise HTTPException(status_code=403, detail="You don't have permission to create invoices") - - try: - result = InvoicesService.create_invoices(db=db, data=data) - return result - except ValueError as e: - raise HTTPException(status_code=400, detail=str(e)) - -#================ Get ==================== -@router.get("/", response_model=List[Response]) -def get_invoicess( - db: Session = Depends(get_db), - current_user: User = Depends(get_current_user), - skip: int = Query(0, ge=0, description="Number of records to skip"), - limit: int = Query(100, ge=1, le=1000, description="Max number of records to return") -): - """Get list with pagination - requires authentication""" - - if not current_user: - raise HTTPException(status_code=401, detail="Authentication required") - - return InvoicesService.get_invoicess(db=db, skip=skip, limit=limit) - -#================ Get by ID ==================== -@router.get("/{{{entity_name}}_id}", response_model=Response) -def get_invoices_by_id( - invoices_id: int, - db: Session = Depends(get_db), - current_user: User = Depends(get_current_user) -): - """Get invoices by ID - requires authentication""" - - if not current_user: - raise HTTPException(status_code=401, detail="Authentication required") - - try: - result = InvoicesService.get_invoices(db=db, invoices_id=invoices_id, current_user=current_user) - return result - except ValueError as e: - raise HTTPException(status_code=404, detail=str(e)) - -#================ Update ==================== -@router.patch("/update/{{{entity_name}}_id}", response_model=Response) -async def update_invoices( - invoices_id: int, - data: , - db: Session = Depends(get_db), - current_user: User = Depends(get_current_user) -): - """Update existing invoices - requires authentication""" - - if not current_user: - raise HTTPException(status_code=401, detail="Authentication required") - - if current_user.tipo_usuario not in ["root", "admin"]: - raise HTTPException(status_code=403, detail="You don't have permission to update invoices") - - try: - result = InvoicesService.update_invoices( - db=db, - invoices_id=invoices_id, - data=data, - current_user=current_user - ) - return result - except ValueError as e: - raise HTTPException(status_code=404, detail=str(e)) - -#================ Delete ==================== -@router.delete("/delete/{{{entity_name}}_id}", status_code=status.HTTP_200_OK) -async def delete_invoices( - invoices_id: int, - db: Session = Depends(get_db), - current_user: User = Depends(get_current_user) -): - """Delete invoices by ID - requires authentication""" - - if not current_user: - raise HTTPException(status_code=401, detail="Authentication required") - - if current_user.tipo_usuario not in ["root", "admin"]: - raise HTTPException(status_code=403, detail="You don't have permission to delete invoices") - - try: - result = InvoicesService.delete_invoices(db=db, invoices_id=invoices_id, current_user=current_user) - return {"message": "invoices deleted successfully"} - except ValueError as e: - raise HTTPException(status_code=404, detail=str(e)) \ No newline at end of file diff --git a/output/generated/routers/license_router.py b/output/generated/routers/license_router.py deleted file mode 100644 index 7e090a9..0000000 --- a/output/generated/routers/license_router.py +++ /dev/null @@ -1,116 +0,0 @@ -from fastapi import APIRouter, Depends, HTTPException, Query, Header, status -from fastapi.security import HTTPAuthorizationCredentials, HTTPBearer -from sqlalchemy.orm import Session -from typing import Optional, List -# -from database import get_db -from app.core.auth import get_current_user -from app.models.user import User # Modelo base de usuario -from app.modules.license.models import License -from app.modules.license.schema import , Response -from app.modules.license.services import LicenseService - -router = APIRouter(prefix="/license", tags=["license"]) -security = HTTPBearer() - -#================ Create ==================== -@router.post("/create", response_model=Response, status_code=status.HTTP_201_CREATED) -async def create_license( - data: , - db: Session = Depends(get_db), - current_user: User = Depends(get_current_user) -): - """Create a license - Requires authentication""" - - if not current_user: - raise HTTPException(status_code=401, detail="User not found - invalid token") - - if current_user.tipo_usuario not in ["root", "admin"]: - raise HTTPException(status_code=403, detail="You don't have permission to create license") - - try: - result = LicenseService.create_license(db=db, data=data) - return result - except ValueError as e: - raise HTTPException(status_code=400, detail=str(e)) - -#================ Get ==================== -@router.get("/", response_model=List[Response]) -def get_licenses( - db: Session = Depends(get_db), - current_user: User = Depends(get_current_user), - skip: int = Query(0, ge=0, description="Number of records to skip"), - limit: int = Query(100, ge=1, le=1000, description="Max number of records to return") -): - """Get list with pagination - requires authentication""" - - if not current_user: - raise HTTPException(status_code=401, detail="Authentication required") - - return LicenseService.get_licenses(db=db, skip=skip, limit=limit) - -#================ Get by ID ==================== -@router.get("/{{{entity_name}}_id}", response_model=Response) -def get_license_by_id( - license_id: int, - db: Session = Depends(get_db), - current_user: User = Depends(get_current_user) -): - """Get license by ID - requires authentication""" - - if not current_user: - raise HTTPException(status_code=401, detail="Authentication required") - - try: - result = LicenseService.get_license(db=db, license_id=license_id, current_user=current_user) - return result - except ValueError as e: - raise HTTPException(status_code=404, detail=str(e)) - -#================ Update ==================== -@router.patch("/update/{{{entity_name}}_id}", response_model=Response) -async def update_license( - license_id: int, - data: , - db: Session = Depends(get_db), - current_user: User = Depends(get_current_user) -): - """Update existing license - requires authentication""" - - if not current_user: - raise HTTPException(status_code=401, detail="Authentication required") - - if current_user.tipo_usuario not in ["root", "admin"]: - raise HTTPException(status_code=403, detail="You don't have permission to update license") - - try: - result = LicenseService.update_license( - db=db, - license_id=license_id, - data=data, - current_user=current_user - ) - return result - except ValueError as e: - raise HTTPException(status_code=404, detail=str(e)) - -#================ Delete ==================== -@router.delete("/delete/{{{entity_name}}_id}", status_code=status.HTTP_200_OK) -async def delete_license( - license_id: int, - db: Session = Depends(get_db), - current_user: User = Depends(get_current_user) -): - """Delete license by ID - requires authentication""" - - if not current_user: - raise HTTPException(status_code=401, detail="Authentication required") - - if current_user.tipo_usuario not in ["root", "admin"]: - raise HTTPException(status_code=403, detail="You don't have permission to delete license") - - try: - result = LicenseService.delete_license(db=db, license_id=license_id, current_user=current_user) - return {"message": "license deleted successfully"} - except ValueError as e: - raise HTTPException(status_code=404, detail=str(e)) \ No newline at end of file diff --git a/output/generated/routers/locations_router.py b/output/generated/routers/locations_router.py deleted file mode 100644 index cf5d4fd..0000000 --- a/output/generated/routers/locations_router.py +++ /dev/null @@ -1,116 +0,0 @@ -from fastapi import APIRouter, Depends, HTTPException, Query, Header, status -from fastapi.security import HTTPAuthorizationCredentials, HTTPBearer -from sqlalchemy.orm import Session -from typing import Optional, List -# -from database import get_db -from app.core.auth import get_current_user -from app.models.user import User # Modelo base de usuario -from app.modules.locations.models import Locations -from app.modules.locations.schema import , Response -from app.modules.locations.services import LocationsService - -router = APIRouter(prefix="/locations", tags=["locations"]) -security = HTTPBearer() - -#================ Create ==================== -@router.post("/create", response_model=Response, status_code=status.HTTP_201_CREATED) -async def create_locations( - data: , - db: Session = Depends(get_db), - current_user: User = Depends(get_current_user) -): - """Create a locations - Requires authentication""" - - if not current_user: - raise HTTPException(status_code=401, detail="User not found - invalid token") - - if current_user.tipo_usuario not in ["root", "admin"]: - raise HTTPException(status_code=403, detail="You don't have permission to create locations") - - try: - result = LocationsService.create_locations(db=db, data=data) - return result - except ValueError as e: - raise HTTPException(status_code=400, detail=str(e)) - -#================ Get ==================== -@router.get("/", response_model=List[Response]) -def get_locationss( - db: Session = Depends(get_db), - current_user: User = Depends(get_current_user), - skip: int = Query(0, ge=0, description="Number of records to skip"), - limit: int = Query(100, ge=1, le=1000, description="Max number of records to return") -): - """Get list with pagination - requires authentication""" - - if not current_user: - raise HTTPException(status_code=401, detail="Authentication required") - - return LocationsService.get_locationss(db=db, skip=skip, limit=limit) - -#================ Get by ID ==================== -@router.get("/{{{entity_name}}_id}", response_model=Response) -def get_locations_by_id( - locations_id: int, - db: Session = Depends(get_db), - current_user: User = Depends(get_current_user) -): - """Get locations by ID - requires authentication""" - - if not current_user: - raise HTTPException(status_code=401, detail="Authentication required") - - try: - result = LocationsService.get_locations(db=db, locations_id=locations_id, current_user=current_user) - return result - except ValueError as e: - raise HTTPException(status_code=404, detail=str(e)) - -#================ Update ==================== -@router.patch("/update/{{{entity_name}}_id}", response_model=Response) -async def update_locations( - locations_id: int, - data: , - db: Session = Depends(get_db), - current_user: User = Depends(get_current_user) -): - """Update existing locations - requires authentication""" - - if not current_user: - raise HTTPException(status_code=401, detail="Authentication required") - - if current_user.tipo_usuario not in ["root", "admin"]: - raise HTTPException(status_code=403, detail="You don't have permission to update locations") - - try: - result = LocationsService.update_locations( - db=db, - locations_id=locations_id, - data=data, - current_user=current_user - ) - return result - except ValueError as e: - raise HTTPException(status_code=404, detail=str(e)) - -#================ Delete ==================== -@router.delete("/delete/{{{entity_name}}_id}", status_code=status.HTTP_200_OK) -async def delete_locations( - locations_id: int, - db: Session = Depends(get_db), - current_user: User = Depends(get_current_user) -): - """Delete locations by ID - requires authentication""" - - if not current_user: - raise HTTPException(status_code=401, detail="Authentication required") - - if current_user.tipo_usuario not in ["root", "admin"]: - raise HTTPException(status_code=403, detail="You don't have permission to delete locations") - - try: - result = LocationsService.delete_locations(db=db, locations_id=locations_id, current_user=current_user) - return {"message": "locations deleted successfully"} - except ValueError as e: - raise HTTPException(status_code=404, detail=str(e)) \ No newline at end of file diff --git a/output/generated/routers/moves_router.py b/output/generated/routers/moves_router.py deleted file mode 100644 index abc5100..0000000 --- a/output/generated/routers/moves_router.py +++ /dev/null @@ -1,116 +0,0 @@ -from fastapi import APIRouter, Depends, HTTPException, Query, Header, status -from fastapi.security import HTTPAuthorizationCredentials, HTTPBearer -from sqlalchemy.orm import Session -from typing import Optional, List -# -from database import get_db -from app.core.auth import get_current_user -from app.models.user import User # Modelo base de usuario -from app.modules.moves.models import Moves -from app.modules.moves.schema import , Response -from app.modules.moves.services import MovesService - -router = APIRouter(prefix="/moves", tags=["moves"]) -security = HTTPBearer() - -#================ Create ==================== -@router.post("/create", response_model=Response, status_code=status.HTTP_201_CREATED) -async def create_moves( - data: , - db: Session = Depends(get_db), - current_user: User = Depends(get_current_user) -): - """Create a moves - Requires authentication""" - - if not current_user: - raise HTTPException(status_code=401, detail="User not found - invalid token") - - if current_user.tipo_usuario not in ["root", "admin"]: - raise HTTPException(status_code=403, detail="You don't have permission to create moves") - - try: - result = MovesService.create_moves(db=db, data=data) - return result - except ValueError as e: - raise HTTPException(status_code=400, detail=str(e)) - -#================ Get ==================== -@router.get("/", response_model=List[Response]) -def get_movess( - db: Session = Depends(get_db), - current_user: User = Depends(get_current_user), - skip: int = Query(0, ge=0, description="Number of records to skip"), - limit: int = Query(100, ge=1, le=1000, description="Max number of records to return") -): - """Get list with pagination - requires authentication""" - - if not current_user: - raise HTTPException(status_code=401, detail="Authentication required") - - return MovesService.get_movess(db=db, skip=skip, limit=limit) - -#================ Get by ID ==================== -@router.get("/{{{entity_name}}_id}", response_model=Response) -def get_moves_by_id( - moves_id: int, - db: Session = Depends(get_db), - current_user: User = Depends(get_current_user) -): - """Get moves by ID - requires authentication""" - - if not current_user: - raise HTTPException(status_code=401, detail="Authentication required") - - try: - result = MovesService.get_moves(db=db, moves_id=moves_id, current_user=current_user) - return result - except ValueError as e: - raise HTTPException(status_code=404, detail=str(e)) - -#================ Update ==================== -@router.patch("/update/{{{entity_name}}_id}", response_model=Response) -async def update_moves( - moves_id: int, - data: , - db: Session = Depends(get_db), - current_user: User = Depends(get_current_user) -): - """Update existing moves - requires authentication""" - - if not current_user: - raise HTTPException(status_code=401, detail="Authentication required") - - if current_user.tipo_usuario not in ["root", "admin"]: - raise HTTPException(status_code=403, detail="You don't have permission to update moves") - - try: - result = MovesService.update_moves( - db=db, - moves_id=moves_id, - data=data, - current_user=current_user - ) - return result - except ValueError as e: - raise HTTPException(status_code=404, detail=str(e)) - -#================ Delete ==================== -@router.delete("/delete/{{{entity_name}}_id}", status_code=status.HTTP_200_OK) -async def delete_moves( - moves_id: int, - db: Session = Depends(get_db), - current_user: User = Depends(get_current_user) -): - """Delete moves by ID - requires authentication""" - - if not current_user: - raise HTTPException(status_code=401, detail="Authentication required") - - if current_user.tipo_usuario not in ["root", "admin"]: - raise HTTPException(status_code=403, detail="You don't have permission to delete moves") - - try: - result = MovesService.delete_moves(db=db, moves_id=moves_id, current_user=current_user) - return {"message": "moves deleted successfully"} - except ValueError as e: - raise HTTPException(status_code=404, detail=str(e)) \ No newline at end of file diff --git a/output/generated/routers/suppliers_router.py b/output/generated/routers/suppliers_router.py deleted file mode 100644 index 5ce9cf6..0000000 --- a/output/generated/routers/suppliers_router.py +++ /dev/null @@ -1,116 +0,0 @@ -from fastapi import APIRouter, Depends, HTTPException, Query, Header, status -from fastapi.security import HTTPAuthorizationCredentials, HTTPBearer -from sqlalchemy.orm import Session -from typing import Optional, List -# -from database import get_db -from app.core.auth import get_current_user -from app.models.user import User # Modelo base de usuario -from app.modules.suppliers.models import Suppliers -from app.modules.suppliers.schema import , Response -from app.modules.suppliers.services import SuppliersService - -router = APIRouter(prefix="/suppliers", tags=["suppliers"]) -security = HTTPBearer() - -#================ Create ==================== -@router.post("/create", response_model=Response, status_code=status.HTTP_201_CREATED) -async def create_suppliers( - data: , - db: Session = Depends(get_db), - current_user: User = Depends(get_current_user) -): - """Create a suppliers - Requires authentication""" - - if not current_user: - raise HTTPException(status_code=401, detail="User not found - invalid token") - - if current_user.tipo_usuario not in ["root", "admin"]: - raise HTTPException(status_code=403, detail="You don't have permission to create suppliers") - - try: - result = SuppliersService.create_suppliers(db=db, data=data) - return result - except ValueError as e: - raise HTTPException(status_code=400, detail=str(e)) - -#================ Get ==================== -@router.get("/", response_model=List[Response]) -def get_supplierss( - db: Session = Depends(get_db), - current_user: User = Depends(get_current_user), - skip: int = Query(0, ge=0, description="Number of records to skip"), - limit: int = Query(100, ge=1, le=1000, description="Max number of records to return") -): - """Get list with pagination - requires authentication""" - - if not current_user: - raise HTTPException(status_code=401, detail="Authentication required") - - return SuppliersService.get_supplierss(db=db, skip=skip, limit=limit) - -#================ Get by ID ==================== -@router.get("/{{{entity_name}}_id}", response_model=Response) -def get_suppliers_by_id( - suppliers_id: int, - db: Session = Depends(get_db), - current_user: User = Depends(get_current_user) -): - """Get suppliers by ID - requires authentication""" - - if not current_user: - raise HTTPException(status_code=401, detail="Authentication required") - - try: - result = SuppliersService.get_suppliers(db=db, suppliers_id=suppliers_id, current_user=current_user) - return result - except ValueError as e: - raise HTTPException(status_code=404, detail=str(e)) - -#================ Update ==================== -@router.patch("/update/{{{entity_name}}_id}", response_model=Response) -async def update_suppliers( - suppliers_id: int, - data: , - db: Session = Depends(get_db), - current_user: User = Depends(get_current_user) -): - """Update existing suppliers - requires authentication""" - - if not current_user: - raise HTTPException(status_code=401, detail="Authentication required") - - if current_user.tipo_usuario not in ["root", "admin"]: - raise HTTPException(status_code=403, detail="You don't have permission to update suppliers") - - try: - result = SuppliersService.update_suppliers( - db=db, - suppliers_id=suppliers_id, - data=data, - current_user=current_user - ) - return result - except ValueError as e: - raise HTTPException(status_code=404, detail=str(e)) - -#================ Delete ==================== -@router.delete("/delete/{{{entity_name}}_id}", status_code=status.HTTP_200_OK) -async def delete_suppliers( - suppliers_id: int, - db: Session = Depends(get_db), - current_user: User = Depends(get_current_user) -): - """Delete suppliers by ID - requires authentication""" - - if not current_user: - raise HTTPException(status_code=401, detail="Authentication required") - - if current_user.tipo_usuario not in ["root", "admin"]: - raise HTTPException(status_code=403, detail="You don't have permission to delete suppliers") - - try: - result = SuppliersService.delete_suppliers(db=db, suppliers_id=suppliers_id, current_user=current_user) - return {"message": "suppliers deleted successfully"} - except ValueError as e: - raise HTTPException(status_code=404, detail=str(e)) \ No newline at end of file diff --git a/output/generated/services/branches_service.py b/output/generated/services/branches_service.py deleted file mode 100644 index 8bd8794..0000000 --- a/output/generated/services/branches_service.py +++ /dev/null @@ -1,67 +0,0 @@ -from sqlalchemy.orm import Session -from datetime import datetime -from typing import Optional -from fastapi import HTTPException -from app.modules.branches.models import Branches -from app.modules.branches.schema import - - -class BranchesService: - @staticmethod - def create_branches(db: Session, data: ): - - - - - new_branches = Branches(**data.dict()) - db.add(new_branches) - db.commit() - db.refresh(new_branches) - return new_branches - - @staticmethod - def get_branches(db: Session, branches_id: int, current_user): - branches = db.query(Branches).filter(Branches.id == branches_id).first() - if not branches: - raise ValueError("branches no encontrado") - return branches - - @staticmethod - def update_branches(db: Session, branches_id: int, data: , current_user): - branches = db.query(Branches).filter(Branches.id == branches_id).first() - if not branches: - raise ValueError("branches no encontrado") - - if current_user.role not in ["ROOT", "ADMIN"]: - raise ValueError("No tienes permisos para actualizar este branches") - - update_data = data.dict(exclude_unset=True) - for key, value in update_data.items(): - setattr(branches, key, value) - - db.commit() - db.refresh(branches) - return branches - - @staticmethod - def delete_branches(db: Session, branches_id: int, current_user): - branches = db.query(Branches).filter(Branches.id == branches_id).first() - if not branches: - raise ValueError("branches no encontrado") - - if current_user.role not in ["ROOT", "ADMIN"]: - raise ValueError("No tienes permisos para eliminar este branches") - - try: - branches.is_active = False - branches.deleted_at = datetime.utcnow() - branches.deleted_by = current_user.id - db.commit() - db.refresh(branches) - except Exception as e: - db.rollback() - raise ValueError(f"Error al eliminar el branches: {e}") - - return {"message": "branches eliminado correctamente"} - - \ No newline at end of file diff --git a/output/generated/services/client_service.py b/output/generated/services/client_service.py deleted file mode 100644 index 37c2c3f..0000000 --- a/output/generated/services/client_service.py +++ /dev/null @@ -1,67 +0,0 @@ -from sqlalchemy.orm import Session -from datetime import datetime -from typing import Optional -from fastapi import HTTPException -from app.modules.client.models import Client -from app.modules.client.schema import - - -class ClientService: - @staticmethod - def create_client(db: Session, data: ): - - - - - new_client = Client(**data.dict()) - db.add(new_client) - db.commit() - db.refresh(new_client) - return new_client - - @staticmethod - def get_client(db: Session, client_id: int, current_user): - client = db.query(Client).filter(Client.id == client_id).first() - if not client: - raise ValueError("client no encontrado") - return client - - @staticmethod - def update_client(db: Session, client_id: int, data: , current_user): - client = db.query(Client).filter(Client.id == client_id).first() - if not client: - raise ValueError("client no encontrado") - - if current_user.role not in ["ROOT", "ADMIN"]: - raise ValueError("No tienes permisos para actualizar este client") - - update_data = data.dict(exclude_unset=True) - for key, value in update_data.items(): - setattr(client, key, value) - - db.commit() - db.refresh(client) - return client - - @staticmethod - def delete_client(db: Session, client_id: int, current_user): - client = db.query(Client).filter(Client.id == client_id).first() - if not client: - raise ValueError("client no encontrado") - - if current_user.role not in ["ROOT", "ADMIN"]: - raise ValueError("No tienes permisos para eliminar este client") - - try: - client.is_active = False - client.deleted_at = datetime.utcnow() - client.deleted_by = current_user.id - db.commit() - db.refresh(client) - except Exception as e: - db.rollback() - raise ValueError(f"Error al eliminar el client: {e}") - - return {"message": "client eliminado correctamente"} - - \ No newline at end of file diff --git a/output/generated/services/coments_service.py b/output/generated/services/coments_service.py deleted file mode 100644 index a5dd49c..0000000 --- a/output/generated/services/coments_service.py +++ /dev/null @@ -1,67 +0,0 @@ -from sqlalchemy.orm import Session -from datetime import datetime -from typing import Optional -from fastapi import HTTPException -from app.modules.coments.models import Coments -from app.modules.coments.schema import - - -class ComentsService: - @staticmethod - def create_coments(db: Session, data: ): - - - - - new_coments = Coments(**data.dict()) - db.add(new_coments) - db.commit() - db.refresh(new_coments) - return new_coments - - @staticmethod - def get_coments(db: Session, coments_id: int, current_user): - coments = db.query(Coments).filter(Coments.id == coments_id).first() - if not coments: - raise ValueError("coments no encontrado") - return coments - - @staticmethod - def update_coments(db: Session, coments_id: int, data: , current_user): - coments = db.query(Coments).filter(Coments.id == coments_id).first() - if not coments: - raise ValueError("coments no encontrado") - - if current_user.role not in ["ROOT", "ADMIN"]: - raise ValueError("No tienes permisos para actualizar este coments") - - update_data = data.dict(exclude_unset=True) - for key, value in update_data.items(): - setattr(coments, key, value) - - db.commit() - db.refresh(coments) - return coments - - @staticmethod - def delete_coments(db: Session, coments_id: int, current_user): - coments = db.query(Coments).filter(Coments.id == coments_id).first() - if not coments: - raise ValueError("coments no encontrado") - - if current_user.role not in ["ROOT", "ADMIN"]: - raise ValueError("No tienes permisos para eliminar este coments") - - try: - coments.is_active = False - coments.deleted_at = datetime.utcnow() - coments.deleted_by = current_user.id - db.commit() - db.refresh(coments) - except Exception as e: - db.rollback() - raise ValueError(f"Error al eliminar el coments: {e}") - - return {"message": "coments eliminado correctamente"} - - \ No newline at end of file diff --git a/output/generated/services/edos_service.py b/output/generated/services/edos_service.py deleted file mode 100644 index a13a5d1..0000000 --- a/output/generated/services/edos_service.py +++ /dev/null @@ -1,67 +0,0 @@ -from sqlalchemy.orm import Session -from datetime import datetime -from typing import Optional -from fastapi import HTTPException -from app.modules.edos.models import EDOS -from app.modules.edos.schema import - - -class EDOSService: - @staticmethod - def create_edos(db: Session, data: ): - - - - - new_edos = EDOS(**data.dict()) - db.add(new_edos) - db.commit() - db.refresh(new_edos) - return new_edos - - @staticmethod - def get_edos(db: Session, edos_id: int, current_user): - edos = db.query(EDOS).filter(EDOS.id == edos_id).first() - if not edos: - raise ValueError("edos no encontrado") - return edos - - @staticmethod - def update_edos(db: Session, edos_id: int, data: , current_user): - edos = db.query(EDOS).filter(EDOS.id == edos_id).first() - if not edos: - raise ValueError("edos no encontrado") - - if current_user.role not in ["ROOT", "ADMIN"]: - raise ValueError("No tienes permisos para actualizar este edos") - - update_data = data.dict(exclude_unset=True) - for key, value in update_data.items(): - setattr(edos, key, value) - - db.commit() - db.refresh(edos) - return edos - - @staticmethod - def delete_edos(db: Session, edos_id: int, current_user): - edos = db.query(EDOS).filter(EDOS.id == edos_id).first() - if not edos: - raise ValueError("edos no encontrado") - - if current_user.role not in ["ROOT", "ADMIN"]: - raise ValueError("No tienes permisos para eliminar este edos") - - try: - edos.is_active = False - edos.deleted_at = datetime.utcnow() - edos.deleted_by = current_user.id - db.commit() - db.refresh(edos) - except Exception as e: - db.rollback() - raise ValueError(f"Error al eliminar el edos: {e}") - - return {"message": "edos eliminado correctamente"} - - \ No newline at end of file diff --git a/output/generated/services/efos_service.py b/output/generated/services/efos_service.py deleted file mode 100644 index 2a1a488..0000000 --- a/output/generated/services/efos_service.py +++ /dev/null @@ -1,67 +0,0 @@ -from sqlalchemy.orm import Session -from datetime import datetime -from typing import Optional -from fastapi import HTTPException -from app.modules.efos.models import EFOS -from app.modules.efos.schema import - - -class EFOSService: - @staticmethod - def create_efos(db: Session, data: ): - - - - - new_efos = EFOS(**data.dict()) - db.add(new_efos) - db.commit() - db.refresh(new_efos) - return new_efos - - @staticmethod - def get_efos(db: Session, efos_id: int, current_user): - efos = db.query(EFOS).filter(EFOS.id == efos_id).first() - if not efos: - raise ValueError("efos no encontrado") - return efos - - @staticmethod - def update_efos(db: Session, efos_id: int, data: , current_user): - efos = db.query(EFOS).filter(EFOS.id == efos_id).first() - if not efos: - raise ValueError("efos no encontrado") - - if current_user.role not in ["ROOT", "ADMIN"]: - raise ValueError("No tienes permisos para actualizar este efos") - - update_data = data.dict(exclude_unset=True) - for key, value in update_data.items(): - setattr(efos, key, value) - - db.commit() - db.refresh(efos) - return efos - - @staticmethod - def delete_efos(db: Session, efos_id: int, current_user): - efos = db.query(EFOS).filter(EFOS.id == efos_id).first() - if not efos: - raise ValueError("efos no encontrado") - - if current_user.role not in ["ROOT", "ADMIN"]: - raise ValueError("No tienes permisos para eliminar este efos") - - try: - efos.is_active = False - efos.deleted_at = datetime.utcnow() - efos.deleted_by = current_user.id - db.commit() - db.refresh(efos) - except Exception as e: - db.rollback() - raise ValueError(f"Error al eliminar el efos: {e}") - - return {"message": "efos eliminado correctamente"} - - \ No newline at end of file diff --git a/output/generated/services/files_service.py b/output/generated/services/files_service.py deleted file mode 100644 index eb588d5..0000000 --- a/output/generated/services/files_service.py +++ /dev/null @@ -1,67 +0,0 @@ -from sqlalchemy.orm import Session -from datetime import datetime -from typing import Optional -from fastapi import HTTPException -from app.modules.files.models import Files -from app.modules.files.schema import - - -class FilesService: - @staticmethod - def create_files(db: Session, data: ): - - - - - new_files = Files(**data.dict()) - db.add(new_files) - db.commit() - db.refresh(new_files) - return new_files - - @staticmethod - def get_files(db: Session, files_id: int, current_user): - files = db.query(Files).filter(Files.id == files_id).first() - if not files: - raise ValueError("files no encontrado") - return files - - @staticmethod - def update_files(db: Session, files_id: int, data: , current_user): - files = db.query(Files).filter(Files.id == files_id).first() - if not files: - raise ValueError("files no encontrado") - - if current_user.role not in ["ROOT", "ADMIN"]: - raise ValueError("No tienes permisos para actualizar este files") - - update_data = data.dict(exclude_unset=True) - for key, value in update_data.items(): - setattr(files, key, value) - - db.commit() - db.refresh(files) - return files - - @staticmethod - def delete_files(db: Session, files_id: int, current_user): - files = db.query(Files).filter(Files.id == files_id).first() - if not files: - raise ValueError("files no encontrado") - - if current_user.role not in ["ROOT", "ADMIN"]: - raise ValueError("No tienes permisos para eliminar este files") - - try: - files.is_active = False - files.deleted_at = datetime.utcnow() - files.deleted_by = current_user.id - db.commit() - db.refresh(files) - except Exception as e: - db.rollback() - raise ValueError(f"Error al eliminar el files: {e}") - - return {"message": "files eliminado correctamente"} - - \ No newline at end of file diff --git a/output/generated/services/invoices_service.py b/output/generated/services/invoices_service.py deleted file mode 100644 index 295d046..0000000 --- a/output/generated/services/invoices_service.py +++ /dev/null @@ -1,67 +0,0 @@ -from sqlalchemy.orm import Session -from datetime import datetime -from typing import Optional -from fastapi import HTTPException -from app.modules.invoices.models import Invoices -from app.modules.invoices.schema import - - -class InvoicesService: - @staticmethod - def create_invoices(db: Session, data: ): - - - - - new_invoices = Invoices(**data.dict()) - db.add(new_invoices) - db.commit() - db.refresh(new_invoices) - return new_invoices - - @staticmethod - def get_invoices(db: Session, invoices_id: int, current_user): - invoices = db.query(Invoices).filter(Invoices.id == invoices_id).first() - if not invoices: - raise ValueError("invoices no encontrado") - return invoices - - @staticmethod - def update_invoices(db: Session, invoices_id: int, data: , current_user): - invoices = db.query(Invoices).filter(Invoices.id == invoices_id).first() - if not invoices: - raise ValueError("invoices no encontrado") - - if current_user.role not in ["ROOT", "ADMIN"]: - raise ValueError("No tienes permisos para actualizar este invoices") - - update_data = data.dict(exclude_unset=True) - for key, value in update_data.items(): - setattr(invoices, key, value) - - db.commit() - db.refresh(invoices) - return invoices - - @staticmethod - def delete_invoices(db: Session, invoices_id: int, current_user): - invoices = db.query(Invoices).filter(Invoices.id == invoices_id).first() - if not invoices: - raise ValueError("invoices no encontrado") - - if current_user.role not in ["ROOT", "ADMIN"]: - raise ValueError("No tienes permisos para eliminar este invoices") - - try: - invoices.is_active = False - invoices.deleted_at = datetime.utcnow() - invoices.deleted_by = current_user.id - db.commit() - db.refresh(invoices) - except Exception as e: - db.rollback() - raise ValueError(f"Error al eliminar el invoices: {e}") - - return {"message": "invoices eliminado correctamente"} - - \ No newline at end of file diff --git a/output/generated/services/locations_service.py b/output/generated/services/locations_service.py deleted file mode 100644 index 58319a6..0000000 --- a/output/generated/services/locations_service.py +++ /dev/null @@ -1,67 +0,0 @@ -from sqlalchemy.orm import Session -from datetime import datetime -from typing import Optional -from fastapi import HTTPException -from app.modules.locations.models import Locations -from app.modules.locations.schema import - - -class LocationsService: - @staticmethod - def create_locations(db: Session, data: ): - - - - - new_locations = Locations(**data.dict()) - db.add(new_locations) - db.commit() - db.refresh(new_locations) - return new_locations - - @staticmethod - def get_locations(db: Session, locations_id: int, current_user): - locations = db.query(Locations).filter(Locations.id == locations_id).first() - if not locations: - raise ValueError("locations no encontrado") - return locations - - @staticmethod - def update_locations(db: Session, locations_id: int, data: , current_user): - locations = db.query(Locations).filter(Locations.id == locations_id).first() - if not locations: - raise ValueError("locations no encontrado") - - if current_user.role not in ["ROOT", "ADMIN"]: - raise ValueError("No tienes permisos para actualizar este locations") - - update_data = data.dict(exclude_unset=True) - for key, value in update_data.items(): - setattr(locations, key, value) - - db.commit() - db.refresh(locations) - return locations - - @staticmethod - def delete_locations(db: Session, locations_id: int, current_user): - locations = db.query(Locations).filter(Locations.id == locations_id).first() - if not locations: - raise ValueError("locations no encontrado") - - if current_user.role not in ["ROOT", "ADMIN"]: - raise ValueError("No tienes permisos para eliminar este locations") - - try: - locations.is_active = False - locations.deleted_at = datetime.utcnow() - locations.deleted_by = current_user.id - db.commit() - db.refresh(locations) - except Exception as e: - db.rollback() - raise ValueError(f"Error al eliminar el locations: {e}") - - return {"message": "locations eliminado correctamente"} - - \ No newline at end of file diff --git a/output/generated/services/moves_service.py b/output/generated/services/moves_service.py deleted file mode 100644 index 23e0357..0000000 --- a/output/generated/services/moves_service.py +++ /dev/null @@ -1,67 +0,0 @@ -from sqlalchemy.orm import Session -from datetime import datetime -from typing import Optional -from fastapi import HTTPException -from app.modules.moves.models import Moves -from app.modules.moves.schema import - - -class MovesService: - @staticmethod - def create_moves(db: Session, data: ): - - - - - new_moves = Moves(**data.dict()) - db.add(new_moves) - db.commit() - db.refresh(new_moves) - return new_moves - - @staticmethod - def get_moves(db: Session, moves_id: int, current_user): - moves = db.query(Moves).filter(Moves.id == moves_id).first() - if not moves: - raise ValueError("moves no encontrado") - return moves - - @staticmethod - def update_moves(db: Session, moves_id: int, data: , current_user): - moves = db.query(Moves).filter(Moves.id == moves_id).first() - if not moves: - raise ValueError("moves no encontrado") - - if current_user.role not in ["ROOT", "ADMIN"]: - raise ValueError("No tienes permisos para actualizar este moves") - - update_data = data.dict(exclude_unset=True) - for key, value in update_data.items(): - setattr(moves, key, value) - - db.commit() - db.refresh(moves) - return moves - - @staticmethod - def delete_moves(db: Session, moves_id: int, current_user): - moves = db.query(Moves).filter(Moves.id == moves_id).first() - if not moves: - raise ValueError("moves no encontrado") - - if current_user.role not in ["ROOT", "ADMIN"]: - raise ValueError("No tienes permisos para eliminar este moves") - - try: - moves.is_active = False - moves.deleted_at = datetime.utcnow() - moves.deleted_by = current_user.id - db.commit() - db.refresh(moves) - except Exception as e: - db.rollback() - raise ValueError(f"Error al eliminar el moves: {e}") - - return {"message": "moves eliminado correctamente"} - - \ No newline at end of file diff --git a/output/generated/services/suppliers_service.py b/output/generated/services/suppliers_service.py deleted file mode 100644 index 0d81e79..0000000 --- a/output/generated/services/suppliers_service.py +++ /dev/null @@ -1,67 +0,0 @@ -from sqlalchemy.orm import Session -from datetime import datetime -from typing import Optional -from fastapi import HTTPException -from app.modules.suppliers.models import Suppliers -from app.modules.suppliers.schema import - - -class SuppliersService: - @staticmethod - def create_suppliers(db: Session, data: ): - - - - - new_suppliers = Suppliers(**data.dict()) - db.add(new_suppliers) - db.commit() - db.refresh(new_suppliers) - return new_suppliers - - @staticmethod - def get_suppliers(db: Session, suppliers_id: int, current_user): - suppliers = db.query(Suppliers).filter(Suppliers.id == suppliers_id).first() - if not suppliers: - raise ValueError("suppliers no encontrado") - return suppliers - - @staticmethod - def update_suppliers(db: Session, suppliers_id: int, data: , current_user): - suppliers = db.query(Suppliers).filter(Suppliers.id == suppliers_id).first() - if not suppliers: - raise ValueError("suppliers no encontrado") - - if current_user.role not in ["ROOT", "ADMIN"]: - raise ValueError("No tienes permisos para actualizar este suppliers") - - update_data = data.dict(exclude_unset=True) - for key, value in update_data.items(): - setattr(suppliers, key, value) - - db.commit() - db.refresh(suppliers) - return suppliers - - @staticmethod - def delete_suppliers(db: Session, suppliers_id: int, current_user): - suppliers = db.query(Suppliers).filter(Suppliers.id == suppliers_id).first() - if not suppliers: - raise ValueError("suppliers no encontrado") - - if current_user.role not in ["ROOT", "ADMIN"]: - raise ValueError("No tienes permisos para eliminar este suppliers") - - try: - suppliers.is_active = False - suppliers.deleted_at = datetime.utcnow() - suppliers.deleted_by = current_user.id - db.commit() - db.refresh(suppliers) - except Exception as e: - db.rollback() - raise ValueError(f"Error al eliminar el suppliers: {e}") - - return {"message": "suppliers eliminado correctamente"} - - \ No newline at end of file diff --git a/requerimiento_minimos.txt b/requerimiento_minimos.txt index 82b815e..9a8b649 100644 --- a/requerimiento_minimos.txt +++ b/requerimiento_minimos.txt @@ -1,4 +1,4 @@ -qeuitar condenados_contenados +quitar condenados_contenados ajustar el envio de notificacions ajustar los matchs de visualizacion diff --git a/requirements.txt b/requirements.txt index 974b93a..86ff5f8 100644 --- a/requirements.txt +++ b/requirements.txt @@ -5,6 +5,7 @@ sqlalchemy==2.0.23 alembic==1.12.1 psycopg2-binary==2.9.9 python-dotenv==1.0.0 +pandas>=2.0.0 pydantic==2.5.0 python-jose[cryptography]==3.3.0 passlib[bcrypt]==1.7.4 @@ -12,4 +13,5 @@ python-multipart==0.0.6 pyjwt==2.8.0 email-validator==2.1.0 python-dateutil==2.8.2 -bcrypt==4.0.1 \ No newline at end of file +bcrypt==4.0.1 +requests==2.31.0 \ No newline at end of file diff --git a/test_csv_extractor.py b/test_csv_extractor.py new file mode 100644 index 0000000..b9b5925 --- /dev/null +++ b/test_csv_extractor.py @@ -0,0 +1,24 @@ +# test_csv_extractor.py +import sys +from pathlib import Path + +# Añadir el directorio raíz al path +sys.path.append(str(Path(__file__).parent)) + +from app.helpers.extractCsv import CSVExtractor + +# Prueba con un CSV público +test_url = "https://people.sc.fsu.edu/~jburkardt/data/csv/hw_200.csv" + +try: + print("📥 Descargando CSV...") + content = CSVExtractor.download_csv(test_url) + print(f"✅ Descargado: {len(content)} caracteres") + + print("📖 Leyendo CSV...") + rows = CSVExtractor.read_csv(content) + print(f"✅ Leídas {len(rows)} filas") + print(f"📋 Columnas: {list(rows[0].keys()) if rows else 'Ninguna'}") + +except Exception as e: + print(f"❌ Error: {e}") \ No newline at end of file