Single-binary self-hosted website analytics on Rust axum: collector API, dashboards, world map, and PDF reports.
analyticsaxumdockerrustself-hostedsqliteviteweb-analytics
1use serde::{Deserialize, Serialize};
2use sqlx::FromRow;
3use uuid::Uuid;
4
5#[derive(Debug, Clone, Serialize)]
6pub struct Property {
7 pub id: Uuid,
8 pub name: String,
9 pub custom_cards: Vec<CustomCard>,
10 pub is_protected: bool,
11 pub is_public: bool,
12 pub created_at: i64,
13 pub updated_at: i64,
14}
15
16#[derive(Debug, Clone, Serialize, Deserialize)]
17pub struct CustomCard {
18 pub event: String,
19 #[serde(default)]
20 pub value: bool,
21}
22
23#[derive(Debug, FromRow)]
24pub struct PropertyRow {
25 pub id: Vec<u8>,
26 pub name: String,
27 pub custom_cards: String,
28 pub is_protected: i64,
29 pub is_public: i64,
30 pub created_at: i64,
31 pub updated_at: i64,
32}
33
34impl PropertyRow {
35 pub fn into_property(self) -> Property {
36 let id = Uuid::from_slice(&self.id).unwrap_or_default();
37 let custom_cards: Vec<CustomCard> =
38 serde_json::from_str(&self.custom_cards).unwrap_or_default();
39 Property {
40 id,
41 name: self.name,
42 custom_cards,
43 is_protected: self.is_protected != 0,
44 is_public: self.is_public != 0,
45 created_at: self.created_at,
46 updated_at: self.updated_at,
47 }
48 }
49}