- Fetch: [GET] -> /news/:id
- List: [GET] -> /news/list
- Add: [POST] -> /news
- Update: [POST] -> /news/:id
- Remove: [DELETE] -> /news/:id
Model / View / Controller Model / Template (Django) / View (Django)
Data Access Object, DAO Serializer and Model (Django)
# [*A]: could be Decorator
# [*B]: could be Django Serializer
class ListNews(APIView):
'''
List: [GET] -> /news/list
'''
def get(self, request, format=None):
fields = ['cursor', 'key']
if not Validator.validate(request): # [*A]
return Response(Validator.errors, status=status.HTTP_400_BAD_REQUEST)
querySet = DAO.loadAll(filterBy(fields)) # [*B]
results = maskData(querySet) # [*B]
return Response(results)
'''
Add: [POST] -> /news
'''
def post(self, request, format=None):
# id = DAO.save(data)
pass
class NewsDetail(APIView):
'''
Fetch: [GET] -> /news/:id
'''
def get(self, request, format=None):
fields = ['key']
if not Validator.validate(request, fields): # [*A]
return Response(Validator.errors, status=status.HTTP_400_BAD_REQUEST)
querySet = DAO.load(filterBy(request, fields)) # [*B]
item = maskData(querySet) # [*B]
if not data:
return Response(None, status=status.HTTP_404_NOT_FOUND)
return Response(item)
'''
Update: [POST] -> /news/:id
'''
def post(self, request, format=None):
# DAO.saveOrUpdate(id, data)
pass
'''
Remove: [DELETE] -> /news/:id
'''
def delete(self, request, format=None):
# DAO.destroy(id)
pass