|
| 1 | +// rustfmt-max_width: 140 |
| 2 | + |
| 3 | +impl NotificationRepository { |
| 4 | + fn set_status_changed( |
| 5 | + &self, |
| 6 | + repo_tx_conn: &RepoTxConn, |
| 7 | + rid: &RoutableId, |
| 8 | + changed_at: NaiveDateTime, |
| 9 | + ) -> NukeResult<Option<NotificationStatus>> { |
| 10 | + repo_tx_conn.run(move |conn| { |
| 11 | + let res = diesel::update(client_notification::table) |
| 12 | + .filter( |
| 13 | + client_notification::routable_id.eq(DieselRoutableId(rid.clone())).and( |
| 14 | + client_notification::changed_at |
| 15 | + .lt(changed_at) |
| 16 | + .or(client_notification::changed_at.is_null()), |
| 17 | + ), |
| 18 | + ) |
| 19 | + .set(client_notification::changed_at.eq(changed_at)) |
| 20 | + .returning(( |
| 21 | + client_notification::id, |
| 22 | + client_notification::changed_at, |
| 23 | + client_notification::polled_at, |
| 24 | + client_notification::notified_at, |
| 25 | + )) |
| 26 | + .get_result::<(Uuid, Option<NaiveDateTime>, Option<NaiveDateTime>, Option<NaiveDateTime>)>(conn) |
| 27 | + .optional()?; |
| 28 | + |
| 29 | + match res { |
| 30 | + Some(row) => { |
| 31 | + let client_id = client_contract::table |
| 32 | + .inner_join(client_notification::table) |
| 33 | + .filter(client_notification::id.eq(row.0)) |
| 34 | + .select(client_contract::client_id) |
| 35 | + .get_result::<Uuid>(conn)?; |
| 36 | + |
| 37 | + Ok(Some(NotificationStatus { |
| 38 | + client_id: client_id.into(), |
| 39 | + changed_at: row.1, |
| 40 | + polled_at: row.2, |
| 41 | + notified_at: row.3, |
| 42 | + })) |
| 43 | + } |
| 44 | + None => Ok(None), |
| 45 | + } |
| 46 | + }) |
| 47 | + } |
| 48 | +} |
0 commit comments