removed device_id from all entities except car. Replaced with car_id . Car -> device_id

This commit is contained in:
2026-07-16 17:40:59 +04:00
parent 41eaf49bb2
commit f6547cd1f1
18 changed files with 126 additions and 78 deletions
+10
View File
@@ -247,6 +247,7 @@ type CreateCarOptions struct {
ColorHex string
AvatarURL string
Active *bool // optional; defaults to true
DeviceID *int
}
// Validate sanity-checks dimensions and required fields.
@@ -319,6 +320,7 @@ func (s *Service) CreateCar(ctx context.Context, opts CreateCarOptions) (CarMeta
ColorHex: opts.ColorHex,
AvatarURL: opts.AvatarURL,
Active: active,
DeviceID: opts.DeviceID,
CreatedMs: now,
UpdatedMs: now,
}
@@ -345,6 +347,7 @@ type UpdateCarOptions struct {
Motor *MotorSpec
Battery *BatterySpec
Drive *Drivetrain
DeviceID *int // double pointer or *int to clear / set? Let's use *int, but to allow setting to nil (e.g. if we pass -1 or use *int), wait, actually, we can support DeviceID **int or *int. Let's use *int for now or wait, if *int is nil, it means do not update. If they want to set to a device ID, they pass a pointer. Wait! What if they want to clear it? They can pass a pointer to a negative value like -1 or we can use a double pointer. Actually, in Go, *int is very simple. Let's make it *int. If we need to clear, we can pass a device ID of -1 and map it to nil. Let's check how the JSON schema handles it. Usually *int is sufficient. Wait, let's use *int.
}
// UpdateCar applies a partial update.
@@ -403,6 +406,13 @@ func (s *Service) UpdateCar(ctx context.Context, id string, opts UpdateCarOption
if opts.Drive != nil {
c.Drive = *opts.Drive
}
if opts.DeviceID != nil {
if *opts.DeviceID < 0 {
c.DeviceID = nil
} else {
c.DeviceID = opts.DeviceID
}
}
c.UpdatedMs = time.Now().UnixMilli()
if c.LengthMm < minCarLengthMm || c.LengthMm > maxCarLengthMm ||