rex_app/views/
activity_view.rs1use anyhow::Result;
2use chrono::NaiveDate;
3use rex_db::ConnCache;
4pub use rex_db::models::FullActivityTx;
5use rex_db::models::{Activity, ActivityNature, ActivityWithTxs};
6
7pub struct ActivityView(Vec<ActivityWithTxs>);
8
9pub(crate) fn get_activity_view(
10 date: NaiveDate,
11 conn: &mut impl ConnCache,
12) -> Result<ActivityView> {
13 let activities = Activity::get_activities(date, conn)?;
14
15 Ok(ActivityView(activities))
16}
17
18impl ActivityView {
19 #[must_use]
20 pub fn total_activity(&self) -> usize {
21 self.0.len()
22 }
23
24 #[must_use]
25 pub fn get_activity_table(&self) -> Vec<Vec<String>> {
26 self.0.iter().map(|a| a.activity.to_array()).collect()
27 }
28
29 #[must_use]
30 pub fn is_empty(&self) -> bool {
31 self.0.is_empty()
32 }
33
34 #[must_use]
35 pub fn get_activity_txs_table(&self, index: Option<usize>) -> Vec<Vec<String>> {
36 let Some(index) = index else {
37 return Vec::new();
38 };
39
40 let target_activity = self.0.get(index).unwrap();
41
42 target_activity.to_array()
43 }
44
45 #[must_use]
46 pub fn add_extra_field(&self, index: usize) -> bool {
47 let target_activity = self.0.get(index).unwrap();
48
49 matches!(
50 target_activity.activity.activity_type.as_str().into(),
51 ActivityNature::EditTx | ActivityNature::PositionSwap
52 )
53 }
54
55 #[must_use]
56 pub fn get_activity_txs(&self, index: usize) -> Vec<&FullActivityTx> {
57 self.0.get(index).unwrap().txs.iter().collect()
58 }
59}