Skip to content

Commit

Permalink
Merge pull request #2 from akmamun/dev
Browse files Browse the repository at this point in the history
get todos done
  • Loading branch information
akmamun authored Jul 28, 2021
2 parents f1b2ea7 + cb97c23 commit 364d152
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 7 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/ENV/
*__pycache__
.env

# testing
/coverage
Expand All @@ -14,6 +13,6 @@
.env.development.local
.env.test.local
.env.production.local

.env
*.egg-info
.vscode/
7 changes: 5 additions & 2 deletions src/servers/controllers/todo_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,11 @@ async def save_todo(self, request: Request):
await self.todos.saveTodo(**request_data)

return JSONResponse(
status_code=200,
status_code=201,
content={"data": None,
"code": status.HTTP_200_OK,
"code": status.HTTP_201_CREATED,
"message": "successfully save"},
)

async def get_todos(self, title: str = None):
return await self.todos.getAll(title)
16 changes: 14 additions & 2 deletions src/servers/models/todo.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,20 @@ class Todos(Repository):
def collection(self):
return 'todos'

def saveTodo(self, title: str, description: str):
async def saveTodo(self, title: str, description: str):
data = {"title": title,
"description": description}

return self.save(data=data, collection_name=self.collection())
return await self.save(data=data, collection_name=self.collection())

async def getAll(self, title: str, start: int = 0, limit: int = 0):
qurey = {}
if title:
qurey['title'] = {'$regex': f'.*{title}.*'}
result = await self.find({
'$query': qurey, # filter deleted face
'$orderby': {
'updated_at': -1
}}, self.collection())
# result.skip(start).limit(limit)
return result
5 changes: 4 additions & 1 deletion src/servers/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@
def index():
return {"message": "base route of service"}


TodoController = TodoController()
routes = [
APIRoute('/', index, methods=["GET"]),
APIRoute('/todos', TodoController.save_todo, methods=["POST"])
APIRoute('/todos', TodoController.save_todo, methods=["POST"]),
APIRoute('/todos', TodoController.get_todos, methods=["GET"])

]

0 comments on commit 364d152

Please sign in to comment.