use serde::{Deserialize, Serialize}; use crate::{ error::RepositoryError, model::repository::{IssueLabel, Repository, RepositoryIssue, RepositoryTreeEntry}, }; use super::{GiteratedOperation, Object, ObjectBackend}; /// A request to get a repository's information. /// /// # Authentication /// - Instance Authentication /// - Validate request against the `issued_for` public key /// - Validate User token against the user's instance's public key /// # Authorization /// - User Authorization /// - Potential User permissions checks #[derive(Clone, Debug, Serialize, Deserialize)] pub struct RepositoryIssuesCountRequest; impl GiteratedOperation for RepositoryIssuesCountRequest { type Success = u64; type Failure = RepositoryError; } /// A request to get a repository's issues count. /// /// # Authentication /// - Instance Authentication /// - Validate request against the `issued_for` public key /// - Validate User token against the user's instance's public key /// # Authorization /// - User Authorization /// - Potential User permissions checks #[derive(Clone, Debug, Serialize, Deserialize)] pub struct RepositoryIssueLabelsRequest; impl GiteratedOperation for RepositoryIssueLabelsRequest { type Success = Vec; type Failure = RepositoryError; } /// A request to get a repository's issue labels. /// /// # Authentication /// - Instance Authentication /// - Validate request against the `issued_for` public key /// - Validate User token against the user's instance's public key /// # Authorization /// - User Authorization /// - Potential User permissions checks #[derive(Clone, Debug, Serialize, Deserialize)] pub struct RepositoryIssuesRequest; impl GiteratedOperation for RepositoryIssuesRequest { type Success = Vec; type Failure = RepositoryError; } /// A request to inspect the tree of a repository. /// /// # Authentication /// - Instance Authentication /// - Validate request against the `issued_for` public key /// - Validate User token against the user's instance's public key /// # Authorization /// - User Authorization /// - Potential User permissions checks #[derive(Clone, Debug, Serialize, Deserialize)] pub struct RepositoryFileInspectRequest { pub path: RepositoryTreeEntry, } impl GiteratedOperation for RepositoryFileInspectRequest { type Success = Vec; type Failure = RepositoryError; } impl Object<'_, Repository, B> { pub async fn issues_count(&mut self) -> Result { self.request::(RepositoryIssuesCountRequest) } pub async fn issue_labels(&mut self) -> Result, RepositoryError> { self.request::(RepositoryIssueLabelsRequest) } pub async fn issues(&mut self) -> Result, RepositoryError> { self.request::(RepositoryIssuesRequest) } pub async fn inspect_files( &mut self, entry: &RepositoryTreeEntry, ) -> Result, RepositoryError> { self.request::(RepositoryFileInspectRequest { path: entry.clone(), }) } }