wip expose a summary
This commit is contained in:
committed by
Anthony LC
parent
2f8c50540e
commit
e0d41b712e
@@ -8,6 +8,8 @@ from rest_framework import views as drf_views
|
||||
from rest_framework.decorators import api_view
|
||||
from rest_framework.response import Response
|
||||
|
||||
from ..models import Document, User, RoleChoices, DocumentAccess
|
||||
|
||||
|
||||
def exception_handler(exc, context):
|
||||
"""Handle Django ValidationError as an accepted exception.
|
||||
@@ -38,3 +40,32 @@ def get_frontend_configuration(request):
|
||||
}
|
||||
frontend_configuration.update(settings.FRONTEND_CONFIGURATION)
|
||||
return Response(frontend_configuration)
|
||||
|
||||
|
||||
|
||||
@api_view(["POST"])
|
||||
def create_summary(request):
|
||||
"""Wip."""
|
||||
|
||||
data = request.data
|
||||
|
||||
document = Document(
|
||||
title="Votre résumé",
|
||||
link_reach="authenticated",
|
||||
link_role="reader",
|
||||
)
|
||||
|
||||
document.save()
|
||||
owner_user = User.objects.get(email=data["owner"])
|
||||
|
||||
document_access = DocumentAccess(
|
||||
user=owner_user,
|
||||
document=document,
|
||||
role=RoleChoices.OWNER
|
||||
)
|
||||
document_access.save()
|
||||
|
||||
document.content = data["content"]
|
||||
document.save()
|
||||
|
||||
return Response({"id": document.id})
|
||||
|
||||
@@ -5,7 +5,7 @@ from django.urls import include, path, re_path
|
||||
|
||||
from rest_framework.routers import DefaultRouter
|
||||
|
||||
from core.api import viewsets
|
||||
from core.api import viewsets, create_summary
|
||||
from core.authentication.urls import urlpatterns as oidc_urls
|
||||
|
||||
# - Main endpoints
|
||||
@@ -44,6 +44,7 @@ urlpatterns = [
|
||||
[
|
||||
*router.urls,
|
||||
*oidc_urls,
|
||||
path("summary/", create_summary, name="create_summary"),
|
||||
re_path(
|
||||
r"^documents/(?P<resource_id>[0-9a-z-]*)/",
|
||||
include(document_related_router.urls),
|
||||
|
||||
Reference in New Issue
Block a user