forked from 8xFF/atm0s-media-server
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
83 additions
and
125 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,39 @@ | ||
use poem_openapi::types::{ToJSON, Type}; | ||
use poem_openapi::{types::ParseFromJSON, Object}; | ||
use poem_openapi::{ | ||
types::{ParseFromJSON, ToJSON, Type}, | ||
Object, | ||
}; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
#[derive(Debug, Default, Serialize, Deserialize, Object)] | ||
pub struct Response<T: ParseFromJSON + ToJSON + Type + Send + Sync> { | ||
pub status: bool, | ||
#[derive(Debug, Serialize, Deserialize, Object)] | ||
pub struct Response<T: ParseFromJSON + ToJSON + Type + Send + Sync, E: ParseFromJSON + ToJSON + Type + Send + Sync> { | ||
pub success: bool, | ||
#[serde(skip_serializing_if = "Option::is_none")] | ||
#[oai(skip_serializing_if = "Option::is_none")] | ||
pub error: Option<String>, | ||
pub error_code: Option<E>, | ||
#[serde(skip_serializing_if = "Option::is_none")] | ||
#[oai(skip_serializing_if = "Option::is_none")] | ||
pub error_msg: Option<String>, | ||
#[serde(skip_serializing_if = "Option::is_none")] | ||
#[oai(skip_serializing_if = "Option::is_none")] | ||
pub data: Option<T>, | ||
} | ||
|
||
impl<T: ParseFromJSON + ToJSON + Type + Send + Sync, E: ParseFromJSON + ToJSON + Type + Send + Sync> Response<T, E> { | ||
pub fn success<T2: Into<T>>(data: T2) -> Self { | ||
Self { | ||
success: true, | ||
data: Some(data.into()), | ||
error_code: None, | ||
error_msg: None, | ||
} | ||
} | ||
|
||
pub fn error<E2: Into<E>>(error_code: E2, error_msg: &str) -> Self { | ||
Self { | ||
success: false, | ||
error_code: Some(error_code.into()), | ||
error_msg: Some(error_msg.to_string()), | ||
data: None, | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.