use super::GitLabApi;
use super::converters::GitLabProject;
use crate::handlers::templates::PercentEncoded;
use crate::network::ForgeApi;
use crate::network::error;
use crate::network::net::{ApiEndpoint, Net};
use url::Url;
pub struct ProjectEndpoint<'a> {
pub api: &'a GitLabApi,
pub base_url: Url,
pub project_id: &'a PercentEncoded,
}
impl ApiEndpoint<GitLabApi, GitLabProject> for ProjectEndpoint<'_> {
fn api(&self) -> &GitLabApi {
self.api
}
fn url(&self) -> Url {
self.base_url
.join(&format!("projects/{}", self.project_id.uri_component()))
.expect("Valid URL path")
}
}
pub async fn get_repo(
api: &GitLabApi,
net: &Net,
project_id: &PercentEncoded,
) -> Result<GitLabProject, error::Error> {
let base_url = api.base_url().clone();
let endpoint = ProjectEndpoint {
api,
base_url,
project_id,
};
net.call(&endpoint).await
}