brewlog/src/domain/timeline.rs
Jon Seager b12ad2bf6d
feat(timeline): add "brew again" button to timeline
- Add TimelineBrewData struct to domain layer to carry raw brew
  parameters needed for repeating a brew
- Extend timeline SQL query to LEFT JOIN with brews table and fetch
  brew data (bag_id, grinder_id, brewer_id, coffee_weight, etc.)
- Add brew_data field to TimelineEventView for template access
- Add is_authenticated to TimelineChunkTemplate for auth-aware chunks
- Add "brew again" button to timeline month partial, visible only for
  authenticated users on brew events
- Server returns reload script when brew is created from timeline page,
  using Datastar's fragment patching to append script to body
2026-02-02 20:14:51 +00:00

79 lines
2 KiB
Rust

use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
use crate::domain::ids::TimelineEventId;
use crate::domain::listing::{SortDirection, SortKey};
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct TimelineEventDetail {
pub label: String,
pub value: String,
}
/// Raw brew data for repeating a brew from the timeline.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct TimelineBrewData {
pub bag_id: i64,
pub grinder_id: i64,
pub brewer_id: i64,
pub coffee_weight: f64,
pub grind_setting: f64,
pub water_volume: i32,
pub water_temp: f64,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct TimelineEvent {
pub id: TimelineEventId,
pub entity_type: String,
pub entity_id: i64,
pub action: String,
pub occurred_at: DateTime<Utc>,
pub title: String,
pub details: Vec<TimelineEventDetail>,
pub tasting_notes: Vec<String>,
pub slug: Option<String>,
pub roaster_slug: Option<String>,
pub brew_data: Option<TimelineBrewData>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct NewTimelineEvent {
pub entity_type: String,
pub entity_id: i64,
pub action: String,
pub occurred_at: DateTime<Utc>,
pub title: String,
pub details: Vec<TimelineEventDetail>,
pub tasting_notes: Vec<String>,
}
#[derive(Debug, Clone, Copy, Eq, PartialEq)]
pub enum TimelineSortKey {
OccurredAt,
}
impl SortKey for TimelineSortKey {
fn default() -> Self {
TimelineSortKey::OccurredAt
}
fn from_query(value: &str) -> Option<Self> {
match value {
"occurred-at" => Some(TimelineSortKey::OccurredAt),
_ => None,
}
}
fn query_value(self) -> &'static str {
match self {
TimelineSortKey::OccurredAt => "occurred-at",
}
}
fn default_direction(self) -> SortDirection {
match self {
TimelineSortKey::OccurredAt => SortDirection::Desc,
}
}
}