Skip to content

Commit 49e03ce

Browse files
committed
feat: core IoT integration with pairing flow and upload endpoint
- Add database models: Device, PairingSession, AIMetrics - Implement device authentication middleware for secure IoT communication - Build device pairing flow (mobile request → IoT verify → device token) - Create IoT endpoint for uploading run data
1 parent 1777daf commit 49e03ce

File tree

10 files changed

+1108
-0
lines changed

10 files changed

+1108
-0
lines changed

cmd/server/main.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ func main() {
3636
}))
3737

3838
authHandler := handlers.NewAuthHandler(db)
39+
mobileHandler := handlers.NewMobileHandler(db)
40+
iotHandler := handlers.NewIoTHandler(db)
3941

4042
api := r.Group("/api/v1")
4143
{
@@ -58,6 +60,31 @@ func main() {
5860
protectedAuth.GET("/profile", authHandler.GetProfile)
5961
protectedAuth.PUT("/profile", authHandler.UpdateProfile)
6062
}
63+
64+
mobile := api.Group("/mobile")
65+
mobile.Use(middleware.AuthMiddleware())
66+
{
67+
mobile.POST("/pairing/request", mobileHandler.RequestPairingCode)
68+
mobile.GET("/pairing/:session_id/status", mobileHandler.CheckPairingStatus)
69+
70+
mobile.GET("/devices", mobileHandler.GetDevices)
71+
mobile.DELETE("/devices/:device_id", mobileHandler.RemoveDevice)
72+
}
73+
74+
iot := api.Group("/iot")
75+
{
76+
iot.POST("/pairing/verify", iotHandler.VerifyPairingCode)
77+
78+
iotProtected := iot.Group("")
79+
iotProtected.Use(middleware.DeviceAuthMiddleware(db))
80+
{
81+
iotProtected.POST("/runs/upload", iotHandler.UploadRun)
82+
iotProtected.POST("/runs/batch", iotHandler.BatchUploadRuns)
83+
84+
iotProtected.POST("/devices/status", iotHandler.UpdateDeviceStatus)
85+
iotProtected.GET("/devices/config", iotHandler.GetDeviceConfig)
86+
}
87+
}
6188
}
6289

6390

internal/database/migrate.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ import (
88
func Migrate(db *gorm.DB) error {
99
return db.AutoMigrate(
1010
&models.User{},
11+
&models.Device{},
12+
&models.PairingSession{},
1113
&models.Run{},
14+
&models.AIMetrics{},
1215
)
1316
}

0 commit comments

Comments
 (0)