feat(presentation): all handlers

This commit is contained in:
2026-05-14 04:00:04 +02:00
parent fb39ea2469
commit 38106ecdb6
5 changed files with 190 additions and 0 deletions

View File

@@ -0,0 +1,18 @@
use axum::{extract::{Path, State}, http::StatusCode, Json};
use uuid::Uuid;
use domain::{models::feed::PageParams, value_objects::NotificationId};
use crate::{errors::ApiError, extractors::AuthUser, state::AppState};
pub async fn list_notifications(State(s): State<AppState>, AuthUser(uid): AuthUser) -> Result<Json<serde_json::Value>, ApiError> {
let page = PageParams { page: 1, per_page: 20 };
let result = s.notifications.list_for_user(&uid, &page).await?;
Ok(Json(serde_json::json!({ "total": result.total, "unread": result.items.iter().filter(|n| !n.read).count() })))
}
pub async fn mark_notification_read(State(s): State<AppState>, AuthUser(uid): AuthUser, Path(id): Path<Uuid>) -> Result<StatusCode, ApiError> {
s.notifications.mark_read(&NotificationId::from_uuid(id), &uid).await?;
Ok(StatusCode::NO_CONTENT)
}
pub async fn mark_all_read(State(s): State<AppState>, AuthUser(uid): AuthUser) -> Result<StatusCode, ApiError> {
s.notifications.mark_all_read(&uid).await?;
Ok(StatusCode::NO_CONTENT)
}