Merge pull request 'feat/Introduce config module' (#7) from config into master
Reviewed-on: #7pull/10/head
commit
4795b60260
@ -1,9 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
</head>
|
||||
<body></body>
|
||||
</html>
|
||||
@ -1,19 +1,26 @@
|
||||
use crate::api::types::{paginated_response::PaginatedResponse, transaction::TransactionCompany};
|
||||
use crate::{
|
||||
api::types::{paginated_response::PaginatedResponse, transaction::TransactionCompany},
|
||||
env::Config,
|
||||
};
|
||||
|
||||
pub async fn get_transactions(
|
||||
company_slug: Option<String>,
|
||||
page: i64,
|
||||
size: i64,
|
||||
) -> Result<PaginatedResponse<TransactionCompany>, ()> {
|
||||
let res = reqwasm::http::Request::get(&format!(
|
||||
"http://localhost:8000/v1/transaction?page={}&size={}",
|
||||
page, size,
|
||||
"{}transaction{}?page={}&size={}",
|
||||
Config::new().api_url,
|
||||
company_slug.unwrap_or("".to_string()),
|
||||
page,
|
||||
size,
|
||||
))
|
||||
.send()
|
||||
.await
|
||||
.unwrap()
|
||||
.map_err(|_| ())?
|
||||
.json::<PaginatedResponse<TransactionCompany>>()
|
||||
.await
|
||||
.unwrap();
|
||||
.map_err(|_| ())?;
|
||||
|
||||
Ok(res)
|
||||
}
|
||||
|
||||
@ -0,0 +1,15 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use std::env;
|
||||
|
||||
#[derive(Clone, Serialize, Deserialize)]
|
||||
pub struct Config {
|
||||
pub api_url: String,
|
||||
}
|
||||
|
||||
impl Config {
|
||||
pub fn new() -> Self {
|
||||
let api_url = env!("API_URL").to_string();
|
||||
Config { api_url }
|
||||
}
|
||||
}
|
||||
Loading…
Reference in new issue