cscart_rs/service/
auth_service.rs1use crate::prelude::*;
2use crate::service::config::ServiceConfig;
3use crate::types::Auth;
4use serde::{Deserialize, Serialize};
5
6pub struct AuthService {
7 config: ServiceConfig<Authenticated>,
8}
9
10impl AuthService {
11 pub fn with_config(service: ServiceConfig<Authenticated>) -> AuthService {
12 Self { config: service }
13 }
14}
15
16#[derive(Serialize, Deserialize, Debug)]
17pub struct CreateAuthRequest {
18 pub email: String,
19}
20
21impl AuthService {
22 pub async fn create(&self, data: CreateAuthRequest) -> anyhow::Result<Auth> {
23 let handler = crate::handler::Handler::new()
24 .host(&self.config.host())
25 .username(self.config.auth().username())
26 .api_key(self.config.auth().api_key())
27 .path(self.config.resource.as_ref().unwrap().path())
28 .build();
29 let value = serde_json::to_value(data)?;
30 let response_value = handler.create(value).await?;
31 dbg!(&response_value);
32 let response: Auth = serde_json::from_value(response_value)?;
33 Ok(response)
34 }
35}