use reqwest::Method;
use serde::{Deserialize, Serialize};
use crate::{
core::{
api_req::ApiRequest,
api_resp::{ApiResponseTrait, BaseResponse, ResponseFormat},
config::Config,
constants::AccessTokenType,
endpoints::LINGO_REPO_LIST,
http::Transport,
req_option::RequestOption,
SDKResult,
},
service::lingo::models::{PageResponse, Repo},
};
pub struct RepoService {
pub config: Config,
}
impl RepoService {
pub fn new(config: Config) -> Self {
Self { config }
}
pub async fn list_repos(
&self,
request: RepoListRequest,
option: Option<RequestOption>,
) -> SDKResult<BaseResponse<RepoListResponse>> {
let mut api_req = ApiRequest {
http_method: Method::GET,
api_path: LINGO_REPO_LIST.to_string(),
supported_access_token_types: vec![AccessTokenType::Tenant, AccessTokenType::User],
body: vec![],
..Default::default()
};
if let Some(page_token) = request.page_token {
api_req.query_params.insert("page_token", page_token);
}
if let Some(page_size) = request.page_size {
api_req
.query_params
.insert("page_size", page_size.to_string());
}
Transport::request(api_req, &self.config, option).await
}
}
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct RepoListRequest {
#[serde(skip_serializing_if = "Option::is_none")]
pub page_token: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub page_size: Option<i32>,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct RepoListResponse {
#[serde(flatten)]
pub repos: PageResponse<Repo>,
}
impl ApiResponseTrait for RepoListResponse {
fn data_format() -> ResponseFormat {
ResponseFormat::Data
}
}