feat: create_repository interface

This commit is contained in:
Aravinth Manivannan 2022-05-04 12:10:13 +05:30
parent 2055a00565
commit cb8500da3f
Signed by: realaravinth
GPG key ID: AD9F0F08E855ED88
2 changed files with 29 additions and 4 deletions

View file

@ -87,6 +87,26 @@ pub struct AddUser<'a> {
pub profile_photo: Option<&'a str>,
}
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
/// add new repository to database
pub struct AddRepository<'a> {
/// html link to the repository
pub html_link: &'a str,
/// repository topic tags
pub tags: Option<Vec<&'a str>>,
/// hostname of the forge instance: with scheme but remove trailing slash
/// hostname can be derived from html_link also, but used to link to user's forge instance
pub hostname: &'a str,
/// repository name
pub name: &'a str,
/// repository owner
pub owner: &'a str,
/// repository description, if any
pub description: Option<&'a str>,
/// repository website, if any
pub website: Option<&'a str>,
}
#[async_trait]
/// Starchart's database requirements. To implement support for $Database, kindly implement this
/// trait.
@ -115,6 +135,9 @@ pub trait SCDatabase: std::marker::Send + std::marker::Sync + CloneSPDatabase {
/// check if a repository exists.
async fn repository_exists(&self, name: &str, owner: &str, hostname: &str) -> DBResult<bool>;
/// add new repository to database.
async fn create_repository(&self, r: &AddRepository) -> DBResult<()>;
}
/// Trait to clone SCDatabase

View file

@ -19,11 +19,12 @@
use crate::prelude::*;
/// adding forge works
pub async fn adding_forge_works<T: SCDatabase>(
pub async fn adding_forge_works<'a, T: SCDatabase>(
db: &T,
create_forge_msg: CreateForge<'static>,
add_user_msg: AddUser<'static>,
add_user_msg2: AddUser<'static>,
create_forge_msg: CreateForge<'a>,
add_user_msg: AddUser<'a>,
add_user_msg2: AddUser<'a>,
add_repo_msg: AddRepository<'a>,
) {
let _ = db.delete_forge_instance(&create_forge_msg.hostname).await;
db.create_forge_isntance(&create_forge_msg).await.unwrap();
@ -34,6 +35,7 @@ pub async fn adding_forge_works<T: SCDatabase>(
db.add_user(&add_user_msg).await.unwrap();
db.add_user(&add_user_msg2).await.unwrap();
db.create_repository(&add_repo_msg).await.unwrap();
}
/// test if all forge type implementations are loaded into DB