Skip to content

Commit

Permalink
필요 없는 라우터 제거 (#95)
Browse files Browse the repository at this point in the history
* refact(main.py) : 사용하지 않는 라우터 제거

* refact(routers) : 사용하지 않는 라우터 제거

* refact(user_type_router) : 함수 이름 일관성 유지
  • Loading branch information
YunseongJeong authored Jul 14, 2024
1 parent 0133d49 commit a040f2c
Show file tree
Hide file tree
Showing 4 changed files with 247 additions and 251 deletions.
8 changes: 2 additions & 6 deletions app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,8 @@
LoggingMiddleware,
)
from app.router.generate_simple_article_router import simple_article_router
from app.router.newsletter_article_crud_router import newsletter_article_router
from app.router.send_email_service_router import send_email_service_router
from app.router.subscription_crud_router import subscription_router
from app.router.user_type_router import user_type_router
from app.router.send_email_service_router import send_email_service_router
from app.service.news_scheduling_service import schedule_task

app = FastAPI()
Expand All @@ -30,11 +28,9 @@ async def startup_event():
app.add_middleware(LoggingMiddleware)

# routers
app.include_router(subscription_router)
app.include_router(newsletter_article_router)
app.include_router(send_email_service_router)
app.include_router(user_type_router)
app.include_router(simple_article_router)
app.include_router(send_email_service_router)

# exception handlers
app.add_exception_handler(Exception, exception_handler)
Expand Down
232 changes: 116 additions & 116 deletions app/router/newsletter_article_crud_router.py
Original file line number Diff line number Diff line change
@@ -1,117 +1,117 @@
# newsletter_article_crud_router.py

from datetime import datetime
from typing import List

from fastapi import APIRouter, Depends
from pydantic import BaseModel
from sqlalchemy.ext.asyncio import AsyncSession

from app.database.session import get_db_session
from app.model.newsletter_article import NewsletterArticle
from app.model.subscription import MailTypeCategory
from app.service.newsletter_article_service import (
NewsletterService,
generate_newsletter_article,
)
from app.utils.generic_response import GenericResponseDTO

newsletter_article_router = APIRouter()


class NewsletterArticleResponseDTO(BaseModel):
category: str
content: str
updated_at: datetime


async def newsletter_to_dto(newsletter_article: NewsletterArticle):
return NewsletterArticleResponseDTO(
category=newsletter_article.category,
content=newsletter_article.content,
updated_at=newsletter_article.updated_at,
)


async def list_to_dto_list(newsletter_article: List[NewsletterArticle]):
return [await newsletter_to_dto(article) for article in newsletter_article]


@newsletter_article_router.post(
"/newsletter_article/save", response_model=GenericResponseDTO[int]
)
async def create_manager(
category: MailTypeCategory,
content: str,
session: AsyncSession = Depends(get_db_session),
):
newsletter_article = await NewsletterService().create_article(
category, content, session
)
return GenericResponseDTO[int](
data=newsletter_article.id, message="Successfully Done", result=True
)


@newsletter_article_router.get(
"/newsletter_article/{id}",
response_model=GenericResponseDTO[NewsletterArticleResponseDTO],
)
async def get_content_by_id(id: int, session: AsyncSession = Depends(get_db_session)):
newsletter_article = await NewsletterService().get_content_by_id(id, session)
return GenericResponseDTO[NewsletterArticleResponseDTO](
data=await newsletter_to_dto(newsletter_article),
message="Successfully Done",
result=True,
)


@newsletter_article_router.get(
"/newsletter_article",
response_model=GenericResponseDTO[List[NewsletterArticleResponseDTO]],
)
async def get_all(session: AsyncSession = Depends(get_db_session)):
newsletter_article = await NewsletterService().get_all_contents(session)
dummy = await list_to_dto_list(newsletter_article)
return GenericResponseDTO[List[NewsletterArticleResponseDTO]](
data=dummy, message="Successfully Done", result=True
)


@newsletter_article_router.get(
"/newsletter_article/search/{category}",
response_model=GenericResponseDTO[List[NewsletterArticleResponseDTO]],
)
async def get_content_by_category(
category: MailTypeCategory, session: AsyncSession = Depends(get_db_session)
):
newsletter_article = await NewsletterService().get_content_by_category(
category, session
)
newsletter_article_dto = await list_to_dto_list(newsletter_article)
return GenericResponseDTO[List[NewsletterArticleResponseDTO]](
data=newsletter_article_dto, message="Successfully Done", result=True
)


@newsletter_article_router.put(
"/newsletter_article/update", response_model=GenericResponseDTO[int]
)
async def update_content_by_id(
id: int,
category: MailTypeCategory,
content: str,
session: AsyncSession = Depends(get_db_session),
):
newsletter_article = await NewsletterService().update_content(
id, category, content, session
)
return GenericResponseDTO[int](
data=newsletter_article.id, message="Successfully Done", result=True
)


@newsletter_article_router.post("/newsletter_article/test")
async def ai_client_test(session: AsyncSession = Depends(get_db_session)):
newsletter_article = await generate_newsletter_article(session)
return newsletter_article
#
# from datetime import datetime
# from typing import List
#
# from fastapi import APIRouter, Depends
# from pydantic import BaseModel
# from sqlalchemy.ext.asyncio import AsyncSession
#
# from app.database.session import get_db_session
# from app.model.newsletter_article import NewsletterArticle
# from app.model.subscription import MailTypeCategory
# from app.service.newsletter_article_service import (
# NewsletterService,
# generate_newsletter_article,
# )
# from app.utils.generic_response import GenericResponseDTO
#
# newsletter_article_router = APIRouter()
#
#
# class NewsletterArticleResponseDTO(BaseModel):
# category: str
# content: str
# updated_at: datetime
#
#
# async def newsletter_to_dto(newsletter_article: NewsletterArticle):
# return NewsletterArticleResponseDTO(
# category=newsletter_article.category,
# content=newsletter_article.content,
# updated_at=newsletter_article.updated_at,
# )
#
#
# async def list_to_dto_list(newsletter_article: List[NewsletterArticle]):
# return [await newsletter_to_dto(article) for article in newsletter_article]


# @newsletter_article_router.post(
# "/newsletter_article/save", response_model=GenericResponseDTO[int]
# )
# async def create_manager(
# category: MailTypeCategory,
# content: str,
# session: AsyncSession = Depends(get_db_session),
# ):
# newsletter_article = await NewsletterService().create_article(
# category, content, session
# )
# return GenericResponseDTO[int](
# data=newsletter_article.id, message="Successfully Done", result=True
# )


# @newsletter_article_router.get(
# "/newsletter_article/{id}",
# response_model=GenericResponseDTO[NewsletterArticleResponseDTO],
# )
# async def get_content_by_id(id: int, session: AsyncSession = Depends(get_db_session)):
# newsletter_article = await NewsletterService().get_content_by_id(id, session)
# return GenericResponseDTO[NewsletterArticleResponseDTO](
# data=await newsletter_to_dto(newsletter_article),
# message="Successfully Done",
# result=True,
# )


# @newsletter_article_router.get(
# "/newsletter_article",
# response_model=GenericResponseDTO[List[NewsletterArticleResponseDTO]],
# )
# async def get_all(session: AsyncSession = Depends(get_db_session)):
# newsletter_article = await NewsletterService().get_all_contents(session)
# dummy = await list_to_dto_list(newsletter_article)
# return GenericResponseDTO[List[NewsletterArticleResponseDTO]](
# data=dummy, message="Successfully Done", result=True
# )


# @newsletter_article_router.get(
# "/newsletter_article/search/{category}",
# response_model=GenericResponseDTO[List[NewsletterArticleResponseDTO]],
# )
# async def get_content_by_category(
# category: MailTypeCategory, session: AsyncSession = Depends(get_db_session)
# ):
# newsletter_article = await NewsletterService().get_content_by_category(
# category, session
# )
# newsletter_article_dto = await list_to_dto_list(newsletter_article)
# return GenericResponseDTO[List[NewsletterArticleResponseDTO]](
# data=newsletter_article_dto, message="Successfully Done", result=True
# )


# @newsletter_article_router.put(
# "/newsletter_article/update", response_model=GenericResponseDTO[int]
# )
# async def update_content_by_id(
# id: int,
# category: MailTypeCategory,
# content: str,
# session: AsyncSession = Depends(get_db_session),
# ):
# newsletter_article = await NewsletterService().update_content(
# id, category, content, session
# )
# return GenericResponseDTO[int](
# data=newsletter_article.id, message="Successfully Done", result=True
# )


# @newsletter_article_router.post("/newsletter_article/test")
# async def ai_client_test(session: AsyncSession = Depends(get_db_session)):
# newsletter_article = await generate_newsletter_article(session)
# return newsletter_article
Loading

0 comments on commit a040f2c

Please sign in to comment.