first commit
This commit is contained in:
commit
f66fd0e2aa
3
.idea/.gitignore
generated
vendored
Normal file
3
.idea/.gitignore
generated
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
6
.idea/inspectionProfiles/profiles_settings.xml
generated
Normal file
6
.idea/inspectionProfiles/profiles_settings.xml
generated
Normal file
@ -0,0 +1,6 @@
|
||||
<component name="InspectionProjectProfileManager">
|
||||
<settings>
|
||||
<option name="USE_PROJECT_PROFILE" value="false" />
|
||||
<version value="1.0" />
|
||||
</settings>
|
||||
</component>
|
||||
7
.idea/misc.xml
generated
Normal file
7
.idea/misc.xml
generated
Normal file
@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="Black">
|
||||
<option name="sdkName" value="Python 3.13" />
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.13" project-jdk-type="Python SDK" />
|
||||
</project>
|
||||
8
.idea/modules.xml
generated
Normal file
8
.idea/modules.xml
generated
Normal file
@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/.idea/programador3.iml" filepath="$PROJECT_DIR$/.idea/programador3.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
||||
8
.idea/programador3.iml
generated
Normal file
8
.idea/programador3.iml
generated
Normal file
@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="PYTHON_MODULE" version="4">
|
||||
<component name="NewModuleRootManager">
|
||||
<content url="file://$MODULE_DIR$" />
|
||||
<orderEntry type="jdk" jdkName="Python 3.13" jdkType="Python SDK" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
||||
6
.idea/vcs.xml
generated
Normal file
6
.idea/vcs.xml
generated
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
||||
21
core/domain/user.py
Normal file
21
core/domain/user.py
Normal file
@ -0,0 +1,21 @@
|
||||
from sqlalchemy import Column, Integer, String
|
||||
|
||||
class User(Base):
|
||||
__tablename__ = 'usuario'
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
username = Column(String(20))
|
||||
nombre = Column(String(20))
|
||||
rol = Column(String(20))
|
||||
|
||||
class Config:
|
||||
orm_mode = True
|
||||
|
||||
class Producto(Base):
|
||||
__tablename__ = 'producto'
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
price = Column(float())
|
||||
nombre = Column(String(20))
|
||||
rol = Column(String(20))
|
||||
|
||||
class Config:
|
||||
orm_mode = True
|
||||
8
infrastructure/adapters/contracts/product.py
Normal file
8
infrastructure/adapters/contracts/product.py
Normal file
@ -0,0 +1,8 @@
|
||||
from pydantic import BaseModel
|
||||
|
||||
class Producto(BaseModel):
|
||||
id: int
|
||||
username: str
|
||||
nombre: str
|
||||
rol: str
|
||||
|
||||
8
infrastructure/adapters/contracts/user.py
Normal file
8
infrastructure/adapters/contracts/user.py
Normal file
@ -0,0 +1,8 @@
|
||||
from pydantic import BaseModel
|
||||
|
||||
class User(BaseModel):
|
||||
id: int
|
||||
username: str
|
||||
nombre: str
|
||||
rol: str
|
||||
|
||||
28
infrastructure/dependencies/dependencies.py
Normal file
28
infrastructure/dependencies/dependencies.py
Normal file
@ -0,0 +1,28 @@
|
||||
import os
|
||||
|
||||
from sqlalchemy import create_engine
|
||||
from sqlalchemy.orm import sessionmaker, Session
|
||||
from typing import Generator
|
||||
from fastapi import Depends
|
||||
|
||||
DB_DATABASE = os.getenv('DB_DATABASE')
|
||||
DB_USER = os.getenv('DB_USER')
|
||||
DB_PASSWORD = os.getenv('DB_PASSWORD')
|
||||
DB_NAME = os.getenv('DB_NAME')
|
||||
DB_HOST = os.getenv('DB_HOST')
|
||||
DB_PORT = os.getenv('DB_PORT')
|
||||
DATABASE = os.getenv('DATABASE')
|
||||
|
||||
|
||||
engine = create_engine(f'postgresql+psycopg2://{DB_NAME}:{DB_PASSWORD}@{DB_HOST}:{DB_PORT}/{DATABASE}')
|
||||
SessionLocal = sessionmaker(autocommit = False, autoflush=False, bind = engine)
|
||||
|
||||
def getDb() -> Generator[Session, None, None]:
|
||||
db: Session = SessionLocal
|
||||
try:
|
||||
yield db
|
||||
finally:
|
||||
db.close()
|
||||
|
||||
def get_user_repo(db = Depends(getDb())):
|
||||
return SQLUserRepository()
|
||||
17
infrastructure/entrypoints/routes/routes.py
Normal file
17
infrastructure/entrypoints/routes/routes.py
Normal file
@ -0,0 +1,17 @@
|
||||
from fastapi import APIRouter, FastAPI
|
||||
from infrastructure.adapters.contracts.user import User
|
||||
from infrastructure.adapters.contracts.product import Producto
|
||||
from core.domain.user import User
|
||||
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
|
||||
@router.get("/users/", response_model = User)
|
||||
async def read_users():
|
||||
|
||||
return [{"username": "Rick"}, {"username": "Morty"}]
|
||||
|
||||
@router.get("/users/", response_model = Producto)
|
||||
async def read_users():
|
||||
return [{"username": "Rick"}, {"username": "Morty"}]
|
||||
8
requirements.txt
Normal file
8
requirements.txt
Normal file
@ -0,0 +1,8 @@
|
||||
psycopg[binary] == 3.2.6
|
||||
SQLAlchemy == 2.0.39
|
||||
pydantic == 2.10.6
|
||||
fastapi == 0.115.12
|
||||
uvicorn == 0.34.0
|
||||
alembic == 1.15.1
|
||||
python-jose == 3.4.0
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user