Commit 0a4ba94a authored by Christopher Løkken's avatar Christopher Løkken
Browse files

Refactored url config

parent 73e26036
Pipeline #171121 failed with stages
in 35 seconds
backend/secfit/.vscode/
backend/secfit/*/migrations/__pycache__/
backend/secfit/*/__pycache__/
backend/secfit/**/__pycache__/**
backend/secfit/db.sqlite3
venv/
backend/secfit/.coverage
from calendar import c
from django.urls import path, include
from comments.models import Comment, Like
from comments.views import CommentList, CommentDetail, LikeList, LikeDetail
from rest_framework.urlpatterns import format_suffix_patterns
urlpatterns = [
path("api/comments/", CommentList.as_view(), name="comment-list"),
likes_url_patterns = [
path("", LikeList.as_view(), name="like-list"),
path(
"<int:pk>/",
LikeDetail.as_view(),
name="like-detail"),
]
comments_url_patterns = [
path("", CommentList.as_view(), name="comment-list"),
path(
"api/comments/<int:pk>/",
"<int:pk>/",
CommentDetail.as_view(),
name="comment-detail"),
path("api/likes/", LikeList.as_view(), name="like-list"),
path("api/likes/<int:pk>/", LikeDetail.as_view(), name="like-detail"),
]
urlpatterns = [
path("comments/", include(comments_url_patterns)),
path("likes/", include(likes_url_patterns)),
]
from django.urls import path, include
from meals import views
from rest_framework.urlpatterns import format_suffix_patterns
from rest_framework_simplejwt.views import (
TokenObtainPairView,
TokenRefreshView,
)
# This is messy and should be refactored
meal_url_patterns = [
path("",
views.MealList.as_view(),
name="meal-list"),
path(
"<int:pk>/",
views.MealDetail.as_view(),
name="meal-detail",
),
]
meal_files_url_patterns = [
path(
"",
views.MealFileList.as_view(),
name="meal-file-list",
),
path(
"<int:pk>/",
views.MealFileDetail.as_view(),
name="mealfile-detail",
),
]
urlpatterns = format_suffix_patterns(
[
path("", views.api_root),
path("api/meals/", views.MealList.as_view(), name="meal-list"),
path(
"api/meals/<int:pk>/",
views.MealDetail.as_view(),
name="meal-detail",
),
path(
"api/meal-files/",
views.MealFileList.as_view(),
name="meal-file-list",
),
path(
"api/meal-files/<int:pk>/",
views.MealFileDetail.as_view(),
name="mealfile-detail",
),
path("", include("users.urls")),
path("meals/", include(meal_url_patterns)),
path("meal-files/", include(meal_files_url_patterns)),
]
)
......@@ -30,20 +30,6 @@ import base64
import pickle
from django.core.signing import Signer
@api_view(["GET"])
def api_root(request, format=None):
return Response(
{
"users": reverse("user-list", request=request, format=format),
"meals": reverse("meal-list", request=request, format=format),
"meal-files": reverse(
"meal-file-list", request=request, format=format
),
}
)
class MealList(
mixins.ListModelMixin, mixins.CreateModelMixin, generics.GenericAPIView
):
......
......@@ -17,12 +17,41 @@ from django.contrib import admin
from django.urls import path, include
from django.conf import settings
from django.conf.urls.static import static
from workouts import views
from rest_framework_simplejwt.views import (
TokenObtainPairView,
TokenRefreshView,
)
urlpatterns = [
path("admin/", admin.site.urls),
api_url_patterns = [
path("", include("workouts.urls")),
path("", include("users.urls")),
path("", include("comments.urls")),
path("", include("meals.urls")),
]
token_url_patterns = [
path(
"",
TokenObtainPairView.as_view(),
name="token_obtain_pair"),
path(
"refresh/",
TokenRefreshView.as_view(),
name="token_refresh"),
]
urlpatterns = [
path("", views.api_root),
path("admin/", admin.site.urls),
path("api/", include(api_url_patterns)),
path("auth/", include("rest_framework.urls")),
path("token/", include(token_url_patterns)),
path(
"remember_me/",
views.RememberMe.as_view(),
name="remember_me"),
]
urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
from rest_framework.decorators import api_view
from rest_framework.response import Response
from rest_framework.reverse import reverse
@api_view(["GET"])
def api_root(request, format=None):
return Response(
{
"users": reverse("user-list", request=request, format=format),
"meals": reverse("meal-list", request=request, format=format),
"meal-files": reverse(
"meal-file-list", request=request, format=format
),
"workouts": reverse("workout-list", request=request, format=format),
"exercises": reverse("exercise-list", request=request, format=format),
"exercise-instances": reverse(
"exercise-instance-list", request=request, format=format
),
"workout-files": reverse(
"workout-file-list", request=request, format=format
),
"comments": reverse("comment-list", request=request, format=format),
"likes": reverse("like-list", request=request, format=format),
}
)
from django.urls import path, include
from users import views
from rest_framework.urlpatterns import format_suffix_patterns
urlpatterns = [
path("api/usersearch/", views.UserSearch.as_view(), name="user-search"),
path(
"api/uservisibility/<int:pk>/",
views.UserVisibility.as_view(),
name="user-visibility"),
path("api/users/", views.UserList.as_view(), name="user-list"),
users_url_patterns = [
path("", views.UserList.as_view(), name="user-list"),
path(
"api/users/<int:pk>/",
"<int:pk>/",
views.UserDetail.as_view(),
name="user-detail"),
path(
"api/users/<str:username>/",
"<str:username>/",
views.UserDetail.as_view(),
name="user-detail"),
path("api/offers/", views.OfferList.as_view(), name="offer-list"),
]
offers_url_patterns = [
path("",
views.OfferList.as_view(),
name="offer-list"),
path(
"api/offers/<int:pk>/",
"<int:pk>/",
views.OfferDetail.as_view(),
name="offer-detail"),
]
athlete_files_url_patterns = [
path(
"api/athlete-files/", views.AthleteFileList.as_view(), name="athlete-file-list"
"",
views.AthleteFileList.as_view(),
name="athlete-file-list"
),
path(
"api/athlete-files/<int:pk>/",
"<int:pk>/",
views.AthleteFileDetail.as_view(),
name="athletefile-detail",
),
]
urlpatterns = [
path("users/", include(users_url_patterns)),
path("offers/", include(offers_url_patterns)),
path("athelete-files/", include(athlete_files_url_patterns)),
path("usersearch/", views.UserSearch.as_view(), name="user-search"),
path(
"uservisibility/<int:pk>/",
views.UserVisibility.as_view(),
name="user-visibility"),
]
from django.urls import path, include
from workouts import views
from rest_framework.urlpatterns import format_suffix_patterns
from rest_framework_simplejwt.views import (
TokenObtainPairView,
TokenRefreshView,
)
# This is a bit messy and will need to change
workouts_url_patterns = [
path(
"",
views.WorkoutList.as_view(),
name="workout-list"),
path(
"<int:pk>/",
views.WorkoutDetail.as_view(),
name="workout-detail",
),
]
exercises_url_patterns = [
path(
"",
views.ExerciseList.as_view(),
name="exercise-list"),
path(
"<int:pk>/",
views.ExerciseDetail.as_view(),
name="exercise-detail",
),
]
exercise_instances_url_patterns = [
path(
"",
views.ExerciseInstanceList.as_view(),
name="exercise-instance-list",
),
path(
"int:pk>/",
views.ExerciseInstanceDetail.as_view(),
name="exerciseinstance-detail",
),
]
workout_files_url_patterns = [
path(
"",
views.WorkoutFileList.as_view(),
name="workout-file-list",
),
path(
"<int:pk>/",
views.WorkoutFileDetail.as_view(),
name="workoutfile-detail",
),
]
urlpatterns = format_suffix_patterns(
[
path("", views.api_root),
path(
"api/workouts/",
views.WorkoutList.as_view(),
name="workout-list"),
path(
"api/workouts/<int:pk>/",
views.WorkoutDetail.as_view(),
name="workout-detail",
),
path(
"api/exercises/",
views.ExerciseList.as_view(),
name="exercise-list"),
path(
"api/exercises/<int:pk>/",
views.ExerciseDetail.as_view(),
name="exercise-detail",
),
path(
"api/exercise-instances/",
views.ExerciseInstanceList.as_view(),
name="exercise-instance-list",
),
path(
"api/exercise-instances/<int:pk>/",
views.ExerciseInstanceDetail.as_view(),
name="exerciseinstance-detail",
),
path(
"api/workout-files/",
views.WorkoutFileList.as_view(),
name="workout-file-list",
),
path(
"api/workout-files/<int:pk>/",
views.WorkoutFileDetail.as_view(),
name="workoutfile-detail",
),
path("", include("users.urls")),
path("", include("comments.urls")),
path("api/auth/", include("rest_framework.urls")),
path(
"api/token/",
TokenObtainPairView.as_view(),
name="token_obtain_pair"),
path(
"api/token/refresh/",
TokenRefreshView.as_view(),
name="token_refresh"),
path(
"api/remember_me/",
views.RememberMe.as_view(),
name="remember_me"),
path("workouts/", include(workouts_url_patterns)),
path("exercises/", include(exercises_url_patterns)),
path("exercise-instances/", include(exercise_instances_url_patterns)),
path("workout-files/", include(workout_files_url_patterns)),
]
)
......@@ -6,9 +6,7 @@ from rest_framework import permissions
from rest_framework.parsers import (
JSONParser,
)
from rest_framework.decorators import api_view
from rest_framework.response import Response
from rest_framework.reverse import reverse
from django.db.models import Q
from rest_framework import filters
from workouts.parsers import MultipartJsonParser
......@@ -29,32 +27,12 @@ from workouts.serializers import ExerciseInstanceSerializer, WorkoutFileSerializ
from django.core.exceptions import PermissionDenied
from rest_framework_simplejwt.tokens import RefreshToken
from rest_framework.response import Response
import json
from collections import namedtuple
import base64
import pickle
from django.core.signing import Signer
@api_view(["GET"])
def api_root(request, format=None):
return Response(
{
"users": reverse("user-list", request=request, format=format),
"workouts": reverse("workout-list", request=request, format=format),
"exercises": reverse("exercise-list", request=request, format=format),
"exercise-instances": reverse(
"exercise-instance-list", request=request, format=format
),
"workout-files": reverse(
"workout-file-list", request=request, format=format
),
"comments": reverse("comment-list", request=request, format=format),
"likes": reverse("like-list", request=request, format=format),
}
)
# Allow users to save a persistent session in their browser
class RememberMe(
mixins.ListModelMixin,
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment