added login info inside marker struct and created a marker payload struct to handle the sent json

This commit is contained in:
Valmo Trindade
2024-09-20 17:02:32 -03:00
parent ba77e3a2fe
commit cb7b7e9c0f

View File

@@ -1,4 +1,4 @@
use arma_rs::FromArma; use arma_rs::{FromArma, FromArmaError};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
#[derive(Serialize)] #[derive(Serialize)]
@@ -13,10 +13,12 @@ pub struct Marker {
pub hae: f64, pub hae: f64,
pub api_address: String, pub api_address: String,
pub api_auth_token: String, pub api_auth_token: String,
pub api_auth_username: String,
pub api_auth_password: String,
} }
impl FromArma for Marker { impl FromArma for Marker {
fn from_arma(data: String) -> Result<Self, String> { fn from_arma(data: String) -> Result<Marker, FromArmaError> {
let ( let (
uid, uid,
latitude, latitude,
@@ -28,6 +30,8 @@ impl FromArma for Marker {
hae, hae,
api_address, api_address,
api_auth_token, api_auth_token,
api_auth_username,
api_auth_password
) = <( ) = <(
String, String,
f64, f64,
@@ -39,6 +43,8 @@ impl FromArma for Marker {
f64, f64,
String, String,
String, String,
String,
String
)>::from_arma(data)?; )>::from_arma(data)?;
Ok(Self { Ok(Self {
uid, uid,
@@ -51,11 +57,25 @@ impl FromArma for Marker {
hae, hae,
api_address, api_address,
api_auth_token, api_auth_token,
api_auth_username,
api_auth_password
}) })
} }
} }
#[derive(Debug, Serialize, Deserialize)] #[derive(Debug, Serialize, Deserialize)]
pub struct MarkerPayload {
pub uid: String,
pub longitude: f64,
pub latitude: f64,
pub name: String,
pub r#type: String,
pub course: f64,
pub speed: f64,
pub hae: f64,
}
#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct LoginPayload { pub struct LoginPayload {
pub address: String, pub address: String,
pub username: String, pub username: String,
@@ -69,7 +89,7 @@ pub struct LoginInfo {
} }
impl FromArma for LoginPayload { impl FromArma for LoginPayload {
fn from_arma(data: String) -> Result<Self, String> { fn from_arma(data: String) -> Result<LoginPayload, FromArmaError> {
let (address, username, password) = <(String, String, String)>::from_arma(data)?; let (address, username, password) = <(String, String, String)>::from_arma(data)?;
Ok(Self { Ok(Self {
address, address,