Преглед изворни кода

Start GitRepository implementation + structure clean up.

Alexandre Leblanc пре 3 година
родитељ
комит
b970d3e4ed

+ 9 - 7
src/main.rs

@@ -1,18 +1,20 @@
-mod articles_repository;
+extern crate chrono;
+
 mod config;
 mod theme;
-mod vcs;
-
-extern crate chrono;
+mod repository;
 
 use actix_web::middleware::Logger;
 use actix_web::{get, web, App, HttpResponse, HttpServer, Responder};
 use fern;
 use std::{env, io};
 
-use articles_repository::{ArticlesRepository, FsRepository};
-use config::Configuration;
-use theme::Theme;
+use crate::config::Configuration;
+use crate::theme::Theme;
+use crate::repository::{
+    ArticlesRepository,
+    FsRepository
+};
 
 #[get("")]
 async fn show_articles_list() -> impl Responder {

+ 16 - 0
src/repository/articles_repository.rs

@@ -0,0 +1,16 @@
+pub struct ArticleAuthor {
+    pub name: String,
+    pub email: String,
+}
+
+pub struct ArticleEntry {
+    pub version_id: String,
+    pub title: String,
+    pub date: String,
+    pub author: ArticleAuthor,
+    pub path: String,
+}
+
+pub trait ArticlesRepository {
+    fn get_directory_listing(&self, path: &str) -> Vec<String>;
+}

+ 1 - 3
src/articles_repository.rs

@@ -1,8 +1,6 @@
 use walkdir::WalkDir;
 
-pub trait ArticlesRepository {
-    fn get_directory_listing(&self, path: &str) -> Vec<String>;
-}
+use crate::ArticlesRepository;
 
 pub struct FsRepository {}
 

+ 33 - 0
src/repository/git_repository.rs

@@ -0,0 +1,33 @@
+use git2::Repository;
+
+use crate::ArticlesRepository;
+
+pub struct GitRepository<'a> {
+    repo: &'a git2::Repository
+}
+
+impl<'a> GitRepository<'a> {
+    fn new(repo: &'a git2::Repository) -> Self {
+        GitRepository {
+            repo
+        }
+    }
+}
+
+//Modification times: https://github.com/Shnatsel/rustsec/blob/f043c75731df311292a7e4f4dbb05c6728d055f5/rustsec/src/repository/git/modification_time.rs#L18
+impl<'a> ArticlesRepository for GitRepository<'a> {
+    fn get_directory_listing(&self, path: &str) -> Vec<String> {
+        vec![]
+    }
+}
+
+#[cfg(test)]
+mod tests_git_repository {
+    use super::*;
+
+    #[test]
+    fn when_path_is_empty_should_return_nothing() {}
+
+    #[test]
+    fn when_path_is_valid_should_return_proper_listing() {}
+}

+ 7 - 0
src/repository/mod.rs

@@ -0,0 +1,7 @@
+pub mod articles_repository;
+pub mod git_repository;
+pub mod fs_repository;
+
+pub use articles_repository::ArticlesRepository;
+pub use git_repository::GitRepository;
+pub use fs_repository::FsRepository;

+ 0 - 13
src/vcs/git.rs

@@ -1,13 +0,0 @@
-use crate::vcs::VersionSource;
-
-struct Git {}
-
-impl VersionSource for Git {
-    fn update() -> Result<String, String> {
-        todo!()
-    }
-
-    fn commit() -> Result<String, String> {
-        todo!()
-    }
-}

+ 0 - 9
src/vcs/mod.rs

@@ -1,9 +0,0 @@
-mod git;
-
-trait VersionSource {
-    // Update local
-    fn update() -> Result<String, String>;
-
-    // Update remotes
-    fn commit() -> Result<String, String>;
-}