|
1 | 1 | package handlers |
2 | 2 |
|
3 | 3 | import ( |
| 4 | + "github.com/DIMO-Network/device-definitions-api/internal/api/common" |
4 | 5 | "strconv" |
5 | 6 | "strings" |
6 | 7 |
|
@@ -62,31 +63,34 @@ type DecodeVINResponse struct { |
62 | 63 | } |
63 | 64 |
|
64 | 65 | // GetDeviceDefinitionByID godoc |
65 | | -// @Summary gets a device definition, optionally from tableland (on-chain records) if use an mmy style id. |
| 66 | +// @Summary gets a device definition, from tableland on-chain records. Only support mmy style id's eg. ford_escape_2025 |
66 | 67 | // @ID GetDeviceDefinitionByID |
67 | 68 | // @Description gets a device definition |
68 | 69 | // @Tags device-definitions |
69 | | -// @Param id path string true "device definition id or mmy definition_id eg. ford_escape_2020" |
| 70 | +// @Param id path string true "mmy definition_id eg. ford_escape_2020" |
70 | 71 | // @Produce json |
71 | 72 | // @Success 200 {object} models.DeviceDefinitionTablelandModel |
72 | 73 | // @Failure 404 |
| 74 | +// @Failure 400 |
73 | 75 | // @Failure 500 |
74 | 76 | // @Router /device-definitions/{id} [get] |
75 | 77 | func GetDeviceDefinitionByID(m mediator.Mediator) fiber.Handler { |
76 | 78 | return func(c *fiber.Ctx) error { |
77 | 79 | id := c.Params("id") |
78 | | - // check if not ksuid, eg. MMY based definition_id |
| 80 | + // make sure it is mmy style dd id |
79 | 81 | split := strings.Split(id, "_") |
80 | 82 | if len(split) == 3 { |
81 | 83 | query := &queries.GetDeviceDefinitionByIDQueryV2{DefinitionID: id} |
82 | 84 | result, _ := m.Send(c.UserContext(), query) |
83 | 85 | return c.Status(fiber.StatusOK).JSON(result) |
84 | 86 | } |
85 | 87 |
|
86 | | - query := &queries.GetDeviceDefinitionByIDQuery{DeviceDefinitionID: id} |
87 | | - result, _ := m.Send(c.UserContext(), query) |
88 | | - |
89 | | - return c.Status(fiber.StatusOK).JSON(result) |
| 88 | + return c.Status(fiber.StatusBadRequest).JSON(common.ProblemDetails{ |
| 89 | + Type: "https://tools.ietf.org/html/rfc7231#section-6.5.1", |
| 90 | + Title: "invalid id format", |
| 91 | + Status: fiber.StatusBadRequest, |
| 92 | + Detail: "id must be mmy style eg. ford_escape_2025", |
| 93 | + }) |
90 | 94 | } |
91 | 95 | } |
92 | 96 |
|
|
0 commit comments