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

fanar khalil #82

Open
wants to merge 3 commits 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
8 changes: 7 additions & 1 deletion config/urls.py
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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)
]
29 changes: 29 additions & 0 deletions headless/controllers.py
Original file line number Diff line number Diff line change
@@ -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)

4 changes: 3 additions & 1 deletion headless/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,6 @@ def get_post(title):


def del_post(title):
pass
pass
filename = f"posts/{title}.md"
default_storage.delete(filename)