use axum::Json; use common::{Event, Person, Stats}; use serde::{Deserialize, Serialize}; use utoipa::ToSchema; use crate::errors::ApiError; pub type ApiResult = Result, ApiError>; #[derive(Deserialize, ToSchema)] pub struct EventInput { pub name: Option, pub times: Vec, pub timezone: String, } #[derive(Serialize, ToSchema)] pub struct EventResponse { pub id: String, pub name: String, pub times: Vec, pub timezone: String, pub created_at: i64, } impl From for EventResponse { fn from(value: Event) -> Self { Self { id: value.id, name: value.name, times: value.times, timezone: value.timezone, created_at: value.created_at.timestamp(), } } } #[derive(Serialize, ToSchema)] pub struct StatsResponse { pub event_count: i64, pub person_count: i64, pub version: String, } impl From for StatsResponse { fn from(value: Stats) -> Self { Self { event_count: value.event_count, person_count: value.person_count, version: env!("CARGO_PKG_VERSION").to_string(), } } } #[derive(Serialize, ToSchema)] pub struct PersonResponse { pub name: String, pub availability: Vec, pub created_at: i64, } impl From for PersonResponse { fn from(value: Person) -> Self { Self { name: value.name, availability: value.availability, created_at: value.created_at.timestamp(), } } } #[derive(Deserialize, ToSchema)] pub struct PersonInput { pub availability: Vec, }