Updated the API to use Core
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
"1" : "uviconrn",
|
||||
"2" : "fastapi",
|
||||
"3" : "pydantic",
|
||||
"4" : "sqlalchemy"
|
||||
"4" : "pydantic-settings",
|
||||
"5" : "sqlalchemy"
|
||||
}
|
||||
}
|
||||
7
src/.env
Normal file
7
src/.env
Normal file
@@ -0,0 +1,7 @@
|
||||
DATABASE_URL=sqlite:///./users.db
|
||||
API_TITLE=Users Microservice
|
||||
API_VERSION=1.0.0
|
||||
HOST=0.0.0.0
|
||||
PORT=8000
|
||||
RELOAD=true
|
||||
LOG_LEVEL=info
|
||||
3
src/__init__.py
Normal file
3
src/__init__.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from core.config import settings
|
||||
|
||||
__all__ = ["settings"]
|
||||
Binary file not shown.
BIN
src/core/__pycache__/config.cpython-314.pyc
Normal file
BIN
src/core/__pycache__/config.cpython-314.pyc
Normal file
Binary file not shown.
29
src/core/config.py
Normal file
29
src/core/config.py
Normal file
@@ -0,0 +1,29 @@
|
||||
from pydantic_settings import BaseSettings
|
||||
from pydantic import Field
|
||||
|
||||
class Settings(BaseSettings):
|
||||
"""Configuración de la aplicación"""
|
||||
|
||||
# Base de datos
|
||||
database_url: str = Field(
|
||||
default="sqlite:///./test.db",
|
||||
description="URL de conexión a la base de datos"
|
||||
)
|
||||
|
||||
# API
|
||||
api_title: str = "Users Microservice"
|
||||
api_version: str = "1.0.0"
|
||||
api_description: str = "Microservicio de gestión de usuarios"
|
||||
|
||||
# Server
|
||||
host: str = "0.0.0.0"
|
||||
port: int = 8000
|
||||
reload: bool = True
|
||||
log_level: str = "info"
|
||||
|
||||
class Config:
|
||||
env_file = ".env"
|
||||
case_sensitive = False
|
||||
|
||||
|
||||
ConfSettings = Settings()
|
||||
Binary file not shown.
@@ -1,11 +1,12 @@
|
||||
from sqlalchemy import create_engine
|
||||
from sqlalchemy.orm import sessionmaker, declarative_base
|
||||
from core.config import ConfSettings
|
||||
|
||||
DATABASE_URL = "sqlite:///./users.db"
|
||||
|
||||
engine = create_engine(
|
||||
DATABASE_URL,
|
||||
connect_args={"check_same_thread": False}
|
||||
ConfSettings.database_url,
|
||||
connect_args={"check_same_thread": False} if "sqlite" in ConfSettings.database_url else {}
|
||||
)
|
||||
|
||||
SessionLocal = sessionmaker(
|
||||
|
||||
Binary file not shown.
Binary file not shown.
@@ -1,7 +1,10 @@
|
||||
from fastapi import FastAPI
|
||||
from core.config import ConfSettings
|
||||
from infrastructure.api.users.router import router
|
||||
|
||||
def create_app() -> FastAPI:
|
||||
app = FastAPI(title="Users service")
|
||||
app = FastAPI(title=ConfSettings.api_title,
|
||||
version=ConfSettings.api_version,
|
||||
description=ConfSettings.api_description)
|
||||
app.include_router(router)
|
||||
return app
|
||||
@@ -1,10 +1,16 @@
|
||||
from fastapi import APIRouter
|
||||
import platform
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
@router.get("/")
|
||||
def root():
|
||||
uname = platform.uname()
|
||||
return {
|
||||
"machine": {
|
||||
"OS" : f"{uname.system} {uname.release}",
|
||||
"Arch": uname.machine
|
||||
},
|
||||
"Status": "Running",
|
||||
"Docs": "/docs"
|
||||
}
|
||||
11
src/main.py
11
src/main.py
@@ -1,4 +1,5 @@
|
||||
from infrastructure.api.users.app import create_app
|
||||
from core.config import ConfSettings
|
||||
|
||||
app = create_app()
|
||||
|
||||
@@ -6,11 +7,11 @@ def run():
|
||||
import uvicorn
|
||||
uvicorn.run(
|
||||
"main:app",
|
||||
host="0.0.0.0",
|
||||
port=8000,
|
||||
reload=True,
|
||||
log_level="info",
|
||||
host=ConfSettings.host,
|
||||
port=ConfSettings.port,
|
||||
reload=ConfSettings.reload,
|
||||
log_level=ConfSettings.log_level,
|
||||
)
|
||||
|
||||
if __name__ == "__main__":
|
||||
run()
|
||||
run()
|
||||
BIN
src/users.db
BIN
src/users.db
Binary file not shown.
Reference in New Issue
Block a user