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

Muntadhar Faris #100

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
8 changes: 7 additions & 1 deletion config/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,13 @@
"""
from django.contrib import admin
from django.urls import path
from ninja import NinjaAPI
from headless.controllers import controller

api = NinjaAPI()
api.add_router('', controller)

urlpatterns = [
path('admin/', admin.site.urls),
]
path('api/', api.urls)
]
24 changes: 24 additions & 0 deletions headless/controllers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from ninja import Router
from headless.utils import *

controller = Router()

@controller.get('posts')
def get_posts(request):
return list_posts()

@controller.get('post')
def get_single_post(request, title):
return get_post(title)

@controller.post('create')
def create_post(request, title, content):
return save_post(title, content)

@controller.put('update')
def update_post(request, title, content):
return save_post(title, content)

@controller.delete('deleted')
def delet_post(request, title):
return del_post(title)
9 changes: 8 additions & 1 deletion headless/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,11 @@ def get_post(title):


def del_post(title):
pass
"""
Delet a blog post, given its title
If an existing post with the same title already exists,
it is deleted.
"""
filename = f"posts/{title}.md"
if default_storage.exists(filename):
default_storage.delete(filename)
1 change: 1 addition & 0 deletions posts/Muntadhar.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
it's done