Skip to content

Commit 2e36122

Browse files
authored
Merge pull request #740 from Nickatak/refactor/views-explicit
refactor: Convert single-purpose views to function-based views
2 parents 79db344 + c13308c commit 2e36122

3 files changed

Lines changed: 222 additions & 78 deletions

File tree

backend/ctj_api/urls.py

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,21 @@
11
"""URL routing for the CTJ API; mounted at `/api/` from `backend.urls`.
22
3-
Five resource routers are auto-registered via DRF's `DefaultRouter`,
4-
which generates standard list/detail paths for each ViewSet.
5-
Two explicit `path()` entries (`healthcheck` and `users/<uuid>/`)
6-
sit alongside, and a catch-all `re_path` at the end returns a JSON
7-
404 (via `api_not_found`) for anything else under `/api/*`.
3+
One resource (`opportunities`) is auto-routed via DRF's
4+
`DefaultRouter` because it's a full-CRUD `ModelViewSet`. Every
5+
other endpoint is an explicit `path()` entry pointing at a
6+
function-based view (see `ctj_api.views` for the shape rule):
7+
8+
- `healthcheck`: the liveness endpoint.
9+
- `users/<uuid>/`: the per-user detail FBV.
10+
- `communityOfPractice/`, `roles/`, `skills/`, `projects/`:
11+
list + detail FBV pairs for read-only catalog resources.
12+
13+
A catch-all `re_path` at the end returns a JSON 404 (via
14+
`api_not_found`) for anything else under `/api/*`.
815
916
Order matters: the catch-all is last; if it moved up, it would
10-
match before the explicit paths and shadow them.
17+
match before the explicit paths and shadow them. The router
18+
include sits before the catch-all for the same reason.
1119
"""
1220

1321
from django.urls import include, path, re_path
@@ -17,15 +25,22 @@
1725

1826
router = DefaultRouter()
1927
router.register(r"opportunities", views.OpportunityViewSet)
20-
router.register(r"communityOfPractice", views.CommunityOfPracticeViewSet)
21-
router.register(r"roles", views.RoleViewSet)
22-
router.register(r"skills", views.SkillViewSet)
23-
router.register(r"projects", views.ProjectViewSet)
2428

2529
urlpatterns = [
2630
path("healthcheck", views.healthcheck, name="healthcheck"),
31+
path("users/<uuid:pk>/", views.user_detail),
32+
path("communityOfPractice/", views.community_of_practice_list),
33+
path(
34+
"communityOfPractice/<uuid:pk>/",
35+
views.community_of_practice_detail,
36+
),
37+
path("roles/", views.role_list),
38+
path("roles/<uuid:pk>/", views.role_detail),
39+
path("skills/", views.skill_list),
40+
path("skills/<uuid:pk>/", views.skill_detail),
41+
path("projects/", views.project_list),
42+
path("projects/<uuid:pk>/", views.project_detail),
2743
re_path(r"^", include(router.urls)),
28-
path("users/<uuid:pk>/", views.UserDetail.as_view()),
2944
# Catch-all for incorrect API routes
3045
re_path(r"^.*$", views.api_not_found),
3146
]

0 commit comments

Comments
 (0)