stateset_embedded/
activity_logs.rs1use stateset_core::{ActivityLogEntry, ActivityLogFilter, ActivityLogId, RecordActivity, Result};
4use stateset_db::{Database, DatabaseCapability};
5use std::sync::Arc;
6use uuid::Uuid;
7
8pub struct ActivityLogs {
10 db: Arc<dyn Database>,
11}
12
13impl std::fmt::Debug for ActivityLogs {
14 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
15 f.debug_struct("ActivityLogs").finish_non_exhaustive()
16 }
17}
18
19impl ActivityLogs {
20 pub(crate) fn new(db: Arc<dyn Database>) -> Self {
21 Self { db }
22 }
23
24 #[must_use]
26 pub fn is_supported(&self) -> bool {
27 self.db.supports_capability(DatabaseCapability::ActivityLogs)
28 }
29
30 fn ensure(&self) -> Result<()> {
31 self.db.ensure_capability(DatabaseCapability::ActivityLogs)
32 }
33
34 pub fn record(&self, input: RecordActivity) -> Result<ActivityLogEntry> {
36 self.ensure()?;
37 self.db.activity_logs().record(input)
38 }
39
40 pub fn get(&self, id: ActivityLogId) -> Result<Option<ActivityLogEntry>> {
42 self.ensure()?;
43 self.db.activity_logs().get(id)
44 }
45
46 pub fn list(&self, filter: ActivityLogFilter) -> Result<Vec<ActivityLogEntry>> {
48 self.ensure()?;
49 self.db.activity_logs().list(filter)
50 }
51
52 pub fn history_for_subject(
54 &self,
55 subject_type: &str,
56 subject_id: Uuid,
57 ) -> Result<Vec<ActivityLogEntry>> {
58 self.ensure()?;
59 self.db.activity_logs().history_for_subject(subject_type, subject_id)
60 }
61}