|
1 | 1 | package handlers |
2 | 2 |
|
3 | 3 | import ( |
4 | | - "github.com/DIMO-Network/device-definitions-api/internal/api/common" |
5 | 4 | "strconv" |
6 | 5 | "strings" |
7 | 6 |
|
| 7 | + "github.com/DIMO-Network/device-definitions-api/internal/api/common" |
| 8 | + |
8 | 9 | p_grpc "github.com/DIMO-Network/device-definitions-api/pkg/grpc" |
9 | 10 |
|
10 | 11 | "github.com/DIMO-Network/device-definitions-api/internal/core/mediator" |
@@ -94,6 +95,45 @@ func GetDeviceDefinitionByID(m mediator.Mediator) fiber.Handler { |
94 | 95 | } |
95 | 96 | } |
96 | 97 |
|
| 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 | + |
97 | 137 | // GetR1CompatibilitySearch godoc |
98 | 138 | // @Summary gets r1 MMY compatibility by search filter |
99 | 139 | // @ID GetR1CompatibilitySearch |
|
0 commit comments