From 92c52954c85646628f6b5861856ec443fa7b72e1 Mon Sep 17 00:00:00 2001 From: Sergey Vanyushkin Date: Mon, 4 Mar 2024 10:15:28 +0000 Subject: [PATCH] sync --- api/__pycache__/__init__.cpython-311.pyc | Bin 0 -> 152 bytes api/__pycache__/app.cpython-311.pyc | Bin 0 -> 712 bytes api/__pycache__/di.cpython-311.pyc | Bin 0 -> 1959 bytes api/app.py | 4 +- api/di.py | 20 +++++-- .../__pycache__/env.cpython-311.pyc | Bin 0 -> 3065 bytes .../ec1380cb4f18_initial.cpython-311.pyc | Bin 0 -> 1868 bytes .../__pycache__/__init__.cpython-311.pyc | Bin 0 -> 158 bytes api/model/__pycache__/user.cpython-311.pyc | Bin 0 -> 1220 bytes api/model/user.py | 2 +- .../__pycache__/__init__.cpython-311.pyc | Bin 0 -> 163 bytes .../__pycache__/user.cpython-311.pyc | Bin 0 -> 931 bytes api/repository/user.py | 49 ++---------------- .../__pycache__/__init__.cpython-311.pyc | Bin 0 -> 159 bytes api/router/__pycache__/user.cpython-311.pyc | Bin 0 -> 1179 bytes api/router/user.py | 45 ++-------------- .../__pycache__/__init__.cpython-311.pyc | Bin 0 -> 160 bytes api/service/__pycache__/user.cpython-311.pyc | Bin 0 -> 1009 bytes api/service/user.py | 22 ++------ api/uow/__pycache__/__init__.cpython-311.pyc | Bin 0 -> 156 bytes api/uow/__pycache__/database.cpython-311.pyc | Bin 0 -> 2614 bytes api/uow/__pycache__/uow_base.cpython-311.pyc | Bin 0 -> 1844 bytes api/uow/database.py | 18 +++++-- api/uow/uow_base.py | 23 ++++++++ manage.py | 11 ++++ 25 files changed, 80 insertions(+), 114 deletions(-) create mode 100644 api/__pycache__/__init__.cpython-311.pyc create mode 100644 api/__pycache__/app.cpython-311.pyc create mode 100644 api/__pycache__/di.cpython-311.pyc create mode 100644 api/migrations/__pycache__/env.cpython-311.pyc create mode 100644 api/migrations/versions/__pycache__/ec1380cb4f18_initial.cpython-311.pyc create mode 100644 api/model/__pycache__/__init__.cpython-311.pyc create mode 100644 api/model/__pycache__/user.cpython-311.pyc create mode 100644 api/repository/__pycache__/__init__.cpython-311.pyc create mode 100644 api/repository/__pycache__/user.cpython-311.pyc create mode 100644 api/router/__pycache__/__init__.cpython-311.pyc create mode 100644 api/router/__pycache__/user.cpython-311.pyc create mode 100644 api/service/__pycache__/__init__.cpython-311.pyc create mode 100644 api/service/__pycache__/user.cpython-311.pyc create mode 100644 api/uow/__pycache__/__init__.cpython-311.pyc create mode 100644 api/uow/__pycache__/database.cpython-311.pyc create mode 100644 api/uow/__pycache__/uow_base.cpython-311.pyc create mode 100644 api/uow/uow_base.py create mode 100644 manage.py diff --git a/api/__pycache__/__init__.cpython-311.pyc b/api/__pycache__/__init__.cpython-311.pyc new file mode 100644 index 0000000000000000000000000000000000000000..912a19f461d35dafa0a04683326d7951d8679c3e GIT binary patch literal 152 zcmZ3^%ge<81l&PSQ$h4&5CH>>P{wCAAY(d13PUi1CZpdBam&;sY}yBjX1K7*WIw6axS`njwt< literal 0 HcmV?d00001 diff --git a/api/__pycache__/app.cpython-311.pyc b/api/__pycache__/app.cpython-311.pyc new file mode 100644 index 0000000000000000000000000000000000000000..0053790cab37f1fe3a25a0e522ac6aa15ec410f1 GIT binary patch literal 712 zcmZ8f&1=*^6n~S%+k$f>p1aXBF_EPX* zp`}+(E7E^v6~QG?D3l(0Ti9DqzS$-7%8Mn4P^%MG}|Koen_aDgXJQW4m94G^e>Ek+1VA;G0fsSf)LiOeme`fdcn zk{pcS+dp|_K0s2x#}k}#b~lM&4bmWcdQHeuLDA(6yJV1e+`#ryhYt%Ltu*GM2#}s? zMNurfJ-OL5-i1ClBKMhX2p)w7CVp^jKJ=}?up$>N>O~*(rY*RY@F9kxjg<^7Hqd2o z-dsJ@zvx;2{L#kI;CPVr$FF9T{h@2W=-SDrpS1g%cBiyEYjv{S1(v{`-pJWLetI0R zB#>)}dX9TbWJLzIoA>16qJ}j>{wB-OqJ`)Oh>pB?fbORL+z*}9<1fTR3?;GnExNf% s2${j-X;m*^eOlESJe^i`u2Hh`_2nG!_}_Jat!D2Jys?+5@>wqO7j;;kuK)l5 literal 0 HcmV?d00001 diff --git a/api/__pycache__/di.cpython-311.pyc b/api/__pycache__/di.cpython-311.pyc new file mode 100644 index 0000000000000000000000000000000000000000..7039985e1df9b56a23d5eeac947c01bb5cb387db GIT binary patch literal 1959 zcmZuy&rjP{9DjBa$8lnkkqlA@n4=dHQ0c*zw2`a0m`C^&)kvg*D^f>{g zRi#MlfdiVjZPIq=WlR$sde~uqMyM>+@+s1^!)`%v>S^C+$Bbk=KY!o%$LBqN-+P~L z@|!3M2-^2Q{Eaul2>nHkphf!1c>|Omk&0ACM-m-boiSL6H9}H|p>{|Q8xbku>0zBS zqEgh;BRX%yq?o63x?semID=U90IAUzNaZnGO#~l13L$h1uiqq5Wwua0_763SdDa!m zX04%UHB2lwRww4Jrh=Mh+>u8XCJ%Alw6umvTHuLO&lV=TS{Z}MuPO~?Td}AfePr$} zgIex?#v8l?0PXyOq1(hrVpJrtEW)8G9Esmlrox=CM}Rnn*Kbk;FkCen*kJM1SYWB4 zLG;fERtOLJBw=VyWH3(N$3it8toYwyy%YoA)luaJXVasG{6+!{PO8zDsld8A4t(XE zATr<`z1DkqeQ=pqGffBRBOuXnKqPb$J7U3x*KbnX%PYjs;eAJkU;rp?TS% zc{gzOBtC?h7{W~AiIc<-CZ~!(vk^D8642{uQmJe6#B4S&nQsDYb_V-UHe+Z=wq1+%Gg(bWrfF)^R|BlYVhu+Q>9-9U()V15? z0zI8VKQ0?etpGP!P__Abi_jYP1T7|O0ZO=i`8b({!>{bjLg(H_XQ|l9luk1xJ5y?J zbj6wd?`(1A)!M7&Ki2*;q&W`4K zh>6TN{K!GGKZGO7LPj_Rv{Tp^H=kO^fx%eiz^g6lZBt{R`4vOAj zC*JFu-Nb0%ITNEP;R1o^MFfF6Lm)1wXfOA&D4yHT+rp&7C!OrXFL66N*NcSWfC6zr zMSGQYaskl~d$y%+7DQ7*#`D{vim2^p2ubR9|byGCbzbW7C-LU5dzRw3l z@%eP=hLB8u$$i>nR&iNZD4TaN@Yer#@NYU#GxgG)1MMw;&##V8$pV=4_uKjvL@&fJ zjDuor@9CmDo$GoR&36X7gKl*OyMtysgWW+hox$GYK47>W`oB07>{Q{51}?6NdfWIH Du FastAPI: app = FastAPI() app.container = Container() - app.include_router(router) + app.include_router(user_router) return app diff --git a/api/di.py b/api/di.py index 442f356..f480d03 100644 --- a/api/di.py +++ b/api/di.py @@ -1,16 +1,21 @@ import os from dependency_injector import containers, providers -from repository.user import UserRepository -from service.user import UserService -from uow.database import Database + +from api.repository.user import UserRepository +from api.service.user import UserService +from api.uow.database import Database +from api.uow.uow_base import UowBase class Container(containers.DeclarativeContainer): - wiring_config = containers.WiringConfiguration(modules=["router.user"]) + wiring_config = containers.WiringConfiguration(modules=["api.router.user"]) config = providers.Configuration(yaml_files=[f"{os.getenv('CONFIG_PATH')}"]) + if os.getenv("INDOCKER"): + config.db.host.update("db") + db = providers.Singleton( Database, db_url="postgresql+asyncpg://{}:{}@{}:{}/{}".format( @@ -23,9 +28,14 @@ class Container(containers.DeclarativeContainer): ), ) + uow = providers.Factory( + UowBase, + session_factory=db.provided.session, + ) + user_repository = providers.Factory( UserRepository, - session_factory=db.provided.session, + uow=uow, ) user_service = providers.Factory( diff --git a/api/migrations/__pycache__/env.cpython-311.pyc b/api/migrations/__pycache__/env.cpython-311.pyc new file mode 100644 index 0000000000000000000000000000000000000000..e04ea992715d67bd92d7ec7f1352af0c2a47ab6f GIT binary patch literal 3065 zcmaJ@ON$#v5bn{8q|xZLZ`-?K)3$f5l^;^<*bc@a!RtJ55*EL5un36RnO^NE^H6$5 z`!F_aAcq8U$id)KU{4!@eaK%}hmfme1}p{^48eiiWcgt~E zs;~5GGASWw@vBeB*CIlHvq8}K4)g3EVD2Insho}suE=qW59uL;FY-Rm>w*z3hK)!u z;*SMAS`@)1tj7$gC~=7Jm3ZK`7$@;cA{c!)6hegSmuzte-GisyV6Ie22BTt1jj7S^ zg<=}sBD~pbzA_x>w}8193=mC#Ha#eV{R!6)$cOfl=cIqx>>TGwOPWqDTIP~ghEY_p zOoyyFxsW$P%(7;Z(h{|d5{SXT6RMV_FMypeFWbb6P~z06sdP62OcWk=pwC_cxr-d2 zLEG$pY#?E8l^Z;W+sFy`^p)Up&@JS^#RW|bsk|y^-2L#D07n5&yK#fFyPgIQ;SAbk z7YXJM+QA`4*l#NYYrqq%p+>Hu!{{Wkh1Jj+e*>*TsN4Xb%>Ek6MdeT7Q?J%cY-nXF zJDO$MSTk|fT3XWKOtaXqRFan@4DI@|X5;qx)+n*DvrO2K-2z_KoMl|8*$$TRS69FE z?PXKNrUeocf8yWJahPJ&%F8_o29L6$kg6ju>cpS5Oen#!jaP}T=P{mN$M!c`wW^tA zf5EmVtWe_b)}OLUuxgoE2a^?IVv`URcJcB2h0B+)W8p<`w<2pgTcPtM7iC?C{aeBI z^JI-EHHXaQu)jPpG{;}9tTB(aL;d9~Ci7Rc6{=MoY}K4<&FMJ3nXEnpx^ya*m@c z;cXV^`1Q%cvSpA$ReMhE{W?h510M0#g`wmC7`oH(@kS$+I?D;5q% zo+2R68EG-{B88-3H+HBIn{i_^EyRTn`ea8;yW(_1#IA_zB5v`4!q+}!cF()Uy=i-K zuU@^{OWc#$Bk(QT$*~K0emgH*I2GMK!vR%5+HGAl`5BHB(4-GRoNhiMwAsgZ=c0a# z9*$^eFq>7bA6F_}#JC^Y0_?d5PrKa)1lsK4L?C7FLCiRVZgWn$r>}HT>lWv*Pwuq) z{NO$Sk@{!(<%*f^_P)!mTW$vJ82q!}?lsK#TX1VnYgR(uW)CiO|gdLfsf?84~~5HHS9z-}+&jkJ@$q?uYEqwMxQaiON`m%*uD zEZMGnw4m&2eW!GkabrMW#dv2$29tCWWHt*`jOjSMyz$-X?jIe+pgRkXeH!8&vOR@H zXLrQZBXRPfIQh$2ck1--iw*IdE1qknGdm*_cTTjT!YJf8kmrnSe9=lEY5Y+v^Dvfa z#HQWYbPEaL+0CPVf*;r{{`pQ_ywVV_xZ)LHo+QWI z%lURFPzD8F6e@_Zs449dA@zc;9Y}tNqyXIWtiI576FIHkD%@czf)($C#|9)6_Y0VC*LWwQ$8+ryhI#?gzPtzL_Uz%2+VLz1F zm4i(VKIGs+4?YBHgA6XDZi+(*J@wDn1s%*lAy9JYO~t)5r@mcDnTe_>OhAc1A4c*agD|hwEOpa>h%B7OFI{9V!QhSFw zGx9v6s!MZMfX(D4N)wZXQl(Iu%#|uL8rdVHcZJy9;p@^3-9d6DBKdb3U~jq=2b z1+f?M0vGKXPd^)JDWN7j^O>Km}WM1A1=&e5k4F#xl>YtIj$lN=4x}RPzHm4PNNUwc@&M(qc`oXhlYAb`g@^&^4-Vrr+hrs z#8d5^3kMU8_x5KSvkwP6JniG@CY}y=yq8D6TfF!Ax7Y7o|9R5Gb3UGH;<>idI|r<> zwST*D`yui0tdD1#coue=c;qnd%iJ| z`*`<)A3xiSpY^&Fx)y%^-@bhFO6*D9q=6n^3m|gP;NW3 z>P{wCAAY(d13PUi1CZpd4BO~Jn1{hJq3={(ZJ@O;d literal 0 HcmV?d00001 diff --git a/api/model/__pycache__/user.cpython-311.pyc b/api/model/__pycache__/user.cpython-311.pyc new file mode 100644 index 0000000000000000000000000000000000000000..a2737ef322dbd43885cd227a4e4a90b61f179bb0 GIT binary patch literal 1220 zcmah|zfaph6h8lsLsC*iGeCt>ghYc#qN=D}fPt#C421#O!HebQ4r1ybi5-IyF=Sw1 zOeG|cN+l-RivBS{$`E-%sycLYl}=23X9rh>O1=2LyzjktzVE#|e@ds52*#t@camih z`bNq15C%qn8H^)@5oQczG74j|3Ttu-XYvZqP(N!3rl^PvV$lnPxqXCrBA#&wox_ZV zB4J@2<;5SA=6PRQvTcKCmM=cD4bQZEX~n9OE#mm%dfm~jtvuuNOPWi{gBOH<{DAcL zz&Jt#DGWvmiy4Ju5#fn|*{|Fg6mkwT8j2W3B#7`gB8ez+#y~#ILB1S%laMdm$REPu zK2lOxfsWnn%ErFxk{Rqh5~pfSqKRv^o8k z0MJ}!4{d`LjStXL;Bh{14tQJ>a2|NvT;Re-nYMSeDbG_~4|TlIlxK6q)O2HEvN<|A zo2zJUgbK;bd4H`$D+RAHK1~m*Z@DJT5UdT`Dqn zRVY<#la#9Z<8sL%Rl5WlcJwk)P0cE4RlQ`|m>4D6tYWp{CsY-(993UT1Jp*Ti!aaa5 z$jMTBlmb2C5a<%O2GELsz0vX3t4n$KAlsHsH#+jng*?-hXIe|W)X2ed`^o84CpCSM zn(n5iThDvh`|Zu+H}9=OtF_k4WZPnU_cPzg6fQD_Zl=&$33yRR2Iw|KYN(J^xUosM zW@tvaLd-^_`%h_9qMw0-Dth*A5o^!@`1TwL+)*9l)QW4nO3X*iTXZHMK<|KS0|Xqy hFg^6N^S|d3J?Q-X1mYbAYPbytb3du~*FQp`px+!2CzJpH literal 0 HcmV?d00001 diff --git a/api/model/user.py b/api/model/user.py index f4b0a50..045ea8a 100644 --- a/api/model/user.py +++ b/api/model/user.py @@ -1,6 +1,6 @@ from sqlalchemy import Boolean, Column, Integer, String -from .database import Base +from api.uow.database import Base class User(Base): diff --git a/api/repository/__pycache__/__init__.cpython-311.pyc b/api/repository/__pycache__/__init__.cpython-311.pyc new file mode 100644 index 0000000000000000000000000000000000000000..05f6a27709bb4ab4e031893f53942ba9c8c3fe72 GIT binary patch literal 163 zcmZ3^%ge<81l&PSQ$h4&5CH>>P{wCAAY(d13PUi1CZpder~FM zL8fuCeo<;czJ76PQCVhkYJ6^Do_=CMCRngIvn0Q$Qa?UEGcU6wK3=b&@)w6qZhlH> ePO4oIE6^B_MaBF;;sY}yBjX1K7*WIw6axS|wNIcbx@9n11q|WU7&HLE*G4IWXa(NDL{qBBKM|gfE;dJpa zGrEq<03=8jLCk!{z<^bdMjxcPX8;@^70WjyUjx_rL88mDbL+|Gogh_>u{}Q~ahFjX zfC8UMKu@MjX-IQ}OWx-`msTHqOPUzZ&MvN}Nx;8=l659wvSn zHk62irWdrrTv=4%b5BKD~n#7c;4PKY>>orw5(AzpNXsIX|7ot`J4V)h~TEvlm?Y66aw-b2`)?4iM| zrFW}Cz~dv&k6EypRU_Rj6d5RP-8HjIIO7_=E+X*+-)>P+o_i7h`CHFP=~i)v+uA_` gwK2VqFf None: - self.session_factory = session_factory + def __init__(self, uow: UowBase) -> None: + self.uow = uow - def get_all(self): - with self.session_factory() as session: - return session.query(User).all() - - def get_by_id(self, user_id: int) -> User: - with self.session_factory() as session: - user = session.query(User).filter(User.id == user_id).first() - if not user: - raise UserNotFoundError(user_id) - return user - - def add(self, email: str, password: str, is_active: bool = True) -> User: - with self.session_factory() as session: - user = User(email=email, hashed_password=password, is_active=is_active) - session.add(user) - session.commit() - session.refresh(user) - return user - - def delete_by_id(self, user_id: int) -> None: - with self.session_factory() as session: - entity: User = session.query(User).filter(User.id == user_id).first() - if not entity: - raise UserNotFoundError(user_id) - session.delete(entity) - session.commit() - - -class NotFoundError(Exception): - entity_name: str - - def __init__(self, entity_id): - super().__init__(f"{self.entity_name} not found, id: {entity_id}") - - -class UserNotFoundError(NotFoundError): - entity_name: str = "User" + async def get_all_users(self): + return await self.uow.get_all_users() diff --git a/api/router/__pycache__/__init__.cpython-311.pyc b/api/router/__pycache__/__init__.cpython-311.pyc new file mode 100644 index 0000000000000000000000000000000000000000..399db48a609f9cb10a16814e415713476b859236 GIT binary patch literal 159 zcmZ3^%ge<81l&PSQ$h4&5CH>>P{wCAAY(d13PUi1CZpd&ryk0@&FAkgB{FKt1 dRJ$Tppb;QTiur-W2WCb_#t#fIqKFwN1^{)`BxC>p literal 0 HcmV?d00001 diff --git a/api/router/__pycache__/user.cpython-311.pyc b/api/router/__pycache__/user.cpython-311.pyc new file mode 100644 index 0000000000000000000000000000000000000000..fc4e08500f527b923e3653c4254efedd5b7d06a5 GIT binary patch literal 1179 zcmZ`%&1(}u6rb7M>}K;(O|+FJRdUjX+N>aW5D`StmO?F-de}<{nW=8sk1)Hbw0bDE zXax`6dhMwyy?FBPNF-p`Q$PegxsqE?zL_-DZR_m3xAS}R=J(#bH}A9A6oRqje5ao= zLf<$T4)t)+&%n+OB8XrcIoQOGWJ;K0$(9|(RGfsF5LmWVM>93CR_vssn>t1kqRJjn z?GJg8nWCxP^b!1LK@xiqYae7Vs061I6jN;_GqjBl7bxz#jEPG1Wr=88iFmv?GPD1U zo{TdReG45sJ3>;6sGR=Eb0|xpw!pkqi_lQD+!b06z@*<2Ns`)D;-pfr=CNNhIPGeFxv2p!)&Tf z%{6Kb%V6SOBH>D7ZNMecwkxB$-fHf2YeeSN}>Fvueqr&xv6$;x|5r3rB6&{ zx)1(nT{HZk7Bu}jN5jGIE`#(rF}y)cBn!h`x zSnHLp>}nshPkQIt{m$frc4?+lnu%l?S0V(eo4@!M2+MC7NVdlKZwx3Rg}Y{k#ItP- V*0D&!cp^fexZj1CMVLif{s3_S4MqR} literal 0 HcmV?d00001 diff --git a/api/router/user.py b/api/router/user.py index f1eda84..f233579 100644 --- a/api/router/user.py +++ b/api/router/user.py @@ -1,53 +1,18 @@ from dependency_injector.wiring import Provide, inject -from fastapi import APIRouter, Depends, Response, status +from fastapi import APIRouter, Depends -from ..di import Container -from ..repository.user import NotFoundError -from ..service.user import UserService +from api.di import Container +from api.service.user import UserService router = APIRouter() @router.get("/users") @inject -def get_list( +async def get_user_list( user_service: UserService = Depends(Provide[Container.user_service]), ): - return user_service.get_users() - - -@router.get("/users/{user_id}") -@inject -def get_by_id( - user_id: int, - user_service: UserService = Depends(Provide[Container.user_service]), -): - try: - return user_service.get_user_by_id(user_id) - except NotFoundError: - return Response(status_code=status.HTTP_404_NOT_FOUND) - - -@router.post("/users", status_code=status.HTTP_201_CREATED) -@inject -def add( - user_service: UserService = Depends(Provide[Container.user_service]), -): - return user_service.create_user() - - -@router.delete("/users/{user_id}", status_code=status.HTTP_204_NO_CONTENT) -@inject -def remove( - user_id: int, - user_service: UserService = Depends(Provide[Container.user_service]), -): - try: - user_service.delete_user_by_id(user_id) # type: ignore - except NotFoundError: - return Response(status_code=status.HTTP_404_NOT_FOUND) - else: - return Response(status_code=status.HTTP_204_NO_CONTENT) + return await user_service.get_all_users() @router.get("/status") diff --git a/api/service/__pycache__/__init__.cpython-311.pyc b/api/service/__pycache__/__init__.cpython-311.pyc new file mode 100644 index 0000000000000000000000000000000000000000..86db8f4c40e3024e5815483adaf104bc6b5ede69 GIT binary patch literal 160 zcmZ3^%ge<81l&PSQ$h4&5CH>>P{wCAAY(d13PUi1CZpd!7fq|%%PV(xO=b=BjQ064?+%xdWeT%%}h12$;R2llA1%I zLHq`}da9Ow0r68r2^jV&g5DzW)RXV+Hru3icIG$l&%XD5^JYHga?60@OZTTNGJqeX z%!Y9$OmCww00Dye&|p=@NY;F02uCe>z9ekYXb ziEIU7y&b47T9$T#z58A$YiAMhmR8+DbpR5oOh8o=OzJ`t`mQ02zCpSBP&I{46`~bN zU6JZdy(Xiz4k}!wg`$j-?T%`eYbiC%OtOw^x)GP@u^w=gk|Cf1$E<8KwS)#+i;PhE zyRi~dV4-m8x-WxB_zXJ*Y{ z+Hf7=0LC|*_r@rDeHhOv+MtGalMZ5Vh->-);W04mQV(9G?ho_-rq&~rPEzd`iFk-DSV3n None: - self._repository: UserRepository = user_repository + self.user_repository = user_repository - def get_users(self): - return self._repository.get_all() - - def get_user_by_id(self, user_id: int) -> User: - return self._repository.get_by_id(user_id) - - async def create_user(self) -> User: - uid = uuid4() - return await self._repository.add(email=f"{uid}@email.com", password="pwd") - - async def delete_user_by_id(self, user_id: int) -> None: - return await self._repository.delete_by_id(user_id) + async def get_all_users(self): + return await self.user_repository.get_all_users() diff --git a/api/uow/__pycache__/__init__.cpython-311.pyc b/api/uow/__pycache__/__init__.cpython-311.pyc new file mode 100644 index 0000000000000000000000000000000000000000..70b43619fcaa87b5ec4a0c4bc92fb1431d332e89 GIT binary patch literal 156 zcmZ3^%ge<81l&PSQ$h4&5CH>>P{wCAAY(d13PUi1CZpdNVY%lbV=4{ys}uit0%VI&~ZvkP9I@c|eZx`4hwj663);b74d+JGvWGBC;HPZB?uVLgN7|T&dW0qV!Xx-YJ)GtlhOd&zkcHxaz&b zKA9z9=mwRzpF1$aMD(qP%&AR@6%jM(B9#TVLcmGhA+~2xD{>zbbIuBxPEGyT>AZQ> z;_x1b+lU|oJID|mOhiX;#Cge)HY7tLvLkPxE=Cl_hM_ttpyp_R87BjnbwuDJ8*86g zk;Mj&6=%*|qF$^}5-rinjNKv+MwOw6P);H~g$P5HrZw!~=RzmlYshR_MC{w9EqZXO zSDIRc9Pzod3;v(6F?a$G&1J&|fvL(f-vB=nu@{5SOG2ywbzx}6d9qw}DKUeJX$QXV zMkSeMz(cH>3DHyoiKe_IP=M(UN>=tz(u*vd( z+=Rw9T0=WfpG}>+VHWM-nG&Y&fZ-mdgHVOcX^|EHV>R8itNGSCQVqAf3^wcNC^zsT zH-3;C-_K3fbCWe~k`6&f$K;sLCs0n&ne1fxxUITFt(RZP0A2(~77J*|(fx>~- z(5K3)%)STUFZiva!`#4T&)Gp4BR@hpc?!@R^Z~S!wA0RBQ`vP|p1@Z7LHrhNi%%sC zoVI=4ei$zFHQTg&!6lIn!xyne1J9eY?1!;zdjXtwfd?R#EV>Y;n=gq&hAn-W@2LI` zI=GHG3-1G@Z0P-4-V1%~Kp)%JC+hk{O*pgCcJfW`9}LB3D9l&0T{9yD*OYWA!3Yy6Z{^m@ZxZUuGKnoL&ErD=HtR} qgg&Zu=0h}E>&!=Lp{5r0)uFmNv@SK2D;R=s7LJ+j^*J3pME?NkxlMZj literal 0 HcmV?d00001 diff --git a/api/uow/__pycache__/uow_base.cpython-311.pyc b/api/uow/__pycache__/uow_base.cpython-311.pyc new file mode 100644 index 0000000000000000000000000000000000000000..1380165a961f0f41a99e9c53dce0f0f36f55fa8a GIT binary patch literal 1844 zcmah}-D?|15TCtINtSFUitNy0>ei%250OZlhY(CbHl>uNelaQJpd9DBjdRI;$a|;Q zN)<5J1V8kl2?jx-peL8$KcP?UU!asg#X%uZ3eB5>@?i4R*^^H3)xq7Jo%`*~?A+|^ z?EYLR(UDwPlVdD7imPgB zjAbX|X0@!F({k}#aVFfnmXERO6x>N|l7IkTfR)(;D|?6$9N`!?ZOY26L3!dOpO#59 zQ(F&0W|-lM?}cMcBi@m5LH9C=Q29%kjIO0zd)nFc{ZJ?kL3p61MS+HbF+>(upbrd0PK*Fuuj;2Ne z{Whk-XU%{+nxB7Dt={onTCLlknpH;Yeig&NZ<|zi4Xp#``CCuM=OC2WhgU<+@@EzAY4@ikyPk!6KV zFVPf2RHUV@6BFpH=i^+ zrDwB?&u16A=l)Ck%e`W$ef`Px$4duGe-syfFD^VQUV2`<)K^dc=@tL`>;Dho>;TW! z9v>f{Z4jKty!=or)vk%ZUdt^D>TfbZUKSXy`PH(_uZ3s0RM(@NuDia~a5&EE`ews$ zh8o7NESp326j+I4o^6&-7zaTO+0MB41xa4)E0CM)s~ka^dI6tw)6|2xZkl?q(tQ{8;G=GuUcd+4H1(AU Rf|) None: self._engine = create_async_engine(db_url, echo=True) - self._async_session = async_sessionmaker( + self._session_factory = async_sessionmaker( self._engine, class_=AsyncSession, expire_on_commit=False, ) + @property + def session(self): + return self._session_factory() + async def __aenter__(self): - async with self._async_session() as session: - self.session = session - return self + return self async def __aexit__(self, *args): await self.session.rollback() diff --git a/api/uow/uow_base.py b/api/uow/uow_base.py new file mode 100644 index 0000000..ec93aae --- /dev/null +++ b/api/uow/uow_base.py @@ -0,0 +1,23 @@ +from contextlib import AbstractContextManager +from typing import Iterable + +from dependency_injector.providers import Callable +from sqlalchemy import select +from sqlalchemy.ext.asyncio import AsyncSession, async_sessionmaker +from sqlalchemy.orm import Session + +from api.model.user import User + + +class UowBase: + def __init__( + self, + session_factory, + ) -> None: + self.session = session_factory + + async def get_all_users(self): + async with self.session as s: + query = select(User) + rr = await s.execute(query) + return rr.scalars().all() diff --git a/manage.py b/manage.py new file mode 100644 index 0000000..1f78bf2 --- /dev/null +++ b/manage.py @@ -0,0 +1,11 @@ +if __name__ == "__main__": + import uvicorn + + uvicorn.run( + app="api.app:create_app", + host="0.0.0.0", + port=8000, + reload=True, + factory=True, + workers=1, + )