Skip to content

Commit 3001bfb

Browse files
authored
implement new endpoint to get vin profile info (#287)
1 parent 45e70f7 commit 3001bfb

7 files changed

Lines changed: 269 additions & 8 deletions

File tree

docs/docs.go

Lines changed: 61 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,12 +208,12 @@ const docTemplate = `{
208208
"tags": [
209209
"device-definitions"
210210
],
211-
"summary": "gets a device definition, optionally from tableland (on-chain records) if use an mmy style id.",
211+
"summary": "gets a device definition, from tableland on-chain records. Only support mmy style id's eg. ford_escape_2025",
212212
"operationId": "GetDeviceDefinitionByID",
213213
"parameters": [
214214
{
215215
"type": "string",
216-
"description": "device definition id or mmy definition_id eg. ford_escape_2020",
216+
"description": "mmy definition_id eg. ford_escape_2020",
217217
"name": "id",
218218
"in": "path",
219219
"required": true
@@ -226,6 +226,9 @@ const docTemplate = `{
226226
"$ref": "#/definitions/github_com_DIMO-Network_device-definitions-api_internal_core_models.DeviceDefinitionTablelandModel"
227227
}
228228
},
229+
"400": {
230+
"description": "Bad Request"
231+
},
229232
"404": {
230233
"description": "Not Found"
231234
},
@@ -393,6 +396,45 @@ const docTemplate = `{
393396
}
394397
}
395398
}
399+
},
400+
"/vin-profile/{vin}": {
401+
"get": {
402+
"description": "gets VIN profile if we have it.",
403+
"produces": [
404+
"application/json"
405+
],
406+
"tags": [
407+
"device-definitions"
408+
],
409+
"summary": "gets any raw profile info we have on previously decoded VINs. USA Only.",
410+
"operationId": "VINProfile",
411+
"parameters": [
412+
{
413+
"type": "string",
414+
"description": "17 character usa based VIN eg. WBA12345678901234",
415+
"name": "vin",
416+
"in": "path",
417+
"required": true
418+
}
419+
],
420+
"responses": {
421+
"200": {
422+
"description": "OK",
423+
"schema": {
424+
"$ref": "#/definitions/github_com_DIMO-Network_device-definitions-api_internal_core_queries.GetVINProfileResponse"
425+
}
426+
},
427+
"400": {
428+
"description": "Bad Request"
429+
},
430+
"404": {
431+
"description": "Not Found"
432+
},
433+
"500": {
434+
"description": "Internal Server Error"
435+
}
436+
}
437+
}
396438
}
397439
},
398440
"definitions": {
@@ -598,6 +640,23 @@ const docTemplate = `{
598640
}
599641
}
600642
},
643+
"github_com_DIMO-Network_device-definitions-api_internal_core_queries.GetVINProfileResponse": {
644+
"type": "object",
645+
"properties": {
646+
"profileRaw": {
647+
"type": "array",
648+
"items": {
649+
"type": "integer"
650+
}
651+
},
652+
"vendor": {
653+
"type": "string"
654+
},
655+
"vin": {
656+
"type": "string"
657+
}
658+
}
659+
},
601660
"internal_api_handlers.DecodeVINRequest": {
602661
"type": "object",
603662
"properties": {

docs/swagger.json

Lines changed: 61 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,12 +199,12 @@
199199
"tags": [
200200
"device-definitions"
201201
],
202-
"summary": "gets a device definition, optionally from tableland (on-chain records) if use an mmy style id.",
202+
"summary": "gets a device definition, from tableland on-chain records. Only support mmy style id's eg. ford_escape_2025",
203203
"operationId": "GetDeviceDefinitionByID",
204204
"parameters": [
205205
{
206206
"type": "string",
207-
"description": "device definition id or mmy definition_id eg. ford_escape_2020",
207+
"description": "mmy definition_id eg. ford_escape_2020",
208208
"name": "id",
209209
"in": "path",
210210
"required": true
@@ -217,6 +217,9 @@
217217
"$ref": "#/definitions/github_com_DIMO-Network_device-definitions-api_internal_core_models.DeviceDefinitionTablelandModel"
218218
}
219219
},
220+
"400": {
221+
"description": "Bad Request"
222+
},
220223
"404": {
221224
"description": "Not Found"
222225
},
@@ -384,6 +387,45 @@
384387
}
385388
}
386389
}
390+
},
391+
"/vin-profile/{vin}": {
392+
"get": {
393+
"description": "gets VIN profile if we have it.",
394+
"produces": [
395+
"application/json"
396+
],
397+
"tags": [
398+
"device-definitions"
399+
],
400+
"summary": "gets any raw profile info we have on previously decoded VINs. USA Only.",
401+
"operationId": "VINProfile",
402+
"parameters": [
403+
{
404+
"type": "string",
405+
"description": "17 character usa based VIN eg. WBA12345678901234",
406+
"name": "vin",
407+
"in": "path",
408+
"required": true
409+
}
410+
],
411+
"responses": {
412+
"200": {
413+
"description": "OK",
414+
"schema": {
415+
"$ref": "#/definitions/github_com_DIMO-Network_device-definitions-api_internal_core_queries.GetVINProfileResponse"
416+
}
417+
},
418+
"400": {
419+
"description": "Bad Request"
420+
},
421+
"404": {
422+
"description": "Not Found"
423+
},
424+
"500": {
425+
"description": "Internal Server Error"
426+
}
427+
}
428+
}
387429
}
388430
},
389431
"definitions": {
@@ -589,6 +631,23 @@
589631
}
590632
}
591633
},
634+
"github_com_DIMO-Network_device-definitions-api_internal_core_queries.GetVINProfileResponse": {
635+
"type": "object",
636+
"properties": {
637+
"profileRaw": {
638+
"type": "array",
639+
"items": {
640+
"type": "integer"
641+
}
642+
},
643+
"vendor": {
644+
"type": "string"
645+
},
646+
"vin": {
647+
"type": "string"
648+
}
649+
}
650+
},
592651
"internal_api_handlers.DecodeVINRequest": {
593652
"type": "object",
594653
"properties": {

docs/swagger.yaml

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,17 @@ definitions:
131131
year:
132132
type: integer
133133
type: object
134+
github_com_DIMO-Network_device-definitions-api_internal_core_queries.GetVINProfileResponse:
135+
properties:
136+
profileRaw:
137+
items:
138+
type: integer
139+
type: array
140+
vendor:
141+
type: string
142+
vin:
143+
type: string
144+
type: object
134145
internal_api_handlers.DecodeVINRequest:
135146
properties:
136147
countryCode:
@@ -177,7 +188,7 @@ paths:
177188
description: gets a device definition
178189
operationId: GetDeviceDefinitionByID
179190
parameters:
180-
- description: device definition id or mmy definition_id eg. ford_escape_2020
191+
- description: mmy definition_id eg. ford_escape_2020
181192
in: path
182193
name: id
183194
required: true
@@ -189,12 +200,14 @@ paths:
189200
description: OK
190201
schema:
191202
$ref: '#/definitions/github_com_DIMO-Network_device-definitions-api_internal_core_models.DeviceDefinitionTablelandModel'
203+
"400":
204+
description: Bad Request
192205
"404":
193206
description: Not Found
194207
"500":
195208
description: Internal Server Error
196-
summary: gets a device definition, optionally from tableland (on-chain records)
197-
if use an mmy style id.
209+
summary: gets a device definition, from tableland on-chain records. Only support
210+
mmy style id's eg. ford_escape_2025
198211
tags:
199212
- device-definitions
200213
/device-definitions/decode-vin:
@@ -409,6 +422,32 @@ paths:
409422
(on-chain records)
410423
tags:
411424
- device-definitions
425+
/vin-profile/{vin}:
426+
get:
427+
description: gets VIN profile if we have it.
428+
operationId: VINProfile
429+
parameters:
430+
- description: 17 character usa based VIN eg. WBA12345678901234
431+
in: path
432+
name: vin
433+
required: true
434+
type: string
435+
produces:
436+
- application/json
437+
responses:
438+
"200":
439+
description: OK
440+
schema:
441+
$ref: '#/definitions/github_com_DIMO-Network_device-definitions-api_internal_core_queries.GetVINProfileResponse'
442+
"400":
443+
description: Bad Request
444+
"404":
445+
description: Not Found
446+
"500":
447+
description: Internal Server Error
448+
summary: gets any raw profile info we have on previously decoded VINs. USA Only.
449+
tags:
450+
- device-definitions
412451
securityDefinitions:
413452
BearerAuth:
414453
in: header

internal/api/api.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ func Run(ctx context.Context, logger zerolog.Logger, settings *config.Settings,
131131
mediator.WithHandler(&queries.GetAllDeviceDefinitionByAutocompleteQuery{}, queries.NewGetAllDeviceDefinitionByAutocompleteQueryHandler(searchService)),
132132
mediator.WithHandler(&queries.GetCompatibilityR1SheetQuery{}, queries.NewCompatibilityR1SheetQueryHandler(settings)),
133133
mediator.WithHandler(&queries.GetDeviceDefinitionByIDQueryV2{}, queries.NewGetDeviceDefinitionByIDQueryV2Handler(ddOnChainService, pdb.DBS)),
134+
mediator.WithHandler(&queries.GetVINProfileQuery{}, queries.NewGetVINProfileQueryHandler(pdb.DBS, &logger)),
134135
)
135136

136137
//fiber

internal/api/handlers/device_definition_handler.go

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
package handlers
22

33
import (
4-
"github.com/DIMO-Network/device-definitions-api/internal/api/common"
54
"strconv"
65
"strings"
76

7+
"github.com/DIMO-Network/device-definitions-api/internal/api/common"
8+
89
p_grpc "github.com/DIMO-Network/device-definitions-api/pkg/grpc"
910

1011
"github.com/DIMO-Network/device-definitions-api/internal/core/mediator"
@@ -94,6 +95,45 @@ func GetDeviceDefinitionByID(m mediator.Mediator) fiber.Handler {
9495
}
9596
}
9697

98+
// VINProfile godoc
99+
// @Summary gets any raw profile info we have on previously decoded VINs. USA Only.
100+
// @ID VINProfile
101+
// @Description gets VIN profile if we have it.
102+
// @Tags device-definitions
103+
// @Param vin path string true "17 character usa based VIN eg. WBA12345678901234"
104+
// @Produce json
105+
// @Success 200 {object} queries.GetVINProfileResponse
106+
// @Failure 404
107+
// @Failure 400
108+
// @Failure 500
109+
// @Router /vin-profile/{vin} [get]
110+
func VINProfile(m mediator.Mediator) fiber.Handler {
111+
return func(c *fiber.Ctx) error {
112+
vin := c.Params("vin")
113+
// make sure it is mmy style dd id
114+
if len(vin) != 17 {
115+
return c.Status(fiber.StatusBadRequest).JSON(common.ProblemDetails{
116+
Type: "https://tools.ietf.org/html/rfc7231#section-6.5.1",
117+
Title: "invalid VIN format",
118+
Status: fiber.StatusBadRequest,
119+
Detail: "Only USA style VINs supported 17 characters long.",
120+
})
121+
}
122+
123+
query := &queries.GetVINProfileQuery{VIN: vin}
124+
result, err := m.Send(c.UserContext(), query)
125+
if err != nil {
126+
return c.Status(fiber.StatusNotFound).JSON(common.ProblemDetails{
127+
Type: "https://tools.ietf.org/html/rfc7231#section-6.5.1",
128+
Title: "No VIN profile founder",
129+
Status: fiber.StatusNotFound,
130+
Detail: "Couldn't get VIN profile.",
131+
})
132+
}
133+
return c.Status(fiber.StatusOK).JSON(result)
134+
}
135+
}
136+
97137
// GetR1CompatibilitySearch godoc
98138
// @Summary gets r1 MMY compatibility by search filter
99139
// @ID GetR1CompatibilitySearch

internal/api/routes.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ func RegisterDeviceDefinitionsRoutes(app fiber.Router, m mediator.Mediator, auth
2121
app.Get("/manufacturers/integrations/smartcar", handlers.GetSmartcarManufacturers()).Name("device-definitions-smartcar")
2222

2323
app.Post("/device-definitions/decode-vin", auth, handlers.DecodeVIN(m)).Name("device-definitions-decode-vin")
24+
25+
app.Get("/vin-profile/:vin", auth, handlers.VINProfile(m)).Name("vin-profile")
2426
}
2527

2628
func RegisterIntegrationRoutes(app fiber.Router, m mediator.Mediator) {

0 commit comments

Comments
 (0)