Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feedback #1

Open
wants to merge 3 commits into
base: feedback
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
name: Bug report
about: If something isn't working 🔧
title: "[BUG]"
labels: bug
assignees:
---

## Describe the bug
<!-- 명확하고 간결하게 버그 설명 -->

## To Reproduce
<!-- 어떤 상황에서 발생했는지에 대한 상황 설명 -->

## Additional context
<!-- Add any other context about the problem here. -->
14 changes: 14 additions & 0 deletions .github/ISSUE_TEMPLATE/experiment.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
name: Experiment
about: "Conducting experiments related to other models"
title: "[EXP]"
labels: ''
assignees: ''

---

## Background
<!-- 어떤 모델을 사용하는지, 어떤 방식으로 실험을 진행하는지 -->

## To Do
- [ ]
15 changes: 15 additions & 0 deletions .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
name: 🚀 Feature request
about: Suggest an idea for this project 🏖
title: "[FEAT] "
labels: enhancement
assignees:
---

## Background
<!-- 해당 기능이 필요한 이유 -->

## To do
<!-- 해당 기능을 만들기 위해 할 것 -->

- [ ]
8 changes: 8 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
## Description

<!-- Add a more detailed description of the changes if needed. -->

## Related Issue

<!-- If your PR refers to a related issue, link it here. -->
<!-- 해당 리퀘스트에 관련된 이슈를 달아주세요. -->
144 changes: 144 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/ㅎ
var/
wheels/
pip-wheel-metadata/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
.python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# PEP 582; used by e.g. github.com/David-OConnor/pyflow
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# custom
.vscode/
.idea/
.DS_Store
test.ipynb

config.yaml
yesi.py

/uploads
/tts_data

*.wav

15 changes: 15 additions & 0 deletions .gitmessage
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Title: Summary, imperative, start upper case, don't end with a period
# No more than 50 chars. #### 50 chars is here: #

# Remember blank line between title and body.

# Body: Explain *what* and *why* (not *how*). Include task ID (Jira issue).
# Wrap at 72 chars. ################################## which is here: #

# feat : 기능 (새로운 기능)
# fix : 버그 (버그 수정)
# refactor: 리팩토링
# style : 스타일 (코드 형식, 세미콜론 추가: 비즈니스 로직에 변경 없음)
# docs : 문서 (문서 추가, 수정, 삭제)
# test : 테스트 (테스트 코드 추가, 수정, 삭제: 비즈니스 로직에 변경 없음)
# chore : 기타 변경사항 (빌드 스크립트 수정 등)
90 changes: 90 additions & 0 deletions Backend/auth_router.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import requests
from database.connection import get_db
from database.orm import User
from database.repository import create_update_user, get_user_by_email
from fastapi import APIRouter, Depends, HTTPException, Request, status
from fastapi.responses import RedirectResponse
from oauth import oauth # main.py 혹은 app의 설정을 import 해야 합니다.
from pydantic import BaseModel
from sqlalchemy.orm import Session

router = APIRouter()


class TokenData(BaseModel):
token: str


@router.get("/login")
async def login(request: Request):
# 구글 로그인 페이지로 리다이렉트
redirect_uri = request.url_for("auth")
return await oauth.google.authorize_redirect(request, redirect_uri)


@router.route("/auth")
async def auth(request: Request, session: Session = next(get_db())):
# OAuth 로그인 콜백. 사용자를 체크하는 get_or_create_user 함수 실행
try:
token = await oauth.google.authorize_access_token(request)
except Exception as e:
raise HTTPException(status_code=status.HTTP_400_BAD_REQUEST, detail=str(e))

userinfo = token.get("userinfo")
if not userinfo:
raise HTTPException(
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
detail="Token has no information",
)

user_email = userinfo.get("email")
if not user_email:
raise HTTPException(
status_code=status.HTTP_400_BAD_REQUEST, detail="Token has no information"
)

find_create_user(session, userinfo)
request.session["user_info"] = userinfo # 사용자 정보를 세션에 저장

return RedirectResponse(url="/session", status_code=status.HTTP_303_SEE_OTHER)


def find_create_user(session: Session, userinfo: dict) -> User:
# 이메일로 검색 후 사용자가 존재하지 않으면 생성 후 반환. 사용자가 존재하면 바로 반환
user_email = userinfo["email"]
user = get_user_by_email(session, email=user_email)

if not user:
user = User.create(request=userinfo)
create_update_user(session, user)

return user


def authorize_token(token: TokenData) -> User:
# 토큰으로 유저 검증
google_userinfo_url = "https://www.googleapis.com/oauth2/v3/userinfo"
headers = {"Authorization": f"Bearer {token}"}
response = requests.get(google_userinfo_url, headers=headers)

if response.status_code == 200:
user_info = response.json()
print(user_info)

return user_info


def get_authorized_user(request: Request, session: Session = Depends(get_db)) -> User:
user_info = authorize_token(token=request.headers.get("Access-Token"))
user = get_user_by_email(session=session, email=user_info["email"])
if not user:
raise HTTPException(status_code=404, detail="User not found")
return user


@router.get("/me")
async def get_user_info(request: Request, session: Session = Depends(get_db)) -> dict:
# 유저 정보를 받아와서 닉네임과 streak 반환
user = get_authorized_user(request=request, session=session)

return {"name": user.name, "streak": user.streak}
28 changes: 28 additions & 0 deletions Backend/database/-- CREATE TABLE USERS.pgsql
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
-- CREATE TABLE USERS
-- (
-- ID SERIAL PRIMARY KEY,
-- NAME VARCHAR(50) UNIQUE NOT NULL,
-- EMAIL VARCHAR(50) UNIQUE NOT NULL,
-- IS_DONE BOOLEAN NOT NULL,
-- STREAK INTEGER NOT NULL);

-- DROP TABLE USERS

-- CREATE TABLE tests (
-- id SERIAL PRIMARY KEY,
-- user_id INTEGER NOT NULL,
-- path VARCHAR NOT NULL,
-- inference1 JSONB,
-- inference2 FLOAT NOT NULL,
-- inference3 JSONB,
-- q_num INTEGER NOT NULL,
-- createdDate DATE NOT NULL
-- );

-- CREATE TABLE questions (
-- id SERIAL PRIMARY KEY,
-- date DATE UNIQUE NOT NULL,
-- q1 VARCHAR NOT NULL,
-- q2 VARCHAR NOT NULL,
-- q3 VARCHAR NOT NULL
-- );
26 changes: 26 additions & 0 deletions Backend/database/connection.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import yaml
from sqlalchemy import create_engine, select
from sqlalchemy.orm import sessionmaker


def load_config(filename):
with open(filename, "r") as config_file:
config = yaml.safe_load(config_file)
return config


config = load_config("../config.yaml")
db_config = config.get("database")

DATABASE_URL = db_config.get("dbname")

engine = create_engine(DATABASE_URL, echo=True)
SessionFactory = sessionmaker(autocommit=False, autoflush=False, bind=engine)


def get_db():
session = SessionFactory()
try:
yield session
finally:
session.close()
Loading