Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Todo endpoints. #3

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions api/domain/schemas/todo.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
from api.domain.schemas.schema_base import SchemaBase

from typing import Optional

class TodoBase(SchemaBase):
"""your code goes here"""
description: str
user_id: Optional[int] = None


class TodoCreate(TodoBase):
pass


class Todo(TodoBase):
id: Optional[int] = None

class Config:
orm_mode = True

Expand Down
23 changes: 21 additions & 2 deletions api/host/endpoints/todo_endpoints.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,31 @@
from dependency_injector.wiring import Provide, inject
from fastapi import Depends
from fastapi_utils.cbv import cbv
from fastapi_utils.inferring_router import InferringRouter
from starlette import status

from api.domain.schemas.todo import TodoCreate, Todo
from api.domain.application_container import ApplicationContainer
from api.domain.schemas.todo import TodoCreate, Todo, TodoResponse
from api.host.endpoints.endpoints_base import EndpointsBase
from api.host.handler.todo_handler import TodoHandler

router = InferringRouter()


@cbv(router)
class TodoEndpoints(EndpointsBase[TodoCreate, Todo]):
"""Your code goes here"""
@inject
def __init__(self, handler: TodoHandler = Depends(Provide[ApplicationContainer.handler_container.todo_handler])):
super().__init__(handler=handler)

# Create todo end-point.
@router.post('/todos', status_code=status.HTTP_201_CREATED)
def create(self, dto: TodoCreate) -> TodoResponse:
result = super().create(dto)
return result

# Fetch a todo end-point.
@router.get('/todos/{id}')
def get_by_id(self, id: int) -> TodoResponse:
result = super().get_by_id(id)
return result
101 changes: 101 additions & 0 deletions postman_collection/hitachi_endpoints.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
{
"info": {
"_postman_id": "e5b51a74-a915-4b18-a9d9-ba0db9b1de65",
"name": "Hitachi",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
},
"item": [
{
"name": "Fetch a Todo",
"request": {
"method": "GET",
"header": [],
"url": {
"raw": "localhost:8080/todos/1",
"host": [
"localhost"
],
"port": "8080",
"path": [
"todos",
"1"
]
}
},
"response": []
},
{
"name": "Fetch an User",
"request": {
"method": "GET",
"header": [],
"url": {
"raw": "localhost:8080/users/1",
"host": [
"localhost"
],
"port": "8080",
"path": [
"users",
"1"
]
}
},
"response": []
},
{
"name": "Create User",
"request": {
"method": "POST",
"header": [],
"body": {
"mode": "raw",
"raw": "{\r\n \"name\": \"John Doe\",\r\n \"age\": 22\r\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "localhost:8080/users",
"host": [
"localhost"
],
"port": "8080",
"path": [
"users"
]
}
},
"response": []
},
{
"name": "Create Todo",
"request": {
"method": "POST",
"header": [],
"body": {
"mode": "raw",
"raw": "{\r\n \"description\": \"Work from home\",\r\n \"user_id\": 4\r\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "localhost:8080/todos",
"host": [
"localhost"
],
"port": "8080",
"path": [
"todos"
]
}
},
"response": []
}
]
}
Binary file added screenshots/create_a_todo.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added screenshots/create_an_user.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added screenshots/fetch_a_todo.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added screenshots/fetch_an_user.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.