-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
68 additions
and
641 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,63 +1,31 @@ | ||
from typing import List | ||
|
||
from fastapi import APIRouter, BackgroundTasks, HTTPException, Path | ||
from fastapi import APIRouter, HTTPException | ||
|
||
from app.api import crud | ||
from app.models.pydantic import SummaryPayloadSchema, SummaryResponseSchema | ||
from app.models.tortoise import SummarySchema | ||
from app.summarizer import generate_summary | ||
|
||
from app.models.pydantic import ( # isort:skip | ||
SummaryPayloadSchema, | ||
SummaryResponseSchema, | ||
SummaryUpdatePayloadSchema, | ||
) | ||
|
||
router = APIRouter() | ||
|
||
|
||
@router.get("/", response_model=List[SummarySchema]) | ||
async def read_all_summaries() -> List[SummarySchema]: | ||
return await crud.get_all() | ||
|
||
|
||
@router.get("/{id}/", response_model=SummarySchema) | ||
async def read_summary(id: int = Path(..., gt=0)) -> SummarySchema: | ||
async def read_summary(id: int) -> SummarySchema: | ||
summary = await crud.get(id) | ||
if not summary: | ||
raise HTTPException(status_code=404, detail="Summary not found") | ||
|
||
return summary | ||
|
||
|
||
@router.get("/", response_model=List[SummarySchema]) | ||
async def read_all_summaries() -> List[SummarySchema]: | ||
return await crud.get_all() | ||
|
||
|
||
@router.post("/", response_model=SummaryResponseSchema, status_code=201) | ||
async def create_summary( | ||
payload: SummaryPayloadSchema, background_tasks: BackgroundTasks | ||
) -> SummaryResponseSchema: | ||
async def create_summary(payload: SummaryPayloadSchema) -> SummaryResponseSchema: | ||
summary_id = await crud.post(payload) | ||
|
||
background_tasks.add_task(generate_summary, summary_id, payload.url) | ||
|
||
response_object = {"id": summary_id, "url": payload.url} | ||
return response_object | ||
|
||
|
||
@router.put("/{id}/", response_model=SummarySchema) | ||
async def update_summary( | ||
payload: SummaryUpdatePayloadSchema, id: int = Path(..., gt=0) | ||
) -> SummarySchema: | ||
summary = await crud.put(id, payload) | ||
if not summary: | ||
raise HTTPException(status_code=404, detail="Summary not found") | ||
|
||
return summary | ||
|
||
|
||
@router.delete("/{id}/", response_model=SummaryResponseSchema) | ||
async def delete_summary(id: int = Path(..., gt=0)) -> SummaryResponseSchema: | ||
summary = await crud.get(id) | ||
if not summary: | ||
raise HTTPException(status_code=404, detail="Summary not found") | ||
|
||
await crud.delete(id) | ||
|
||
return summary |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,9 @@ | ||
from pydantic import AnyHttpUrl, BaseModel | ||
from pydantic import BaseModel | ||
|
||
|
||
class SummaryPayloadSchema(BaseModel): | ||
url: AnyHttpUrl | ||
url: str | ||
|
||
|
||
class SummaryResponseSchema(SummaryPayloadSchema): | ||
id: int | ||
|
||
|
||
class SummaryUpdatePayloadSchema(SummaryPayloadSchema): | ||
summary: str |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.