feat(iot): PATCH обновляет metadata (Terraform)
iotDeviceUpdateRequest получил поле metadata; UpdateIoTDevice обновляет переданные поля (enabled и/или metadata). Добавлен store.UpdateMetadata. Хотя бы одно поле обязательно. Раньше metadata нельзя было изменить (только enabled).
This commit is contained in:
@@ -97,6 +97,24 @@ func (s *DeviceStore) UpdateEnabled(ctx context.Context, namespace, name string,
|
||||
return nil
|
||||
}
|
||||
|
||||
// UpdateMetadata обновляет metadata устройства.
|
||||
func (s *DeviceStore) UpdateMetadata(ctx context.Context, namespace, name string, metadata map[string]string) error {
|
||||
b, err := json.Marshal(metadata)
|
||||
if err != nil {
|
||||
return fmt.Errorf("store: marshal metadata: %w", err)
|
||||
}
|
||||
res, err := s.db.ExecContext(ctx,
|
||||
`UPDATE iot_devices SET metadata = $3 WHERE namespace = $1 AND name = $2`,
|
||||
namespace, name, b)
|
||||
if err != nil {
|
||||
return fmt.Errorf("store: update metadata: %w", err)
|
||||
}
|
||||
if n, _ := res.RowsAffected(); n == 0 {
|
||||
return ErrNotFound
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Delete удаляет устройство.
|
||||
func (s *DeviceStore) Delete(ctx context.Context, namespace, name string) error {
|
||||
res, err := s.db.ExecContext(ctx,
|
||||
|
||||
Reference in New Issue
Block a user