| 241 | } |
| 242 | |
| 243 | pub async fn update(gw: Gateway) -> Result<Gateway, Error> { |
| 244 | gw.validate()?; |
| 245 | |
| 246 | let gw: Gateway = diesel::update(gateway::dsl::gateway.find(&gw.gateway_id)) |
| 247 | .set(( |
| 248 | gateway::updated_at.eq(Utc::now()), |
| 249 | gateway::name.eq(&gw.name), |
| 250 | gateway::description.eq(&gw.description), |
| 251 | gateway::latitude.eq(&gw.latitude), |
| 252 | gateway::longitude.eq(&gw.longitude), |
| 253 | gateway::altitude.eq(&gw.altitude), |
| 254 | gateway::stats_interval_secs.eq(&gw.stats_interval_secs), |
| 255 | gateway::tags.eq(&gw.tags), |
| 256 | gateway::downlink_priority.eq(&gw.downlink_priority), |
| 257 | )) |
| 258 | .get_result(&mut get_async_db_conn().await?) |
| 259 | .await |
| 260 | .map_err(|e| Error::from_diesel(e, gw.gateway_id.to_string()))?; |
| 261 | info!( |
| 262 | gateway_id = %gw.gateway_id, |
| 263 | "Gateway updated" |
| 264 | ); |
| 265 | Ok(gw) |
| 266 | } |
| 267 | |
| 268 | pub async fn partial_update(gateway_id: EUI64, gw: &GatewayChangeset) -> Result<Gateway, Error> { |
| 269 | let gw = diesel::update(gateway::dsl::gateway.find(&gateway_id)) |