34
34
from stapi_fastapi .models .shared import Link
35
35
from stapi_fastapi .responses import GeoJSONResponse
36
36
from stapi_fastapi .routers .product_router import ProductRouter
37
+ from stapi_fastapi .routers .route_names import (
38
+ CONFORMANCE ,
39
+ GET_OPPORTUNITY_SEARCH_RECORD ,
40
+ GET_ORDER ,
41
+ LIST_OPPORTUNITY_SEARCH_RECORDS ,
42
+ LIST_ORDER_STATUSES ,
43
+ LIST_ORDERS ,
44
+ LIST_PRODUCTS ,
45
+ ROOT ,
46
+ )
37
47
38
48
logger = logging .getLogger (__name__ )
39
49
@@ -84,31 +94,31 @@ def __init__(
84
94
"/" ,
85
95
self .get_root ,
86
96
methods = ["GET" ],
87
- name = f"{ self .name } :root " ,
97
+ name = f"{ self .name } :{ ROOT } " ,
88
98
tags = ["Root" ],
89
99
)
90
100
91
101
self .add_api_route (
92
102
"/conformance" ,
93
103
self .get_conformance ,
94
104
methods = ["GET" ],
95
- name = f"{ self .name } :conformance " ,
105
+ name = f"{ self .name } :{ CONFORMANCE } " ,
96
106
tags = ["Conformance" ],
97
107
)
98
108
99
109
self .add_api_route (
100
110
"/products" ,
101
111
self .get_products ,
102
112
methods = ["GET" ],
103
- name = f"{ self .name } :list-products " ,
113
+ name = f"{ self .name } :{ LIST_PRODUCTS } " ,
104
114
tags = ["Products" ],
105
115
)
106
116
107
117
self .add_api_route (
108
118
"/orders" ,
109
119
self .get_orders ,
110
120
methods = ["GET" ],
111
- name = f"{ self .name } :list-orders " ,
121
+ name = f"{ self .name } :{ LIST_ORDERS } " ,
112
122
response_class = GeoJSONResponse ,
113
123
tags = ["Orders" ],
114
124
)
@@ -117,7 +127,7 @@ def __init__(
117
127
"/orders/{order_id}" ,
118
128
self .get_order ,
119
129
methods = ["GET" ],
120
- name = f"{ self .name } :get-order " ,
130
+ name = f"{ self .name } :{ GET_ORDER } " ,
121
131
response_class = GeoJSONResponse ,
122
132
tags = ["Orders" ],
123
133
)
@@ -126,7 +136,7 @@ def __init__(
126
136
"/orders/{order_id}/statuses" ,
127
137
self .get_order_statuses ,
128
138
methods = ["GET" ],
129
- name = f"{ self .name } :list-order-statuses " ,
139
+ name = f"{ self .name } :{ LIST_ORDER_STATUSES } " ,
130
140
tags = ["Orders" ],
131
141
)
132
142
@@ -135,7 +145,7 @@ def __init__(
135
145
"/searches/opportunities" ,
136
146
self .get_opportunity_search_records ,
137
147
methods = ["GET" ],
138
- name = f"{ self .name } :list-opportunity-search-records " ,
148
+ name = f"{ self .name } :{ LIST_OPPORTUNITY_SEARCH_RECORDS } " ,
139
149
summary = "List all Opportunity Search Records" ,
140
150
tags = ["Opportunities" ],
141
151
)
@@ -144,15 +154,15 @@ def __init__(
144
154
"/searches/opportunities/{search_record_id}" ,
145
155
self .get_opportunity_search_record ,
146
156
methods = ["GET" ],
147
- name = f"{ self .name } :get-opportunity-search-record " ,
157
+ name = f"{ self .name } :{ GET_OPPORTUNITY_SEARCH_RECORD } " ,
148
158
summary = "Get an Opportunity Search Record by ID" ,
149
159
tags = ["Opportunities" ],
150
160
)
151
161
152
162
def get_root (self , request : Request ) -> RootResponse :
153
163
links = [
154
164
Link (
155
- href = str (request .url_for (f"{ self .name } :root " )),
165
+ href = str (request .url_for (f"{ self .name } :{ ROOT } " )),
156
166
rel = "self" ,
157
167
type = TYPE_JSON ,
158
168
),
@@ -167,17 +177,17 @@ def get_root(self, request: Request) -> RootResponse:
167
177
type = "text/html" ,
168
178
),
169
179
Link (
170
- href = str (request .url_for (f"{ self .name } :conformance " )),
180
+ href = str (request .url_for (f"{ self .name } :{ CONFORMANCE } " )),
171
181
rel = "conformance" ,
172
182
type = TYPE_JSON ,
173
183
),
174
184
Link (
175
- href = str (request .url_for (f"{ self .name } :list-products " )),
185
+ href = str (request .url_for (f"{ self .name } :{ LIST_PRODUCTS } " )),
176
186
rel = "products" ,
177
187
type = TYPE_JSON ,
178
188
),
179
189
Link (
180
- href = str (request .url_for (f"{ self .name } :list-orders " )),
190
+ href = str (request .url_for (f"{ self .name } :{ LIST_ORDERS } " )),
181
191
rel = "orders" ,
182
192
type = TYPE_GEOJSON ,
183
193
),
@@ -187,7 +197,9 @@ def get_root(self, request: Request) -> RootResponse:
187
197
links .append (
188
198
Link (
189
199
href = str (
190
- request .url_for (f"{ self .name } :list-opportunity-search-records" )
200
+ request .url_for (
201
+ f"{ self .name } :{ LIST_OPPORTUNITY_SEARCH_RECORDS } "
202
+ )
191
203
),
192
204
rel = "opportunity-search-records" ,
193
205
type = TYPE_JSON ,
@@ -220,7 +232,7 @@ def get_products(
220
232
ids = self .product_ids [start :end ]
221
233
links = [
222
234
Link (
223
- href = str (request .url_for (f"{ self .name } :list-products " )),
235
+ href = str (request .url_for (f"{ self .name } :{ LIST_PRODUCTS } " )),
224
236
rel = "self" ,
225
237
type = TYPE_JSON ,
226
238
),
@@ -327,10 +339,10 @@ def add_product(self, product: Product, *args, **kwargs) -> None:
327
339
self .product_ids = [* self .product_routers .keys ()]
328
340
329
341
def generate_order_href (self , request : Request , order_id : str ) -> URL :
330
- return request .url_for (f"{ self .name } :get-order " , order_id = order_id )
342
+ return request .url_for (f"{ self .name } :{ GET_ORDER } " , order_id = order_id )
331
343
332
344
def generate_order_statuses_href (self , request : Request , order_id : str ) -> URL :
333
- return request .url_for (f"{ self .name } :list-order-statuses " , order_id = order_id )
345
+ return request .url_for (f"{ self .name } :{ LIST_ORDER_STATUSES } " , order_id = order_id )
334
346
335
347
def order_links (self , order : Order , request : Request ) -> list [Link ]:
336
348
return [
@@ -350,7 +362,7 @@ def order_statuses_link(self, request: Request, order_id: str):
350
362
return Link (
351
363
href = str (
352
364
request .url_for (
353
- f"{ self .name } :list-order-statuses " ,
365
+ f"{ self .name } :{ LIST_ORDER_STATUSES } " ,
354
366
order_id = order_id ,
355
367
)
356
368
),
@@ -428,7 +440,7 @@ def generate_opportunity_search_record_href(
428
440
self , request : Request , search_record_id : str
429
441
) -> URL :
430
442
return request .url_for (
431
- f"{ self .name } :get-opportunity-search-record " ,
443
+ f"{ self .name } :{ GET_OPPORTUNITY_SEARCH_RECORD } " ,
432
444
search_record_id = search_record_id ,
433
445
)
434
446
0 commit comments