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

mohammed salih #80

Open
wants to merge 2 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
20 changes: 5 additions & 15 deletions config/urls.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,11 @@
"""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:
Function views
1. Add an import: from my_app import views
2. Add a URL to urlpatterns: path('', views.home, name='home')
Class-based views
1. Add an import: from other_app.views import Home
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
Including another URLconf
1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
import imp
from django.contrib import admin
from django.urls import path
from headless.controllers import api
from headless.controllers import controll_router

api.add_router('/control',controll_router)
urlpatterns = [
path('admin/', admin.site.urls),
path ('api/',api.urls)
]
26 changes: 26 additions & 0 deletions headless/controllers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@

from ninja import NinjaAPI
from ninja import Router
from . import utils
api = NinjaAPI()
controll_router = Router()

@controll_router.get('/posts')
def List_Post(request):
return utils.list_posts()

@controll_router.get('/posts/{title}')
def get_content_of_certain_post(request,title:str):
return utils.get_post(title)

@controll_router.post('/posts')
def new_post(request,title:str,contant:str):
return utils.save_post(title,contant)

@controll_router.put('/posts/{title}')
def update_post(request,title:str,contant:str):
return utils.save_post(title,contant)

@controll_router.delete('/posts/{title}')
def delete_post(request,title:str):
return utils.del_post(title)
6 changes: 5 additions & 1 deletion headless/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,8 @@ def get_post(title):


def del_post(title):
pass
filename = f"posts/{title}.md"
if default_storage.exists(filename):
default_storage.delete(filename)
return 'done'
else:return 'please enter an exist post'
1 change: 1 addition & 0 deletions posts/dont open me .md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dont close me
7 changes: 0 additions & 7 deletions posts/dot_net_core_sucks_less_than_php.md

This file was deleted.

1 change: 1 addition & 0 deletions posts/hello.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
its me
1 change: 0 additions & 1 deletion posts/php_sucks.md

This file was deleted.

1 change: 1 addition & 0 deletions posts/tell me who are you.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
who are you