Skip to content

Commit

Permalink
User more constants, get rid of AutoPi language
Browse files Browse the repository at this point in the history
  • Loading branch information
elffjs committed Apr 28, 2024
1 parent 64f97f7 commit 3c54af7
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 23 deletions.
4 changes: 2 additions & 2 deletions cmd/devices-api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,8 @@ func startWebAPI(logger zerolog.Logger, settings *config.Settings, pdb db.Store,
apOwner.Get("/commands/claim", userDeviceController.GetAutoPiClaimMessage)
amdOwner.Get("/commands/claim", userDeviceController.GetAutoPiClaimMessage)

apOwner.Post("/commands/claim", userDeviceController.PostClaimAutoPi).Name("PostClaimAutoPi")
amdOwner.Post("/commands/claim", userDeviceController.PostClaimAutoPi).Name("PostClaimAutoPi")
apOwner.Post("/commands/claim", userDeviceController.PostClaimAftermarketDevice).Name("PostClaimAutoPi")
amdOwner.Post("/commands/claim", userDeviceController.PostClaimAftermarketDevice).Name("PostClaimAutoPi")
if !settings.IsProduction() {
// Used by mobile to test. Easy to misuse.
apOwner.Post("/commands/unclaim", userDeviceController.PostUnclaimAutoPi)
Expand Down
8 changes: 4 additions & 4 deletions docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ const docTemplate = `{
"parameters": [
{
"type": "string",
"description": "AutoPi unit id",
"description": "Device serial number",
"name": "serial",
"in": "path",
"required": true
Expand Down Expand Up @@ -121,7 +121,7 @@ const docTemplate = `{
"parameters": [
{
"type": "string",
"description": "AutoPi unit id",
"description": "Device serial number",
"name": "serial",
"in": "path",
"required": true
Expand All @@ -132,7 +132,7 @@ const docTemplate = `{
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/internal_controllers.AutoPiClaimRequest"
"$ref": "#/definitions/internal_controllers.AftermarketClaimRequest"
}
}
],
Expand Down Expand Up @@ -2608,7 +2608,7 @@ const docTemplate = `{
}
}
},
"internal_controllers.AutoPiClaimRequest": {
"internal_controllers.AftermarketClaimRequest": {
"type": "object",
"properties": {
"aftermarketDeviceSignature": {
Expand Down
8 changes: 4 additions & 4 deletions docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
"parameters": [
{
"type": "string",
"description": "AutoPi unit id",
"description": "Device serial number",
"name": "serial",
"in": "path",
"required": true
Expand Down Expand Up @@ -113,7 +113,7 @@
"parameters": [
{
"type": "string",
"description": "AutoPi unit id",
"description": "Device serial number",
"name": "serial",
"in": "path",
"required": true
Expand All @@ -124,7 +124,7 @@
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/internal_controllers.AutoPiClaimRequest"
"$ref": "#/definitions/internal_controllers.AftermarketClaimRequest"
}
}
],
Expand Down Expand Up @@ -2600,7 +2600,7 @@
}
}
},
"internal_controllers.AutoPiClaimRequest": {
"internal_controllers.AftermarketClaimRequest": {
"type": "object",
"properties": {
"aftermarketDeviceSignature": {
Expand Down
8 changes: 4 additions & 4 deletions docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ definitions:
powertrainType:
$ref: '#/definitions/github_com_DIMO-Network_devices-api_internal_services.PowertrainType'
type: object
internal_controllers.AutoPiClaimRequest:
internal_controllers.AftermarketClaimRequest:
properties:
aftermarketDeviceSignature:
description: AftermarketDeviceSignature is the signature from the aftermarket
Expand Down Expand Up @@ -1014,7 +1014,7 @@ paths:
description: Return the EIP-712 payload to be signed for Aftermarket device
claiming.
parameters:
- description: AutoPi unit id
- description: Device serial number
in: path
name: serial
required: true
Expand All @@ -1032,7 +1032,7 @@ paths:
description: Return the EIP-712 payload to be signed for Aftermarket device
claiming.
parameters:
- description: AutoPi unit id
- description: Device serial number
in: path
name: serial
required: true
Expand All @@ -1042,7 +1042,7 @@ paths:
name: claimRequest
required: true
schema:
$ref: '#/definitions/internal_controllers.AutoPiClaimRequest'
$ref: '#/definitions/internal_controllers.AftermarketClaimRequest'
produces:
- application/json
responses:
Expand Down
18 changes: 9 additions & 9 deletions internal/controllers/user_integrations_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -639,10 +639,10 @@ func (udc *UserDevicesController) StartAutoPiUpdateTask(c *fiber.Ctx) error {
})
}

// GetAutoPiClaimMessage godoc
// GetAftermarketDeviceClaimMessage godoc
// @Description Return the EIP-712 payload to be signed for Aftermarket device claiming.
// @Produce json
// @Param serial path string true "AutoPi unit id"
// @Param serial path string true "Device serial number"
// @Success 200 {object} signer.TypedData
// @Security BearerAuth
// @Router /aftermarket/device/by-serial/:serial/commands/claim [get]
Expand Down Expand Up @@ -1208,7 +1208,7 @@ func (udc *UserDevicesController) GetAutoPiUnpairMessage(c *fiber.Ctx) error {
return c.JSON(out)
}

type AutoPiClaimRequest struct {
type AftermarketClaimRequest struct {
// UserSignature is the signature from the user, using their private key.
UserSignature string `json:"userSignature"`
// AftermarketDeviceSignature is the signature from the aftermarket device.
Expand Down Expand Up @@ -1274,21 +1274,21 @@ func (udc *UserDevicesController) PostUnclaimAutoPi(c *fiber.Ctx) error {
return client.UnclaimAftermarketDeviceNode(requestID, []*big.Int{apToken})
}

// PostClaimAutoPi godoc
// PostClaimAftermarketDevice godoc
// @Description Return the EIP-712 payload to be signed for Aftermarket device claiming.
// @Produce json
// @Param serial path string true "AutoPi unit id"
// @Param claimRequest body controllers.AutoPiClaimRequest true "Signatures from the user and AutoPi"
// @Param serial path string true "Device serial number"
// @Param claimRequest body controllers.AftermarketClaimRequest true "Signatures from the user and AutoPi"
// @Success 204
// @Security BearerAuth
// @Router /aftermarket/device/by-serial/:serial/commands/claim [post]
func (udc *UserDevicesController) PostClaimAutoPi(c *fiber.Ctx) error {
func (udc *UserDevicesController) PostClaimAftermarketDevice(c *fiber.Ctx) error {
userID := helpers.GetUserID(c)
unitID := c.Params("serial")

logger := udc.log.With().Str("userId", userID).Str("serial", unitID).Str("route", c.Route().Name).Logger()

reqBody := AutoPiClaimRequest{}
var reqBody AftermarketClaimRequest
err := c.BodyParser(&reqBody)
if err != nil {
return fiber.NewError(fiber.StatusBadRequest, "Couldn't parse request body.")
Expand Down Expand Up @@ -1317,7 +1317,7 @@ func (udc *UserDevicesController) PostClaimAutoPi(c *fiber.Ctx) error {
return fiber.NewError(fiber.StatusConflict, "Device already claimed.")
}

if unit.R.ClaimMetaTransactionRequest != nil && unit.R.ClaimMetaTransactionRequest.Status != "Failed" {
if unit.R.ClaimMetaTransactionRequest != nil && unit.R.ClaimMetaTransactionRequest.Status != models.MetaTransactionRequestStatusFailed {
return fiber.NewError(fiber.StatusConflict, "Claiming transaction in progress.")
}

Expand Down

0 comments on commit 3c54af7

Please sign in to comment.