Skip to content

Commit

Permalink
Merge pull request #4 from machinefi/device-http-api
Browse files Browse the repository at this point in the history
device confirm http api
  • Loading branch information
huangzhiran authored Aug 28, 2024
2 parents 85cc7ec + fedfe81 commit 60a6043
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions cmd/sequencer/api/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package api

import (
"context"
"io"
"log/slog"
"net/http"
"strings"
Expand Down Expand Up @@ -84,8 +85,23 @@ func (s *httpServer) verifyToken(c *gin.Context) {
}

func (s *httpServer) confirmDevice(c *gin.Context) {
//imei := c.Param("imei")

imei := c.Param("imei")
data, err := io.ReadAll(c.Request.Body)
if err != nil {
c.JSON(http.StatusBadRequest, apitypes.NewErrRsp(errors.Wrap(err, "failed to read request body")))
return
}
e := &event.DeviceConfirm{}
if err := e.Unmarshal(data); err != nil {
c.JSON(http.StatusBadRequest, apitypes.NewErrRsp(errors.Wrap(err, "failed to unmarshal request body")))
return
}
e.Imei = imei
if err := e.Handle(s.ctx); err != nil {
c.JSON(http.StatusInternalServerError, apitypes.NewErrRsp(errors.Wrap(err, "failed to confirm device")))
return
}
c.Status(http.StatusOK)
}

func (s *httpServer) queryDeviceState(c *gin.Context) {
Expand Down

0 comments on commit 60a6043

Please sign in to comment.