-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(api): setup API for reading app
We can list articles. See #318
- Loading branch information
Showing
6 changed files
with
81 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
from ninja import NinjaAPI | ||
from ninja.security import django_auth | ||
|
||
from legadilo.reading.api import reading_api_router | ||
|
||
api = NinjaAPI(title="Legadilo API", auth=[django_auth], docs_url="/docs/") | ||
api.add_router("reading/", reading_api_router) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# Legadilo | ||
# Copyright (C) 2023-2024 by Legadilo contributors. | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU Affero General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU Affero General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU Affero General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
from ninja import ModelSchema, Router | ||
from ninja.pagination import paginate | ||
|
||
from legadilo.reading.models import Article | ||
from legadilo.users.user_types import AuthenticatedHttpRequest | ||
|
||
reading_api_router = Router(tags=["reading"]) | ||
|
||
|
||
class OutArticleSchema(ModelSchema): | ||
class Meta: | ||
model = Article | ||
exclude = ("user", "obj_created_at", "obj_updated_at") | ||
|
||
|
||
@reading_api_router.get("/articles/", response=list[OutArticleSchema]) | ||
@paginate | ||
def list_articles(request: AuthenticatedHttpRequest): | ||
return Article.objects.get_queryset().for_user(request.user).default_order_by() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
{% load static %} | ||
|
||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<link type="text/css" | ||
rel="stylesheet" | ||
href="{% static 'ninja/swagger-ui.css' %}" | ||
nonce="{{ request.csp_nonce }}" /> | ||
<link rel="shortcut icon" href="{% static 'ninja/favicon.png' %}" /> | ||
<title>{{ api.title }}</title> | ||
</head> | ||
<body data-csrf-token="{% if add_csrf %}{{ csrf_token }}{% endif %}" | ||
data-api-csrf="{% if add_csrf %}true{% endif %}"> | ||
<script type="application/json" id="swagger-settings"> | ||
{% comment %} | ||
Beware: if this file gets reformatted, we can loose the proper syntax below. This | ||
will breaks the swagger template! | ||
{% endcomment %} | ||
{{ swagger_settings | safe }} | ||
</script> | ||
<div id="swagger-ui"></div> | ||
<script src="{% static 'ninja/swagger-ui-bundle.js' %}" | ||
nonce="{{ request.csp_nonce }}"></script> | ||
<script src="{% static 'ninja/swagger-ui-init.js' %}" | ||
nonce="{{ request.csp_nonce }}"></script> | ||
</body> | ||
</html> |