summary refs log tree commit diff stats
path: root/pkgs/by-name/ba/back/src/web/mod.rs
diff options
context:
space:
mode:
authorBenedikt Peetz <benedikt.peetz@b-peetz.de>2024-12-26 10:00:45 +0100
committerBenedikt Peetz <benedikt.peetz@b-peetz.de>2024-12-26 10:01:56 +0100
commita3111a5d214db66b7d676940b8f8bfda5074bd45 (patch)
treea68cc1458386052a7c97a07b69bd161866ad7046 /pkgs/by-name/ba/back/src/web/mod.rs
parentfix(hosts/server2): Use correct path to `vhack.eu/nixos-server` repo (diff)
downloadnixos-server-a3111a5d214db66b7d676940b8f8bfda5074bd45.zip
fix(pkgs/back): Use rocket to manage the configuration values
This reduces the amount of needed `unwraps`/`expects` and allows us to
streamline the parsing processes.
Diffstat (limited to '')
-rw-r--r--pkgs/by-name/ba/back/src/web/mod.rs (renamed from pkgs/by-name/ba/back/src/issues/mod.rs)35
1 files changed, 17 insertions, 18 deletions
diff --git a/pkgs/by-name/ba/back/src/issues/mod.rs b/pkgs/by-name/ba/back/src/web/mod.rs
index 744d5ba..ed91e7e 100644
--- a/pkgs/by-name/ba/back/src/issues/mod.rs
+++ b/pkgs/by-name/ba/back/src/web/mod.rs
@@ -12,19 +12,17 @@
 use std::path::Path;
 
 use crate::{
-    issues::issue::{Issue, Status},
-    SOURCE_CODE_REPOSITORY,
+    config::BackConfig,
+    web::issue::{Issue, Status},
 };
-use format::BackString;
 use gix::{refs::Target, Repository};
 use issue_show::BackPrefix;
 use rocket::{
     get,
     response::content::{RawCss, RawHtml},
+    State,
 };
 
-use crate::REPOSITORY;
-
 mod format;
 mod issue;
 mod issue_show;
@@ -51,8 +49,12 @@ fn list_all_issues(repo: &'_ Repository) -> Vec<Issue<'_>> {
         .collect()
 }
 
-pub fn issue_list_boilerplate(wanted_status: Status, counter_status: Status) -> RawHtml<String> {
-    let repository = REPOSITORY.get().expect("This should have been set");
+pub fn issue_list_boilerplate(
+    config: &State<BackConfig>,
+    wanted_status: Status,
+    counter_status: Status,
+) -> RawHtml<String> {
+    let repository = &config.repository;
 
     let issue_list = list_all_issues(&repository.to_thread_local())
         .iter()
@@ -94,25 +96,22 @@ pub fn issue_list_boilerplate(wanted_status: Status, counter_status: Status) ->
    </body>
 </html>
 "#,
-        SOURCE_CODE_REPOSITORY.get().expect("This should be set")
+        config.source_code_repository_url
     ))
 }
 
 #[get("/issues/open")]
-pub fn open() -> RawHtml<String> {
-    issue_list_boilerplate(Status::Open, Status::Closed)
+pub fn open(config: &State<BackConfig>) -> RawHtml<String> {
+    issue_list_boilerplate(config, Status::Open, Status::Closed)
 }
 #[get("/issues/closed")]
-pub fn closed() -> RawHtml<String> {
-    issue_list_boilerplate(Status::Closed, Status::Open)
+pub fn closed(config: &State<BackConfig>) -> RawHtml<String> {
+    issue_list_boilerplate(config, Status::Closed, Status::Open)
 }
 
 #[get("/issue/<prefix>")]
-pub fn show_issue(prefix: BackPrefix) -> RawHtml<String> {
-    let repository = REPOSITORY
-        .get()
-        .expect("This should have been set")
-        .to_thread_local();
+pub fn show_issue(config: &State<BackConfig>, prefix: BackPrefix) -> RawHtml<String> {
+    let repository = config.repository.to_thread_local();
 
     let all_issues = list_all_issues(&repository);
     let maybe_issue = all_issues
@@ -120,7 +119,7 @@ pub fn show_issue(prefix: BackPrefix) -> RawHtml<String> {
         .find(|issue| issue.id.to_string().starts_with(&prefix.to_string()));
 
     match maybe_issue {
-        Some(issue) => issue.to_html(),
+        Some(issue) => issue.to_html(config),
         None => RawHtml(format!("Issue with id '{prefix}' not found!")),
     }
 }