Skip to content

Commit

Permalink
Merge pull request #95 from kucc/exp
Browse files Browse the repository at this point in the history
Merge Exp to Main
  • Loading branch information
smreosms13 authored Nov 27, 2024
2 parents 731a046 + 4b18a56 commit 40c3f8e
Show file tree
Hide file tree
Showing 31 changed files with 1,127 additions and 171 deletions.
31 changes: 22 additions & 9 deletions src/dependencies.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from datetime import date

from fastapi import Depends, Header, HTTPException, status
from jose import jwt
from jose import ExpiredSignatureError, JWTError, jwt
from sqlalchemy import select
from sqlalchemy.orm import Session

from config import Settings
Expand All @@ -23,14 +24,26 @@ async def get_current_user(token=Header(None), db: Session = Depends(get_db)):
detail="Invalid credentials",
headers={"WWW-Authenticate": "Bearer"},
)
payload = jwt.decode(token, key=Settings().JWT_SECRET_KEY, algorithms=Settings().JWT_ALGORITHM)
user_id: int = int(payload.get("sub"))
if user_id is None:
raise credentials_exception
user = db.query(User).filter(User.id == user_id).first()
if user is None:
raise credentials_exception
return user
try:
payload = jwt.decode(token, key=Settings().JWT_SECRET_KEY, algorithms=Settings().JWT_ALGORITHM)
user_id: int = int(payload.get("sub"))
if user_id is None:
raise credentials_exception
stmt = select(User).where(User.id == user_id)
user = db.execute(stmt).scalar_one()
if user is None:
raise credentials_exception
return user
except ExpiredSignatureError as err:
raise HTTPException(
status_code=status.HTTP_401_UNAUTHORIZED,
detail="Token has expired",
) from err
except JWTError as err:
raise HTTPException(
status_code=status.HTTP_400_BAD_REQUEST,
detail="Invalid token",
) from err


def get_current_active_user(user: User = Depends(get_current_user)):
Expand Down
22 changes: 21 additions & 1 deletion src/domain/schemas/book_schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class DomainResGetBook(BaseModel):
version: str | None = Field(title="version", description="판본", example="10e")
major: bool = Field(title="major", description="전공책 여부", example=True)
language: str = Field(title="language", description="언어", example="영문")
donor_name: str| None = Field(title="donor_name", description="책 기증자 성함", example="김철수")
donor_name: str | None = Field(title="donor_name", description="책 기증자 성함", example="김철수")
book_status: bool = Field(title="book_stauts", description="책 상태", example=True)
created_at: datetime = Field(title="create_at", description="생성일시", example=datetime.now())
updated_at: datetime = Field(title="update_at", description="수정일시", example=datetime.now())
Expand Down Expand Up @@ -105,3 +105,23 @@ class DomainResAdminPutBook(BaseModel):

class DomainReqAdminDelBook(BaseModel):
book_id: int = Field(title="book_id", description="책 ID", gt=0)


class DomainAdminGetBookItem(BaseModel):
book_id: int = Field(title="book_id", description="책 ID", example=1, gt=0)
book_title: str = Field(title="book_title", description="책 제목", example="FastAPI Tutorial")
code: str = Field(title="code", description="책 코드", example="A3")
category_name: str = Field(title="category_name", description="카테고리 이름", example="웹")
subtitle: str | None = Field(title="subtitle", description="부제목", example="for beginner")
author: str = Field(title="author", description="저자", example="minjae")
publisher: str = Field(title="publisher", description="출판사", example="KUCC")
publication_year: int = Field(title="publication_year", description="출판년도", example=2022, gt=0)
image_url: str | None = Field(title="image_url", description="책 이미지 링크", example="https://example.com/img")
version: str | None = Field(title="version", description="판본", example="10e")
major: bool | None = Field(title="major", description="전공책 여부", example=False, default=False)
language: str | None = Field(title="language", description="언어", example="영문", default="KOREAN")
donor_name: str | None = Field(title="donor_name", description="책 기증자 성함", example="김철수")
book_status: bool = Field(title="book_stauts", description="책 상태", example=True)
created_at: datetime = Field(title="create_at", description="생성일시", example=datetime.now())
updated_at: datetime = Field(title="update_at", description="수정일시", example=datetime.now())
loan_status: bool | None = Field(title="loan_status", description="대출 상태", example=False)
42 changes: 28 additions & 14 deletions src/domain/schemas/loan_schemas.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# ruff: noqa: E501
from datetime import date, timedelta
from datetime import datetime as _datetime
from datetime import date, datetime, timedelta

from pydantic import BaseModel, Field

Expand All @@ -9,10 +8,10 @@ class Loan(BaseModel):
id: int = Field(title="loan_id", description="대출 정보 id", example=1, gt=0)
book_id: int = Field(title="book_id", description="대출한 책 ID", example=1, gt=0)
user_id: int = Field(title="user_id", description="대출한 사용자 ID", example=1, gt=0)
created_at: _datetime = Field(title="create_at", description="생성일시", example=_datetime.now())
updated_at: _datetime = Field(title="update_at", description="수정일시", example=_datetime.now())
loan_date: date = Field(title="loan_date", description="대출 날짜", example=_datetime.today().date())
due_date: date = Field(title="due_date", description="반납 기한", example=(_datetime.today() + timedelta(days=14)).date())
created_at: datetime = Field(title="create_at", description="생성일시", example=datetime.now())
updated_at: datetime = Field(title="update_at", description="수정일시", example=datetime.now())
loan_date: date = Field(title="loan_date", description="대출 날짜", example=datetime.today().date())
due_date: date = Field(title="due_date", description="반납 기한", example=(datetime.today() + timedelta(days=14)).date())
extend_status: bool = Field(title="extend_status", description="연장 상태", example=True)
overdue_days: int = Field(title="overdue_days", description="연체 일자", example=1)
return_status: bool = Field(title="return_status", description="반납 상태", example=False)
Expand All @@ -23,10 +22,10 @@ class DomainResGetLoanItem(BaseModel):
loan_id: int = Field(title="loan_id", description="대출 정보 id", example=1, gt=0)
book_id: int = Field(title="book_id", description="대출한 책 ID", example=1, gt=0)
user_id: int = Field(title="user_id", description="대출한 사용자 ID", example=1, gt=0)
created_at: _datetime = Field(title="create_at", description="생성일시", example=_datetime.now())
updated_at: _datetime = Field(title="update_at", description="수정일시", example=_datetime.now())
loan_date: date = Field(title="loan_date", description="대출 날짜", example=_datetime.today().date())
due_date: date = Field(title="due_date", description="반납 기한", example=(_datetime.today() + timedelta(days=14)).date())
created_at: datetime = Field(title="create_at", description="생성일시", example=datetime.now())
updated_at: datetime = Field(title="update_at", description="수정일시", example=datetime.now())
loan_date: date = Field(title="loan_date", description="대출 날짜", example=datetime.today().date())
due_date: date = Field(title="due_date", description="반납 기한", example=(datetime.today() + timedelta(days=14)).date())
extend_status: bool = Field(title="extend_status", description="연장 상태", example=True)
overdue_days: int = Field(title="overdue_days", description="연체 일자", example=1)
return_status: bool = Field(title="return_status", description="반납 상태", example=False)
Expand Down Expand Up @@ -60,17 +59,32 @@ class DomainReqPostLoan(BaseModel):
class LoanCreate(BaseModel):
user_id: int = Field(title="user_id", description="대출한 사용자 ID", example=1, gt=0)
book_id: int = Field(title="book_id", description="대출한 책 ID", example=1, gt=0)
created_at: _datetime = Field(title="create_at", description="생성일시", example=_datetime.now())
updated_at: _datetime = Field(title="update_at", description="수정일시", example=_datetime.now())
created_at: datetime = Field(title="create_at", description="생성일시", example=datetime.now())
updated_at: datetime = Field(title="update_at", description="수정일시", example=datetime.now())


class DomainResGetLoan(BaseModel):
loan_id: int = Field(title="loan_id", description="대출 정보 id", example=1, gt=0)
book_id: int = Field(title="book_id", description="대출한 책 ID", example=1, gt=0)
user_id: int = Field(title="user_id", description="대출한 사용자 ID", example=1, gt=0)
loan_date: date = Field(title="loan_date", description="대출 날짜", example=_datetime.today().date())
due_date: date = Field(title="due_date", description="반납 기한", example=(_datetime.today() + timedelta(days=14)).date())
loan_date: date = Field(title="loan_date", description="대출 날짜", example=datetime.today().date())
due_date: date = Field(title="due_date", description="반납 기한", example=(datetime.today() + timedelta(days=14)).date())
extend_status: bool = Field(title="extend_status", description="연장 상태", example=True)
overdue_days: int = Field(title="overdue_days", description="연체 일자", example=1)
return_status: bool = Field(title="return_status", description="반납 상태", example=False)
return_date: date | None = Field(title="return_date", description="반납 날짜", example=None)

class DomainAdminGetLoanItem(BaseModel):
loan_id: int = Field(title="loan_id", description="대출 id", example=1, gt=0)
book_id: int = Field(title="book_id", description="대출한 책 ID", example=1, gt=0)
user_id: int = Field(title="user_id", description="대출한 사용자 ID", example=1, gt=0)
user_name: str = Field(title="user_name", description="리뷰한 사용자 이름", example="test")
code: str = Field(title="code", description="책 코드", example="A3")
book_title: str = Field(title="book_title", description="구매 요청한 책 제목", example="book1")
loan_date: date = Field(title="loan_date", description="대출 날짜", example=datetime.today().date())
due_date: date = Field(title="due_date", description="반납 기한", example=(datetime.today() + timedelta(days=14)).date())
extend_status: bool = Field(title="extend_status", description="연장 상태", example=True)
return_status: bool = Field(title="return_status", description="반납 상태", example=False)
return_date: date | None = Field(title="return_date", description="반납 날짜", example=None)
created_at: datetime = Field(title="create_at", description="생성일시", example=datetime.now())
updated_at: datetime = Field(title="update_at", description="수정일시", example=datetime.now())
27 changes: 27 additions & 0 deletions src/domain/schemas/notice_schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from pydantic import BaseModel, Field


class DomainResAdminGetNotice(BaseModel):
notice_id: int = Field(title="notice_id", description="공지사항 ID", example=1, gt=0)
admin_id: int = Field(title="admin_id", description="관리자 ID", example=1, gt=0)
Expand All @@ -17,3 +18,29 @@ class DomainResGetNotice(BaseModel):
title: str = Field(title="title", description="공지사항 제목", example="공지사항 제목")
notice_content: str = Field(title="notice content", description="공지사항 내용", example="공지사항 내용")
created_at: date = Field(title="created_at", description="공지사항 생성일", example=date.today())

class DomainReqAdminPostNotice(BaseModel):
user_id: int = Field(title="user_id", description="사용자 ID", example=1, gt=0)
admin_id: int = Field(title="user_id", description="관리자 ID", example=1, gt=0)
title: str = Field(title="title", description="공지사항 제목", examples=["공지사항 제목1"])
notice_content: str = Field(title="notice content", description="공지사항 내용", examples=["공지사항 내용1"])

class DomainResAdminPostNotice(BaseModel):
notice_id: int = Field(title="notice_id", description="공지사항 ID", examples=[1, 2, 3], gt=0)
admin_name: str = Field(title="admin_name", description="관리자 성명", examples=["관리자 성명1"])
title: str = Field(title="title", description="공지사항 제목", examples=["공지사항 제목1", "공지사항 제목2"])
notice_content: str = Field(title="notice content", description="공지사항 내용", examples=["공지사항 내용1"])
created_at: date = Field(title="created_at", description="공지사항 생성일", examples=[date.today()])

class DomainReqAdminPutNotice(BaseModel):
notice_id: int = Field(title="notice_id", description="공지사항 ID", examples=[1, 2, 3], gt=0)
admin_id: int = Field(title="admin_id", description="관리자 ID", example=1, gt=0)
title: str = Field(title="title", description="공지사항 제목", examples=["공지사항 제목1"])
notice_content: str = Field(title="notice content", description="공지사항 내용", examples=["공지사항 내용1"])

class DomainResAdminPutNotice(BaseModel):
notice_id: int = Field(title="notice_id", description="공지사항 ID", examples=[1, 2, 3], gt=0)
admin_name: str = Field(title="admin_name", description="관리자 성명", examples=["관리자1", "관리자2"])
title: str = Field(title="title", description="공지사항 제목", examples=["공지사항 제목1", "공지사항 제목2"])
notice_content: str = Field(title="notice content", description="공지사항 내용", examples=["공지사항 내용1"])
created_at: date = Field(title="created_at", description="공지사항 생성일", examples=[date.today()])
13 changes: 13 additions & 0 deletions src/domain/schemas/user_schemas.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from datetime import datetime

from pydantic import BaseModel, Field


Expand Down Expand Up @@ -25,3 +27,14 @@ class DomainResPutUser(BaseModel):
github: str | None = Field(None, title="github", description="깃허브 주소", example="https://github.com/kucc")
instagram: str | None = Field(None, title="instagram", description="인스타그램 주소", example="https://www.instagram.com/")

class DomainAdminGetUserItem(BaseModel):
user_id: int = Field(title="user_id", description="대출한 사용자 ID", example=1, gt=0)
auth_id: str = Field(title="auth_id", description="인증 ID", max_length=255)
auth_type: str = Field(default="FIREBASE", description="인증 타입", max_length=20)
email: str = Field(title="email", description="이메일", max_length=100)
user_name: str = Field(title="user_name", description="사용자 이름", max_length=45)
github_id: str | None = Field(default=None, title="github_id", description="깃허브 ID", max_length=100)
instagram_id: str | None = Field(default=None, title="instagram_id", description="인스타그램 ID", max_length=100)
is_active: bool = Field(title="is_active", description="활동 상태")
created_at: datetime = Field(title="create_at", description="생성일시")
updated_at: datetime = Field(title="update_at", description="수정일시")
Empty file.
Loading

0 comments on commit 40c3f8e

Please sign in to comment.