Rohan Sircar
3 years ago
6 changed files with 52 additions and 68 deletions
-
55src/errors/domain_error.rs
-
4src/models.rs
-
22src/models/api_response.rs
-
14src/models/errors.rs
-
4src/routes/users.rs
-
21tests/integration/users.rs
@ -1,4 +1,4 @@ |
|||
pub mod users;
|
|||
pub use self::users::*;
|
|||
pub mod errors;
|
|||
pub use self::errors::*;
|
|||
pub mod api_response;
|
|||
pub use self::api_response::*;
|
@ -0,0 +1,22 @@ |
|||
use serde::{Deserialize, Serialize};
|
|||
|
|||
#[derive(PartialEq, Debug, Clone, Serialize, Deserialize, new)]
|
|||
pub struct ApiResponse<T> {
|
|||
success: bool,
|
|||
response: T,
|
|||
}
|
|||
|
|||
impl<T> ApiResponse<T> {
|
|||
pub fn success(&self) -> bool {
|
|||
self.success
|
|||
}
|
|||
pub fn response(&self) -> &T {
|
|||
&self.response
|
|||
}
|
|||
pub fn successful(response: T) -> ApiResponse<T> {
|
|||
ApiResponse::new(true, response)
|
|||
}
|
|||
pub fn failure(response: T) -> ApiResponse<T> {
|
|||
ApiResponse::new(false, response)
|
|||
}
|
|||
}
|
@ -1,14 +0,0 @@ |
|||
use serde::{Deserialize, Serialize};
|
|||
|
|||
#[derive(Debug, Clone, Serialize, new)]
|
|||
pub struct JsonErrorModel<'a> {
|
|||
status_code: i16,
|
|||
pub line: String,
|
|||
pub reason: &'a str,
|
|||
}
|
|||
#[derive(PartialEq, Debug, Clone, Serialize, Deserialize, new)]
|
|||
pub struct ErrorModel {
|
|||
// pub error_code: i16,
|
|||
pub success: bool,
|
|||
pub reason: String,
|
|||
}
|
Write
Preview
Loading…
Cancel
Save
Reference in new issue