Skip to content

Commit

Permalink
Build initial structure
Browse files Browse the repository at this point in the history
๋Œ€๋žต์ ์ธ ํด๋”๊ตฌ์กฐ๋ฅผ ์ƒ์„ฑํ•˜์˜€์Šต๋‹ˆ๋‹ค.
  • Loading branch information
ehddnr301 committed Aug 28, 2021
1 parent eb3d43a commit b1e0a48
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 9 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.env
12 changes: 3 additions & 9 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
repos:

- repo: https://github.com/psf/black
rev: '21.7b0'
hooks:
- id: black

- repo: https://github.com/PyCQA/flake8
rev: 3.9.2
hooks:
- id: flake8

- repo: https://github.com/PyCQA/pydocstyle
rev: 6.1.1
hooks:
- id: pydocstyle



Empty file added app/__init__.py
Empty file.
31 changes: 31 additions & 0 deletions app/database.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import os

from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from sqlalchemy.ext.declarative import declarative_base

from dotenv import load_dotenv


def connect(db):

load_dotenv(verbose=True)

POSTGRES_USER = os.getenv("POSTGRES_USER")
POSTGRES_PASSWORD = os.getenv("POSTGRES_PASSWORD")
POSTGRES_PORT = os.getenv("POSTGRES_PORT")
POSTGRES_SERVER = os.getenv("POSTGRES_SERVER")
POSTGRES_DB = db
SQLALCHEMY_DATABASE_URL = f"postgresql://{POSTGRES_USER}:{POSTGRES_PASSWORD}\
@{POSTGRES_SERVER}:{POSTGRES_PORT}/{POSTGRES_DB}"

connection = create_engine(SQLALCHEMY_DATABASE_URL)

return connection


POSTGRES_DB = os.getenv("POSTGRES_DB")

engine = connect(POSTGRES_DB)
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
Base = declarative_base()
Empty file added app/router/__init__.py
Empty file.
12 changes: 12 additions & 0 deletions app/router/predict.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from fastapi import APIRouter

router = APIRouter(
prefix="/predict",
tags=["predict"],
responses={404: {"description": "Not Found"}}
)


@router.get("/")
def hello_world():
return {"message": "Hello predict"}
21 changes: 21 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from fastapi import FastAPI

from app.router import predict
from app.database import SessionLocal

app = FastAPI()

app.include_router(predict.router)


def get_db():
db = SessionLocal()
try:
yield db
finally:
db.close()


@app.get("/")
def hello_world():
return {"message": "Hello World"}

0 comments on commit b1e0a48

Please sign in to comment.