Skip to content

Commit

Permalink
Merge branch 'refs/heads/main' into staging
Browse files Browse the repository at this point in the history
  • Loading branch information
stopmin committed Jul 15, 2024
2 parents eebe1d7 + a040f2c commit 18acdb8
Show file tree
Hide file tree
Showing 7 changed files with 262 additions and 254 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
1 change: 1 addition & 0 deletions app/model/interaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

class Interaction(Base):
__tablename__ = "interactions"
__table_args__ = {"schema": "gyeongdan"}

id = Column(BigInteger, primary_key=True, index=True, autoincrement=True)
classification_id = Column(BigInteger)
Expand Down
15 changes: 12 additions & 3 deletions app/recommend/recommend_service.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# pylint: disable=missing-module-docstring, missing-module-docstring, attribute-defined-outside-init, unnecessary-comprehension, not-callable, consider-using-f-string, unused-variable

import asyncio
import os
import warnings
from datetime import datetime

Expand All @@ -27,11 +28,16 @@ def articles_to_dataframe(articles: list[Articles]) -> pd.DataFrame:
articles_dict_list = [
{
"article_id": article.id,
article.category: 1,
'ECONOMY_AND_BUSINESS': 0,
'POLITICS_AND_SOCIETY': 0,
'SPORTS_AND_LEISURE': 0,
'TECHNOLOGY_AND_CULTURE': 0
# "created_at": article.created_at.strftime('%Y-%m-%d'),
}
for article in articles
]
for i in range(len(articles_dict_list)):
articles_dict_list[i][articles[i].category] = 1

df = pd.DataFrame(articles_dict_list)
return df
Expand Down Expand Up @@ -61,6 +67,7 @@ def __init__(self, article_id, category, created_at):
# "created_at": [created_at],
}
)

self.article_data.iloc[0][category] = 1


Expand All @@ -84,10 +91,11 @@ def __init__(self):

def set_user_datas(self, user_data_path):
self.user_data_path = user_data_path
self.user_datas = pd.read_csv(user_data_path)
self.user_datas = pd.read_csv(os.path.dirname(os.path.abspath(__file__)) + user_data_path)


async def initialize_data(self, session):
self.set_user_datas("app/recommend/user_classification.csv")
self.set_user_datas("/./user_classification.csv")
await self.set_article_datas(session)
await self.set_interaction_datas(session)

Expand Down Expand Up @@ -127,6 +135,7 @@ def make_dataset(self):
user_features=self.user_features_col,
)

print(self.item_feat)
self.item_features = self.dataset.build_item_features(
(x, y) for x, y in zip(self.item_features["article_id"], self.item_feat)
)
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 18acdb8

Please sign in to comment.