Skip to content

Commit dfa24c0

Browse files
author
motok822
committed
エンドポイントの修正
1 parent 02dfa07 commit dfa24c0

File tree

8 files changed

+129
-84
lines changed

8 files changed

+129
-84
lines changed

backend/collectmap/urls.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
from django.urls import path, include
1919
from django.http import JsonResponse
2020
from django.db import connection
21+
from rest_framework.routers import DefaultRouter
22+
from paths.views import PathGeometryViewSet
2123

2224

2325
def root(request):
@@ -34,12 +36,16 @@ def health_check(request):
3436
except Exception as e:
3537
return JsonResponse({"status": "unhealthy", "database": "disconnected", "error": str(e)})
3638

39+
# ルート計算用のルーター
40+
route_router = DefaultRouter()
41+
route_router.register(r'', PathGeometryViewSet, basename='route')
3742

3843
urlpatterns = [
3944
path('admin/', admin.site.urls),
4045
path('', root, name='root'),
4146
path('health', health_check, name='health'),
4247
path('mountains/', include('mountains.urls')),
4348
path('paths/', include('paths.urls')),
49+
path('route/', include(route_router.urls)),
4450
path('bear/', include('bear.urls')),
4551
]

backend/docs/openapi.yaml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -349,9 +349,9 @@ paths:
349349
schema:
350350
$ref: '#/components/schemas/PathDetail'
351351
description: ''
352-
/paths/route/:
352+
/route/:
353353
get:
354-
operationId: paths_route_list
354+
operationId: route_list
355355
description: ダイクストラ法でstartノードからdestノードまでの最短経路のPath一覧を取得
356356
parameters:
357357
- in: query
@@ -379,7 +379,7 @@ paths:
379379
description: 開始ノードのnode_id
380380
required: true
381381
tags:
382-
- paths
382+
- route
383383
security:
384384
- cookieAuth: []
385385
- basicAuth: []
@@ -391,9 +391,9 @@ paths:
391391
schema:
392392
$ref: '#/components/schemas/PaginatedPathList'
393393
description: ''
394-
/paths/route/{id}/:
394+
/route/{id}/:
395395
get:
396-
operationId: paths_route_retrieve
396+
operationId: route_retrieve
397397
description: PathGeometry API ViewSet (Read-only) - Dijkstra shortest path
398398
parameters:
399399
- in: path
@@ -403,7 +403,7 @@ paths:
403403
description: A unique integer value identifying this path.
404404
required: true
405405
tags:
406-
- paths
406+
- route
407407
security:
408408
- cookieAuth: []
409409
- basicAuth: []

backend/paths/urls.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
from django.urls import path, include
1+
from django.urls import include, path
22
from rest_framework.routers import DefaultRouter
3+
34
from . import views
45

5-
router = DefaultRouter()
6-
router.register(r'', views.PathViewSet, basename='path')
7-
router.register(r'route', views.PathGeometryViewSet, basename='pathgeometry')
6+
# PathViewSet用のルーター
7+
path_router = DefaultRouter()
8+
path_router.register(r"", views.PathViewSet, basename="path")
89

910
urlpatterns = [
10-
path('', include(router.urls)),
11+
path("", include(path_router.urls)),
1112
]

backend/paths/views.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,16 @@ def list(self, request):
5454
except ValueError:
5555
raise ValidationError("start and dest must be integers")
5656

57+
try:
58+
dest_geom = PathGeometry.objects.get(node_id=dest_node_id)
59+
except PathGeometry.DoesNotExist:
60+
raise NotFound("Destination node not found")
61+
5762
# ノードの存在確認
5863
try:
5964
start_geom = PathGeometry.objects.get(node_id=start_node_id)
60-
dest_geom = PathGeometry.objects.get(node_id=dest_node_id)
6165
except PathGeometry.DoesNotExist:
62-
raise NotFound("Start or destination node not found")
66+
raise NotFound("Start node not found")
6367

6468
# グラフを構築(隣接リスト)
6569
graph = self._build_graph()

frontend/src/app/api/lib/models/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ export * from "./pathUpdatedAt";
102102
export * from "./point";
103103
export * from "./prefecture";
104104
export * from "./prefectureBase";
105+
export * from "./routeListParams";
105106
export * from "./type";
106107
export * from "./validationError";
107108
export * from "./validationErrorLocItem";
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/**
2+
* Generated by orval v7.13.2 🍺
3+
* Do not edit manually.
4+
* Collect Map API
5+
* Django backend for Collect Map API - Mountain and Path data management
6+
* OpenAPI spec version: 1.0.0
7+
*/
8+
9+
export type RouteListParams = {
10+
/**
11+
* 終了ノードのnode_id
12+
*/
13+
dest: number;
14+
/**
15+
* Number of results to return per page.
16+
*/
17+
limit?: number;
18+
/**
19+
* The initial index from which to return the results.
20+
*/
21+
offset?: number;
22+
/**
23+
* 開始ノードのnode_id
24+
*/
25+
start: number;
26+
};

frontend/src/app/api/lib/paths/paths.ts

Lines changed: 0 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,8 @@
99
import { customFetch } from ".././custom-fetch";
1010
import type {
1111
PaginatedPathList,
12-
Path,
1312
PathDetail,
1413
PathsListParams,
15-
PathsRouteListParams,
1614
} from ".././models";
1715

1816
/**
@@ -82,72 +80,3 @@ export const pathsRetrieve = async (
8280
method: "GET",
8381
});
8482
};
85-
86-
/**
87-
* ダイクストラ法でstartノードからdestノードまでの最短経路のPath一覧を取得
88-
*/
89-
export type pathsRouteListResponse200 = {
90-
data: PaginatedPathList;
91-
status: 200;
92-
};
93-
94-
export type pathsRouteListResponseSuccess = pathsRouteListResponse200 & {
95-
headers: Headers;
96-
};
97-
98-
export type pathsRouteListResponse = pathsRouteListResponseSuccess;
99-
100-
export const getPathsRouteListUrl = (params: PathsRouteListParams) => {
101-
const normalizedParams = new URLSearchParams();
102-
103-
Object.entries(params || {}).forEach(([key, value]) => {
104-
if (value !== undefined) {
105-
normalizedParams.append(key, value === null ? "null" : value.toString());
106-
}
107-
});
108-
109-
const stringifiedParams = normalizedParams.toString();
110-
111-
return stringifiedParams.length > 0
112-
? `/paths/route/?${stringifiedParams}`
113-
: `/paths/route/`;
114-
};
115-
116-
export const pathsRouteList = async (
117-
params: PathsRouteListParams,
118-
options?: RequestInit,
119-
): Promise<pathsRouteListResponse> => {
120-
return customFetch<pathsRouteListResponse>(getPathsRouteListUrl(params), {
121-
...options,
122-
method: "GET",
123-
});
124-
};
125-
126-
/**
127-
* PathGeometry API ViewSet (Read-only) - Dijkstra shortest path
128-
*/
129-
export type pathsRouteRetrieveResponse200 = {
130-
data: Path;
131-
status: 200;
132-
};
133-
134-
export type pathsRouteRetrieveResponseSuccess =
135-
pathsRouteRetrieveResponse200 & {
136-
headers: Headers;
137-
};
138-
139-
export type pathsRouteRetrieveResponse = pathsRouteRetrieveResponseSuccess;
140-
141-
export const getPathsRouteRetrieveUrl = (id: number) => {
142-
return `/paths/route/${id}/`;
143-
};
144-
145-
export const pathsRouteRetrieve = async (
146-
id: number,
147-
options?: RequestInit,
148-
): Promise<pathsRouteRetrieveResponse> => {
149-
return customFetch<pathsRouteRetrieveResponse>(getPathsRouteRetrieveUrl(id), {
150-
...options,
151-
method: "GET",
152-
});
153-
};
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/**
2+
* Generated by orval v7.13.2 🍺
3+
* Do not edit manually.
4+
* Collect Map API
5+
* Django backend for Collect Map API - Mountain and Path data management
6+
* OpenAPI spec version: 1.0.0
7+
*/
8+
9+
import { customFetch } from ".././custom-fetch";
10+
import type { PaginatedPathList, Path, RouteListParams } from ".././models";
11+
12+
/**
13+
* ダイクストラ法でstartノードからdestノードまでの最短経路のPath一覧を取得
14+
*/
15+
export type routeListResponse200 = {
16+
data: PaginatedPathList;
17+
status: 200;
18+
};
19+
20+
export type routeListResponseSuccess = routeListResponse200 & {
21+
headers: Headers;
22+
};
23+
24+
export type routeListResponse = routeListResponseSuccess;
25+
26+
export const getRouteListUrl = (params: RouteListParams) => {
27+
const normalizedParams = new URLSearchParams();
28+
29+
Object.entries(params || {}).forEach(([key, value]) => {
30+
if (value !== undefined) {
31+
normalizedParams.append(key, value === null ? "null" : value.toString());
32+
}
33+
});
34+
35+
const stringifiedParams = normalizedParams.toString();
36+
37+
return stringifiedParams.length > 0
38+
? `/route/?${stringifiedParams}`
39+
: `/route/`;
40+
};
41+
42+
export const routeList = async (
43+
params: RouteListParams,
44+
options?: RequestInit,
45+
): Promise<routeListResponse> => {
46+
return customFetch<routeListResponse>(getRouteListUrl(params), {
47+
...options,
48+
method: "GET",
49+
});
50+
};
51+
52+
/**
53+
* PathGeometry API ViewSet (Read-only) - Dijkstra shortest path
54+
*/
55+
export type routeRetrieveResponse200 = {
56+
data: Path;
57+
status: 200;
58+
};
59+
60+
export type routeRetrieveResponseSuccess = routeRetrieveResponse200 & {
61+
headers: Headers;
62+
};
63+
64+
export type routeRetrieveResponse = routeRetrieveResponseSuccess;
65+
66+
export const getRouteRetrieveUrl = (id: number) => {
67+
return `/route/${id}/`;
68+
};
69+
70+
export const routeRetrieve = async (
71+
id: number,
72+
options?: RequestInit,
73+
): Promise<routeRetrieveResponse> => {
74+
return customFetch<routeRetrieveResponse>(getRouteRetrieveUrl(id), {
75+
...options,
76+
method: "GET",
77+
});
78+
};

0 commit comments

Comments
 (0)