Skip to content

Commit a11b60d

Browse files
committed
Add contact app endpoints and crud.
1 parent 0d6d453 commit a11b60d

File tree

3 files changed

+38
-0
lines changed

3 files changed

+38
-0
lines changed

contact/api_crud.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
from typing import List, Optional, Union
2+
3+
from core.base_crud import SLUGTYPE, BaseCRUD
4+
from core.utils import unique_slug_generator
5+
from fastapi import HTTPException
6+
from fastapi.encoders import jsonable_encoder
7+
8+
from contact.models import Contact
9+
from contact.schemas import ContactCreate
10+
11+
12+
class ContactCRUD(BaseCRUD[Contact, ContactCreate, ContactCreate, SLUGTYPE]):
13+
14+
def create(self, obj_in: ContactCreate) -> Contact:
15+
obj_in = jsonable_encoder(obj_in)
16+
query = Category.objects.create(**obj_in)
17+
return query
18+
19+
contact = ContactCRUD(Contact)

contact/endpoints.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
from typing import Any, List
2+
3+
from fastapi import APIRouter
4+
5+
from contact.api_crud import contact
6+
from contact.schemas import ContactCreate, ContactOut
7+
8+
router = APIRouter()
9+
10+
@router.post("/", status_code=201, response_model=ContactOut)
11+
async def create_contact(request: ContactCreate) -> Any:
12+
"""
13+
End point for contact creation.
14+
This should always be placed above the single GET endpoint.
15+
"""
16+
return await contact.create(obj_in=request)
17+

core/api_router.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
from blog.endpoints import router as blog_router
2+
from contact.endpoints import router as contact_router
23
from fastapi import APIRouter
34

45
router = APIRouter()
56
router.include_router(blog_router, prefix="/blog", tags=["Blog"])
7+
router.include_router(contact_router, prefix="/contact", tags=["Contact"])

0 commit comments

Comments
 (0)