Use boolean ok field for api

This commit is contained in:
Lars Jellema 2022-04-21 23:02:14 +02:00
parent ced7d83fd9
commit 8df5fff105
No known key found for this signature in database
GPG Key ID: 563A03936D48B4BC
1 changed files with 3 additions and 6 deletions

View File

@ -22,7 +22,7 @@ use validator::{ValidateArgs, ValidationErrors};
#[derive(Serialize, Deserialize, Debug)]
struct ApiResponse {
result: Cow<'static, str>,
ok: bool,
#[serde(skip_serializing_if = "Option::is_none")]
message: Option<Cow<'static, str>>,
#[serde(skip_serializing_if = "Option::is_none")]
@ -30,18 +30,15 @@ struct ApiResponse {
}
impl ApiResponse {
const SUCCES_RESULT: Cow<'static, str> = Cow::Borrowed("Ok");
const FAILURE_RESULT: Cow<'static, str> = Cow::Borrowed("Failure");
const SUCCES: Self = Self {
result: Self::SUCCES_RESULT,
ok: true,
message: None,
jwt: None,
};
fn login_response(jwt: String) -> Self {
Self {
result: Self::SUCCES_RESULT,
ok: true,
message: None,
jwt: Some(Cow::Owned(jwt)),
}