Skip to content

Commit

Permalink
Feat : Add main.py
Browse files Browse the repository at this point in the history
- #4
  • Loading branch information
taeyang916 committed Feb 25, 2024
1 parent c9e742e commit 78777fc
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 6 deletions.
11 changes: 11 additions & 0 deletions backend/database.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from sqlalchemy.ext.declarative import declarative_base

URL_DATABASE = ''

engine = create_engine(URL_DATABASE)

SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)

Base = declarative_base()
62 changes: 56 additions & 6 deletions main.py → backend/main.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,52 @@
from fastapi import FastAPI, HTTPException
from fastapi import FastAPI, HTTPException, Depends, status
from fastapi.staticfiles import StaticFiles
from fastapi.responses import HTMLResponse
from pydantic import BaseModel, Field
from datetime import datetime
from databases import Database
from passlib.context import CryptContext
from typing import Optional
from typing import Optional, Annotated
import os

import models
from database import engine, SessionLocal
from sqlalchemy.orm import Session

app = FastAPI()
models.Base.metadata.create_all(bind=engine)

class UserBase(BaseModel):
email: str
password: str
age: int
gender: bool
updated_at: Optional[datetime]

class RequestBase(BaseModel):
user_id: int
age: int
gender: bool
voice: str
status: int
eta: Optional[datetime]
updated_at: Optional[datetime]

class ResultBase(BaseModel):
request_id: int
condition_image_url: Optional[str]
condition_gif_url: Optional[str]
voice_image_url: Optional[str]
voice_gif_url: Optional[str]
condition_image_rating: Optional[int]
condition_gif_rating: Optional[int]
voice_image_rating: Optional[int]
voice_gif_rating: Optional[int]
condition_image_score: Optional[float]
condition_gif_score: Optional[float]
voice_image_score: Optional[float]
voice_gif_score: Optional[float]
updated_at: Optional[datetime]


DATABASE_URL = "mysql://root:1234@localhost/MZ"
database = Database(DATABASE_URL)
Expand All @@ -20,12 +59,23 @@
def hash_password(password: str):
return pwd_context.hash(password)

# class User(BaseModel):
# email: str = Field(..., example="[email protected]")
# password: str = Field(..., example="password")
# gender: Optional[str] = Field(None, example="Man")
# age: Optional[int] = Field(None, example=30)
# image_path: Optional[str] = Field(None, example="../src/output/image.jpg")

class User(BaseModel):
email: str = Field(..., example="[email protected]")
password: str = Field(..., example="password")
gender: Optional[str] = Field(None, example="Man")
age: Optional[int] = Field(None, example=30)
image_path: Optional[str] = Field(None, example="../src/output/image.jpg")
password: str = Field(..., example="example123")
age: int = Field(..., example=25)
gender: int = Field(..., example=0) # 0: man, 1: woman
created_at: Optional[datetime] = None
updated_at: Optional[datetime] = None
deleted_at: Optional[datetime] = None



@app.on_event("startup")
async def startup():
Expand Down

0 comments on commit 78777fc

Please sign in to comment.