feat: добавление нового маршрута /v2/reqphoto для получения фотографий автомобиля по VIN - обновлены запросы в app.py и документация Swagger для улучшения взаимодействия с API

This commit is contained in:
Vlad 2025-05-02 10:59:52 +03:00
parent 0643d8173a
commit 3175dbc0fe
3 changed files with 67 additions and 10 deletions

View File

@ -183,6 +183,66 @@ paths:
type: string
description: Error description
/v2/reqphoto:
post:
summary: Get vehicle photos
description: Get photos of the vehicle by VIN
parameters:
- name: access_code
in: query
required: true
schema:
type: string
description: API access code for authentication
requestBody:
required: true
content:
application/json:
schema:
type: object
properties:
vin:
type: string
description: Vehicle Identification Number
example: "1HGCM82633A123456"
responses:
'200':
description: Successful photo retrieval
content:
application/json:
schema:
type: object
properties:
found:
type: boolean
description: Whether photos were found
photos:
type: array
description: List of photo information
items:
type: object
properties:
url:
type: string
description: URL of the photo
type:
type: string
description: Type of photo (FRONT, REAR, SIDE, INTERIOR, etc.)
date:
type: string
format: date
description: Date when photo was taken
'400':
description: Invalid VIN or access code
content:
application/json:
schema:
type: object
properties:
error:
type: string
description: Error description
/restfact:
get:
summary: Check account balance

13
app.py
View File

@ -701,7 +701,7 @@ def api_reqimage():
app.logger.debug(json.dumps(ret))
return response
cur.execute('select count(*) from salvagedb.salvage_images where vin = :p1 and fnd = 1' , {'p1':vin.upper()})
cur.execute('select count(*) from salvagedb.salvage_images where vin = :p1 and fn = 1' , {'p1':vin.upper()})
res = cur.fetchone()
img_count = int(res[0])
if img_count<1:
@ -715,19 +715,17 @@ def api_reqimage():
app.logger.debug(json.dumps(ret))
return response
else:
#req_id = uuid.uuid4().hex
#cur.execute('select rownum,ipath from salvagedb.salvage_images where vin = :p1 and fnd = 1',{'p1':vin.upper()})
cur.execute("""select GenImages('{}','{}') uid from dual""".format(access_code, vin.upper()))
cur.execute("""select GenImages('{}','{}') as ui from dual""".format(access_code, vin.upper()))
res = cur.fetchall()
req_id = res[0]
cur.execute("""select fake_name from salvage_images_req where req_id = '{}}'""".format(req_id))
req_id = res[0][0]
cur.execute('select fake_name from salvage_images_req where req_id = :p1', {'p1':req_id})
res = cur.fetchall()
images = []
nm = 0
for it in res:
images.append({
'num':nm,
'url':'https://salimages.salvagedb/{}/{}'.format(req_id, it)
'url':'https://salimages.salvagedb/{}/{}'.format(req_id, it[0])
})
nm = nm + 1
ret = {'status': 'Image_found', 'Images':images}
@ -736,6 +734,7 @@ def api_reqimage():
status=200,
mimetype='application/json'
)
return response

View File

@ -14,11 +14,10 @@
</div>
<br><br>
<div class="table-container">
<div class="table-container" style="display: flex; justify-content: center;">
<table id="hor-minimalist-a" summary="Salvage cars;Database page 1">
<thead>
<tr>
<th>#</th>
<th>VIN</th>
<th>Make</th>
<th>Model</th>
@ -28,7 +27,6 @@
<tbody>
{% for row in pg %}
<tr>
<td>{{ row[0] }}</td>
<td><a href="/detail/{{ row[1] }}.html">{{ row[1] }}</a></td>
<td>{{ row[2] }}</td>
<td>{{ row[3] }}</td>