From cb8500da3f68c90df59a80a36b751c855f5e4db1 Mon Sep 17 00:00:00 2001
From: realaravinth <realaravinth@batsense.net>
Date: Wed, 4 May 2022 12:10:13 +0530
Subject: [PATCH] feat: create_repository interface

---
 db/db-core/src/lib.rs   | 23 +++++++++++++++++++++++
 db/db-core/src/tests.rs | 10 ++++++----
 2 files changed, 29 insertions(+), 4 deletions(-)

diff --git a/db/db-core/src/lib.rs b/db/db-core/src/lib.rs
index f18df2b..2d6ef51 100644
--- a/db/db-core/src/lib.rs
+++ b/db/db-core/src/lib.rs
@@ -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
diff --git a/db/db-core/src/tests.rs b/db/db-core/src/tests.rs
index f97c56c..e7cd6dc 100644
--- a/db/db-core/src/tests.rs
+++ b/db/db-core/src/tests.rs
@@ -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