From 3af3db52acedeb67fec058c6b5f8f9f8149ec125 Mon Sep 17 00:00:00 2001 From: fanarkhalil <83852436+fanarkhalil@users.noreply.github.com> Date: Thu, 21 Jul 2022 23:58:37 +0300 Subject: [PATCH 1/3] Update urls.py --- config/urls.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/config/urls.py b/config/urls.py index d52e5777..1e94341a 100644 --- a/config/urls.py +++ b/config/urls.py @@ -1,5 +1,4 @@ """config URL Configuration - The `urlpatterns` list routes URLs to views. For more information please see: https://docs.djangoproject.com/en/3.2/topics/http/urls/ Examples: @@ -15,7 +14,14 @@ """ from django.contrib import admin from django.urls import path +from ninja import NinjaAPI + +from headless.controllers import end_points + +api = NinjaAPI() +api.add_router('/methods',end_points) urlpatterns = [ path('admin/', admin.site.urls), + path('api/',api.urls) ] From be07f4e44874632148d13a203781b7efe5841265 Mon Sep 17 00:00:00 2001 From: fanarkhalil <83852436+fanarkhalil@users.noreply.github.com> Date: Thu, 21 Jul 2022 23:59:31 +0300 Subject: [PATCH 2/3] Update controllers.py --- headless/controllers.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/headless/controllers.py b/headless/controllers.py index e69de29b..28d7bd10 100644 --- a/headless/controllers.py +++ b/headless/controllers.py @@ -0,0 +1,29 @@ +from ninja import Router +from headless import utils + +end_points = Router() + +@end_points.get('/list') +def list(request): + return utils.list_posts() + + +@end_points.get('/retrieve/{title}') +def retrieve(request,title): + return utils.get_post(title) + + +@end_points.post("create") +def create(request,title:str,content:str): + utils.save_post(title,content) + + +@end_points.put("/update/{title}") +def update(request,title:str,content:str): + utils.save_post(title,content) + + +@end_points.delete("/delete/{title}") +def delete(request,title:str): + utils.del_post(title) + From 6db0e5a3c192c1a992f11cb4a188dd58a0927e1f Mon Sep 17 00:00:00 2001 From: fanarkhalil <83852436+fanarkhalil@users.noreply.github.com> Date: Fri, 22 Jul 2022 00:09:17 +0300 Subject: [PATCH 3/3] Update utils.py --- headless/utils.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/headless/utils.py b/headless/utils.py index 20a48f9c..00323396 100644 --- a/headless/utils.py +++ b/headless/utils.py @@ -38,4 +38,6 @@ def get_post(title): def del_post(title): - pass \ No newline at end of file + pass +filename = f"posts/{title}.md" + default_storage.delete(filename)