refactor: reorganize HtmlPageContext and update imports across modules
Some checks failed
CI / Check / Test (push) Failing after 46m33s
Some checks failed
CI / Check / Test (push) Failing after 46m33s
This commit is contained in:
2
Cargo.lock
generated
2
Cargo.lock
generated
@@ -320,6 +320,7 @@ dependencies = [
|
|||||||
"futures",
|
"futures",
|
||||||
"hex",
|
"hex",
|
||||||
"rand 0.9.4",
|
"rand 0.9.4",
|
||||||
|
"reqwest 0.13.3",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
"sha2",
|
"sha2",
|
||||||
"tokio",
|
"tokio",
|
||||||
@@ -5787,7 +5788,6 @@ name = "tmdb-enrichment"
|
|||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"application",
|
|
||||||
"async-trait",
|
"async-trait",
|
||||||
"chrono",
|
"chrono",
|
||||||
"domain",
|
"domain",
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
pub use askama;
|
pub use askama;
|
||||||
use askama::Template;
|
use askama::Template;
|
||||||
|
|
||||||
use application::ports::HtmlPageContext;
|
use application::rendering::HtmlPageContext;
|
||||||
use chrono::Datelike;
|
use chrono::Datelike;
|
||||||
use domain::models::{
|
use domain::models::{
|
||||||
DiaryEntry, FeedEntry, MonthActivity, MonthlyRating, ReviewSource, UserStats, UserTrends,
|
DiaryEntry, FeedEntry, MonthActivity, MonthlyRating, ReviewSource, UserStats, UserTrends,
|
||||||
|
|||||||
@@ -89,10 +89,6 @@ impl ReviewLogger for DefaultReviewLogger {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
#[path = "tests/review_logger.rs"]
|
|
||||||
mod tests;
|
|
||||||
|
|
||||||
async fn publish_events(
|
async fn publish_events(
|
||||||
publisher: &Arc<dyn EventPublisher>,
|
publisher: &Arc<dyn EventPublisher>,
|
||||||
movie: &Movie,
|
movie: &Movie,
|
||||||
@@ -119,3 +115,7 @@ async fn publish_events(
|
|||||||
|
|
||||||
publisher.publish(&review_event).await
|
publisher.publish(&review_event).await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
#[path = "tests/review_logger.rs"]
|
||||||
|
mod tests;
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
pub mod config;
|
pub mod config;
|
||||||
pub mod jobs;
|
pub mod jobs;
|
||||||
pub mod ports;
|
pub mod ports;
|
||||||
|
pub mod rendering;
|
||||||
pub mod worker;
|
pub mod worker;
|
||||||
|
|
||||||
pub mod auth;
|
pub mod auth;
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
use uuid::Uuid;
|
|
||||||
|
|
||||||
use domain::errors::DomainError;
|
use domain::errors::DomainError;
|
||||||
use domain::models::DiaryEntry;
|
use domain::models::DiaryEntry;
|
||||||
@@ -11,24 +10,6 @@ pub trait ReviewLogger: Send + Sync {
|
|||||||
async fn log_review(&self, cmd: LogReviewCommand) -> Result<(), DomainError>;
|
async fn log_review(&self, cmd: LogReviewCommand) -> Result<(), DomainError>;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct HtmlPageContext {
|
|
||||||
pub user_email: Option<String>,
|
|
||||||
pub user_id: Option<Uuid>,
|
|
||||||
pub is_admin: bool,
|
|
||||||
pub register_enabled: bool,
|
|
||||||
pub rss_url: String,
|
|
||||||
pub page_title: String,
|
|
||||||
pub canonical_url: String,
|
|
||||||
pub csrf_token: String,
|
|
||||||
pub page_rss_url: Option<String>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl HtmlPageContext {
|
|
||||||
pub fn is_current_user(&self, id: Uuid) -> bool {
|
|
||||||
self.user_id == Some(id)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub trait RssFeedRenderer: Send + Sync {
|
pub trait RssFeedRenderer: Send + Sync {
|
||||||
fn render_feed(&self, entries: &[DiaryEntry], title: &str) -> Result<String, String>;
|
fn render_feed(&self, entries: &[DiaryEntry], title: &str) -> Result<String, String>;
|
||||||
}
|
}
|
||||||
|
|||||||
19
crates/application/src/rendering.rs
Normal file
19
crates/application/src/rendering.rs
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
use uuid::Uuid;
|
||||||
|
|
||||||
|
pub struct HtmlPageContext {
|
||||||
|
pub user_email: Option<String>,
|
||||||
|
pub user_id: Option<Uuid>,
|
||||||
|
pub is_admin: bool,
|
||||||
|
pub register_enabled: bool,
|
||||||
|
pub rss_url: String,
|
||||||
|
pub page_title: String,
|
||||||
|
pub canonical_url: String,
|
||||||
|
pub csrf_token: String,
|
||||||
|
pub page_rss_url: Option<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl HtmlPageContext {
|
||||||
|
pub fn is_current_user(&self, id: Uuid) -> bool {
|
||||||
|
self.user_id == Some(id)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -24,7 +24,7 @@ use crate::{
|
|||||||
use api_types::{
|
use api_types::{
|
||||||
LoginRequest, LoginResponse, LogoutRequest, RefreshRequest, RefreshResponse, RegisterRequest,
|
LoginRequest, LoginResponse, LogoutRequest, RefreshRequest, RefreshResponse, RegisterRequest,
|
||||||
};
|
};
|
||||||
use application::ports::HtmlPageContext;
|
use application::rendering::HtmlPageContext;
|
||||||
use template_askama::{LoginTemplate, RegisterTemplate};
|
use template_askama::{LoginTemplate, RegisterTemplate};
|
||||||
|
|
||||||
// ── HTML helpers ─────────────────────────────────────────────────────────────
|
// ── HTML helpers ─────────────────────────────────────────────────────────────
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
use application::ports::HtmlPageContext;
|
use application::rendering::HtmlPageContext;
|
||||||
use domain::value_objects::UserId;
|
use domain::value_objects::UserId;
|
||||||
|
|
||||||
use crate::state::AppState;
|
use crate::state::AppState;
|
||||||
|
|||||||
@@ -201,7 +201,7 @@ fn format_watch_time(minutes: u32) -> String {
|
|||||||
fn render_wrapup(
|
fn render_wrapup(
|
||||||
report: &WrapUpReport,
|
report: &WrapUpReport,
|
||||||
year: i32,
|
year: i32,
|
||||||
ctx: &application::ports::HtmlPageContext,
|
ctx: &application::rendering::HtmlPageContext,
|
||||||
) -> axum::response::Response {
|
) -> axum::response::Response {
|
||||||
let rating_max = report
|
let rating_max = report
|
||||||
.rating_distribution
|
.rating_distribution
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ pub mod forms;
|
|||||||
pub mod handlers;
|
pub mod handlers;
|
||||||
pub mod mappers;
|
pub mod mappers;
|
||||||
pub mod openapi;
|
pub mod openapi;
|
||||||
pub mod ports;
|
|
||||||
pub mod render;
|
pub mod render;
|
||||||
pub mod routes;
|
pub mod routes;
|
||||||
pub mod state;
|
pub mod state;
|
||||||
|
|||||||
@@ -1 +0,0 @@
|
|||||||
pub use application::ports::RssFeedRenderer;
|
|
||||||
@@ -2,7 +2,7 @@ use std::sync::Arc;
|
|||||||
|
|
||||||
use crate::context::AppContext;
|
use crate::context::AppContext;
|
||||||
|
|
||||||
use crate::ports::RssFeedRenderer;
|
use application::ports::RssFeedRenderer;
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct AppState {
|
pub struct AppState {
|
||||||
|
|||||||
@@ -416,7 +416,7 @@ impl domain::ports::DocumentParser for Panic {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl crate::ports::RssFeedRenderer for Panic {
|
impl application::ports::RssFeedRenderer for Panic {
|
||||||
fn render_feed(&self, _: &[DiaryEntry], _: &str) -> Result<String, String> {
|
fn render_feed(&self, _: &[DiaryEntry], _: &str) -> Result<String, String> {
|
||||||
panic!()
|
panic!()
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user