feagi_api/common/
response.rs1use chrono::Utc;
7use serde::{Deserialize, Serialize};
8#[cfg(feature = "http")]
9use utoipa::ToSchema;
10
11#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
13#[serde(rename_all = "camelCase")]
14pub struct ApiResponse<T> {
15 pub success: bool,
17
18 #[serde(skip_serializing_if = "Option::is_none")]
20 pub data: Option<T>,
21
22 pub timestamp: String,
24}
25
26impl<T> ApiResponse<T> {
27 pub fn success(data: T) -> Self {
29 Self {
30 success: true,
31 data: Some(data),
32 timestamp: Utc::now().to_rfc3339(),
33 }
34 }
35
36 pub fn error() -> ApiResponse<()> {
38 ApiResponse {
39 success: false,
40 data: None,
41 timestamp: Utc::now().to_rfc3339(),
42 }
43 }
44}
45
46#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
48pub struct EmptyResponse {
49 pub message: String,
51}
52
53impl EmptyResponse {
54 pub fn new(message: impl Into<String>) -> Self {
55 Self {
56 message: message.into(),
57 }
58 }
59}