Skip to content

Commit 47d3551

Browse files
authored
Merge pull request #27 from testdrivenio/updates
updates
2 parents 1dc33dd + 839bcdf commit 47d3551

File tree

8 files changed

+62
-53
lines changed

8 files changed

+62
-53
lines changed

.github/workflows/main.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ jobs:
8383
-p 5003:8765 \
8484
${{ env.IMAGE }}-final:latest
8585
- name: Install requirements
86-
run: docker exec fastapi-tdd pip install black==21.12b0 flake8==4.0.1 isort==5.10.1 pytest==6.2.5
86+
run: docker exec fastapi-tdd pip install black==22.10.0 flake8==5.0.4 isort==5.10.1 pytest==7.2.0
8787
- name: Pytest
8888
run: docker exec fastapi-tdd python -m pytest .
8989
- name: Flake8
@@ -98,7 +98,7 @@ jobs:
9898
runs-on: ubuntu-latest
9999
needs: [build, test]
100100
env:
101-
HEROKU_APP_NAME: sleepy-thicket-77414
101+
HEROKU_APP_NAME: guarded-eyrie-00742
102102
HEROKU_REGISTRY_IMAGE: registry.heroku.com/${HEROKU_APP_NAME}/summarizer
103103
steps:
104104
- name: Checkout

project/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# pull official base image
2-
FROM python:3.10.1-slim-buster
2+
FROM python:3.10.8-slim-buster
33

44
# set working directory
55
WORKDIR /usr/src/app

project/Dockerfile.prod

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
###########
44

55
# pull official base image
6-
FROM python:3.10.1-slim-buster as builder
6+
FROM python:3.10.8-slim-buster as builder
77

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

2525
# lint
2626
COPY . /usr/src/app/
27-
RUN pip install black==21.12b0 flake8==4.0.1 isort==5.10.1
27+
RUN pip install black==22.10.0 flake8==5.0.4 isort==5.10.1
2828
RUN flake8 .
2929
RUN black --exclude=migrations .
3030
RUN isort .
@@ -35,7 +35,7 @@ RUN isort .
3535
#########
3636

3737
# pull official base image
38-
FROM python:3.10.1-slim-buster
38+
FROM python:3.10.8-slim-buster
3939

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

7070
# add app
7171
COPY . .

project/app/api/crud.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@
44
from app.models.tortoise import TextSummary
55

66

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

1211

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

1918

20-
async def get_all() -> List:
21-
summaries = await TextSummary.all().values()
22-
return summaries
23-
24-
25-
async def delete(id: int) -> int:
26-
summary = await TextSummary.filter(id=id).first().delete()
27-
return summary
19+
async def post(payload: SummaryPayloadSchema) -> int:
20+
summary = TextSummary(url=payload.url, summary="")
21+
await summary.save()
22+
return summary.id
2823

2924

3025
async def put(id: int, payload: SummaryPayloadSchema) -> Union[dict, None]:
@@ -35,3 +30,8 @@ async def put(id: int, payload: SummaryPayloadSchema) -> Union[dict, None]:
3530
updated_summary = await TextSummary.filter(id=id).first().values()
3631
return updated_summary
3732
return None
33+
34+
35+
async def delete(id: int) -> int:
36+
summary = await TextSummary.filter(id=id).first().delete()
37+
return summary

project/app/api/summaries.py

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,20 @@
1515
router = APIRouter()
1616

1717

18+
@router.get("/", response_model=List[SummarySchema])
19+
async def read_all_summaries() -> List[SummarySchema]:
20+
return await crud.get_all()
21+
22+
23+
@router.get("/{id}/", response_model=SummarySchema)
24+
async def read_summary(id: int = Path(..., gt=0)) -> SummarySchema:
25+
summary = await crud.get(id)
26+
if not summary:
27+
raise HTTPException(status_code=404, detail="Summary not found")
28+
29+
return summary
30+
31+
1832
@router.post("/", response_model=SummaryResponseSchema, status_code=201)
1933
async def create_summary(
2034
payload: SummaryPayloadSchema, background_tasks: BackgroundTasks
@@ -27,20 +41,17 @@ async def create_summary(
2741
return response_object
2842

2943

30-
@router.get("/{id}/", response_model=SummarySchema)
31-
async def read_summary(id: int = Path(..., gt=0)) -> SummarySchema:
32-
summary = await crud.get(id)
44+
@router.put("/{id}/", response_model=SummarySchema)
45+
async def update_summary(
46+
payload: SummaryUpdatePayloadSchema, id: int = Path(..., gt=0)
47+
) -> SummarySchema:
48+
summary = await crud.put(id, payload)
3349
if not summary:
3450
raise HTTPException(status_code=404, detail="Summary not found")
3551

3652
return summary
3753

3854

39-
@router.get("/", response_model=List[SummarySchema])
40-
async def read_all_summaries() -> List[SummarySchema]:
41-
return await crud.get_all()
42-
43-
4455
@router.delete("/{id}/", response_model=SummaryResponseSchema)
4556
async def delete_summary(id: int = Path(..., gt=0)) -> SummaryResponseSchema:
4657
summary = await crud.get(id)
@@ -50,14 +61,3 @@ async def delete_summary(id: int = Path(..., gt=0)) -> SummaryResponseSchema:
5061
await crud.delete(id)
5162

5263
return summary
53-
54-
55-
@router.put("/{id}/", response_model=SummarySchema)
56-
async def update_summary(
57-
payload: SummaryUpdatePayloadSchema, id: int = Path(..., gt=0)
58-
) -> SummarySchema:
59-
summary = await crud.put(id, payload)
60-
if not summary:
61-
raise HTTPException(status_code=404, detail="Summary not found")
62-
63-
return summary
Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1-
-- upgrade --
2-
CREATE TABLE IF NOT EXISTS "textsummary" (
1+
from tortoise import BaseDBAsyncClient
2+
3+
4+
async def upgrade(db: BaseDBAsyncClient) -> str:
5+
return """
6+
CREATE TABLE IF NOT EXISTS "textsummary" (
37
"id" SERIAL NOT NULL PRIMARY KEY,
48
"url" TEXT NOT NULL,
59
"summary" TEXT NOT NULL,
@@ -8,6 +12,11 @@
812
CREATE TABLE IF NOT EXISTS "aerich" (
913
"id" SERIAL NOT NULL PRIMARY KEY,
1014
"version" VARCHAR(255) NOT NULL,
11-
"app" VARCHAR(20) NOT NULL,
15+
"app" VARCHAR(100) NOT NULL,
1216
"content" JSONB NOT NULL
13-
);
17+
);"""
18+
19+
20+
async def downgrade(db: BaseDBAsyncClient) -> str:
21+
return """
22+
"""

project/requirements-dev.txt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
black==21.12b0
2-
flake8==4.0.1
1+
black==22.10.0
2+
flake8==5.0.4
33
isort==5.10.1
4-
pytest==6.2.5
5-
pytest-cov==3.0.0
6-
pytest-xdist==2.5.0
4+
pytest==7.2.0
5+
pytest-cov==4.0.0
6+
pytest-xdist==3.0.2
77

88
-r requirements.txt

project/requirements.txt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
aerich==0.6.1
2-
asyncpg==0.25.0
3-
fastapi==0.70.1
1+
aerich==0.7.1
2+
asyncpg==0.27.0
3+
fastapi==0.85.1
44
gunicorn==20.1.0
55
newspaper3k==0.2.8
6-
requests==2.26.0
7-
tortoise-orm==0.17.8
8-
uvicorn==0.16.0
6+
requests==2.28.1
7+
tortoise-orm==0.19.2
8+
uvicorn==0.19.0

0 commit comments

Comments
 (0)