Skip to content

Commit

Permalink
Merge pull request #27 from testdrivenio/updates
Browse files Browse the repository at this point in the history
updates
  • Loading branch information
mjhea0 authored Oct 30, 2022
2 parents 1dc33dd + 839bcdf commit 47d3551
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 53 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ jobs:
-p 5003:8765 \
${{ env.IMAGE }}-final:latest
- name: Install requirements
run: docker exec fastapi-tdd pip install black==21.12b0 flake8==4.0.1 isort==5.10.1 pytest==6.2.5
run: docker exec fastapi-tdd pip install black==22.10.0 flake8==5.0.4 isort==5.10.1 pytest==7.2.0
- name: Pytest
run: docker exec fastapi-tdd python -m pytest .
- name: Flake8
Expand All @@ -98,7 +98,7 @@ jobs:
runs-on: ubuntu-latest
needs: [build, test]
env:
HEROKU_APP_NAME: sleepy-thicket-77414
HEROKU_APP_NAME: guarded-eyrie-00742
HEROKU_REGISTRY_IMAGE: registry.heroku.com/${HEROKU_APP_NAME}/summarizer
steps:
- name: Checkout
Expand Down
2 changes: 1 addition & 1 deletion project/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# pull official base image
FROM python:3.10.1-slim-buster
FROM python:3.10.8-slim-buster

# set working directory
WORKDIR /usr/src/app
Expand Down
8 changes: 4 additions & 4 deletions project/Dockerfile.prod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
###########

# pull official base image
FROM python:3.10.1-slim-buster as builder
FROM python:3.10.8-slim-buster as builder

# install system dependencies
RUN apt-get update \
Expand All @@ -24,7 +24,7 @@ RUN pip wheel --no-cache-dir --no-deps --wheel-dir /usr/src/app/wheels -r requir

# lint
COPY . /usr/src/app/
RUN pip install black==21.12b0 flake8==4.0.1 isort==5.10.1
RUN pip install black==22.10.0 flake8==5.0.4 isort==5.10.1
RUN flake8 .
RUN black --exclude=migrations .
RUN isort .
Expand All @@ -35,7 +35,7 @@ RUN isort .
#########

# pull official base image
FROM python:3.10.1-slim-buster
FROM python:3.10.8-slim-buster

# create directory for the app user
RUN mkdir -p /home/app
Expand Down Expand Up @@ -65,7 +65,7 @@ COPY --from=builder /usr/src/app/wheels /wheels
COPY --from=builder /usr/src/app/requirements.txt .
RUN pip install --upgrade pip
RUN pip install --no-cache /wheels/*
RUN pip install "uvicorn[standard]==0.16.0"
RUN pip install "uvicorn[standard]==0.19.0"

# add app
COPY . .
Expand Down
24 changes: 12 additions & 12 deletions project/app/api/crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@
from app.models.tortoise import TextSummary


async def post(payload: SummaryPayloadSchema) -> int:
summary = TextSummary(url=payload.url, summary="")
await summary.save()
return summary.id
async def get_all() -> List:
summaries = await TextSummary.all().values()
return summaries


async def get(id: int) -> Union[dict, None]:
Expand All @@ -17,14 +16,10 @@ async def get(id: int) -> Union[dict, None]:
return None


async def get_all() -> List:
summaries = await TextSummary.all().values()
return summaries


async def delete(id: int) -> int:
summary = await TextSummary.filter(id=id).first().delete()
return summary
async def post(payload: SummaryPayloadSchema) -> int:
summary = TextSummary(url=payload.url, summary="")
await summary.save()
return summary.id


async def put(id: int, payload: SummaryPayloadSchema) -> Union[dict, None]:
Expand All @@ -35,3 +30,8 @@ async def put(id: int, payload: SummaryPayloadSchema) -> Union[dict, None]:
updated_summary = await TextSummary.filter(id=id).first().values()
return updated_summary
return None


async def delete(id: int) -> int:
summary = await TextSummary.filter(id=id).first().delete()
return summary
38 changes: 19 additions & 19 deletions project/app/api/summaries.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,20 @@
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:
summary = await crud.get(id)
if not summary:
raise HTTPException(status_code=404, detail="Summary not found")

return summary


@router.post("/", response_model=SummaryResponseSchema, status_code=201)
async def create_summary(
payload: SummaryPayloadSchema, background_tasks: BackgroundTasks
Expand All @@ -27,20 +41,17 @@ async def create_summary(
return response_object


@router.get("/{id}/", response_model=SummarySchema)
async def read_summary(id: int = Path(..., gt=0)) -> SummarySchema:
summary = await crud.get(id)
@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.get("/", response_model=List[SummarySchema])
async def read_all_summaries() -> List[SummarySchema]:
return await crud.get_all()


@router.delete("/{id}/", response_model=SummaryResponseSchema)
async def delete_summary(id: int = Path(..., gt=0)) -> SummaryResponseSchema:
summary = await crud.get(id)
Expand All @@ -50,14 +61,3 @@ async def delete_summary(id: int = Path(..., gt=0)) -> SummaryResponseSchema:
await crud.delete(id)

return summary


@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
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
-- upgrade --
CREATE TABLE IF NOT EXISTS "textsummary" (
from tortoise import BaseDBAsyncClient


async def upgrade(db: BaseDBAsyncClient) -> str:
return """
CREATE TABLE IF NOT EXISTS "textsummary" (
"id" SERIAL NOT NULL PRIMARY KEY,
"url" TEXT NOT NULL,
"summary" TEXT NOT NULL,
Expand All @@ -8,6 +12,11 @@
CREATE TABLE IF NOT EXISTS "aerich" (
"id" SERIAL NOT NULL PRIMARY KEY,
"version" VARCHAR(255) NOT NULL,
"app" VARCHAR(20) NOT NULL,
"app" VARCHAR(100) NOT NULL,
"content" JSONB NOT NULL
);
);"""


async def downgrade(db: BaseDBAsyncClient) -> str:
return """
"""
10 changes: 5 additions & 5 deletions project/requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
black==21.12b0
flake8==4.0.1
black==22.10.0
flake8==5.0.4
isort==5.10.1
pytest==6.2.5
pytest-cov==3.0.0
pytest-xdist==2.5.0
pytest==7.2.0
pytest-cov==4.0.0
pytest-xdist==3.0.2

-r requirements.txt
12 changes: 6 additions & 6 deletions project/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
aerich==0.6.1
asyncpg==0.25.0
fastapi==0.70.1
aerich==0.7.1
asyncpg==0.27.0
fastapi==0.85.1
gunicorn==20.1.0
newspaper3k==0.2.8
requests==2.26.0
tortoise-orm==0.17.8
uvicorn==0.16.0
requests==2.28.1
tortoise-orm==0.19.2
uvicorn==0.19.0

0 comments on commit 47d3551

Please sign in to comment.