From dda4418cf521127a192bcc8e159c499be2e14e31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Kleinb=C3=B6lting?= Date: Mon, 29 Jul 2024 12:38:14 +0200 Subject: [PATCH 1/6] Add robots.txt and sitemap.xml --- dsp-meta-cmd/src/main-server.rs | 6 +++ dsp-meta/src/api/handler/mod.rs | 2 + .../src/api/handler/robots_txt_handler.rs | 22 ++++++++++ .../src/api/handler/sitemap_xml_handler.rs | 43 +++++++++++++++++++ dsp-meta/src/api/router.rs | 22 +++++++--- dsp-meta/src/app_state.rs | 2 + .../service/project_metadata_api_contract.rs | 1 + .../service/project_metadata_service.rs | 4 ++ .../src/domain/service/repository_contract.rs | 5 ++- .../service/project_metadata_repository.rs | 6 +++ 10 files changed, 106 insertions(+), 7 deletions(-) create mode 100644 dsp-meta/src/api/handler/robots_txt_handler.rs create mode 100644 dsp-meta/src/api/handler/sitemap_xml_handler.rs diff --git a/dsp-meta-cmd/src/main-server.rs b/dsp-meta-cmd/src/main-server.rs index b552ad77..c5a93188 100644 --- a/dsp-meta-cmd/src/main-server.rs +++ b/dsp-meta-cmd/src/main-server.rs @@ -12,6 +12,7 @@ use tokio::net::TcpListener; use tracing::info; use tracing_subscriber::prelude::*; use tracing_subscriber::{fmt, EnvFilter}; +use url::Url; fn main() { // Do the pid1 magic. Needs to be the first thing executed. @@ -64,12 +65,17 @@ async fn init_server() { .get::("public_dir") .unwrap_or("/public".to_string()); + let base_url = settings + .get::("base_url") + .unwrap_or(Url::parse("http://localhost:3000").unwrap()); + let shared_state = Arc::new(AppState { project_metadata_service: ProjectMetadataService::new(ProjectMetadataRepository::new( Path::new(&data_dir), )), public_dir, version: VERSION, + base_url }); // start the server diff --git a/dsp-meta/src/api/handler/mod.rs b/dsp-meta/src/api/handler/mod.rs index d67ef8a5..7275e713 100644 --- a/dsp-meta/src/api/handler/mod.rs +++ b/dsp-meta/src/api/handler/mod.rs @@ -1,2 +1,4 @@ pub mod health; pub mod project_metadata_handler; +pub mod sitemap_xml_handler; +pub mod robots_txt_handler; diff --git a/dsp-meta/src/api/handler/robots_txt_handler.rs b/dsp-meta/src/api/handler/robots_txt_handler.rs new file mode 100644 index 00000000..1608af8a --- /dev/null +++ b/dsp-meta/src/api/handler/robots_txt_handler.rs @@ -0,0 +1,22 @@ +use std::sync::Arc; + +use axum::extract::State; +use axum::http::{Response, StatusCode}; + +use crate::app_state::AppState; +use crate::error::DspMetaError; + +pub async fn robots_txt_handler( + State(state): State>, +) -> Result, DspMetaError> { + let sitemap_xml = state.base_url.join( "sitemap.xml").expect("valid url").to_string(); + let response = Response::builder() + .status(StatusCode::OK) + .header("Content-Type", "text/plain") + .body(format!( + "Sitemap: {}\nUser-agent: *\nDisallow:\n", + sitemap_xml + )) + .expect("Failed to build response"); + Ok(response) +} diff --git a/dsp-meta/src/api/handler/sitemap_xml_handler.rs b/dsp-meta/src/api/handler/sitemap_xml_handler.rs new file mode 100644 index 00000000..3ebee813 --- /dev/null +++ b/dsp-meta/src/api/handler/sitemap_xml_handler.rs @@ -0,0 +1,43 @@ +use std::sync::Arc; + +use axum::extract::State; +use axum::http::StatusCode; +use axum::response::Response; +use tracing::instrument; + +use crate::app_state::AppState; +use crate::domain::service::project_metadata_api_contract::ProjectMetadataApiContract; +use crate::error::DspMetaError; + +#[instrument(skip(state))] +pub async fn sitemap_xml_handler( + State(state): State>, +) -> Result, DspMetaError> { + let base_url = state.base_url.clone(); + let mut xml = String::from("\n"); + xml.push_str("\n"); + xml.push_str( + format!( + "{}weekly\n", + base_url + ) + .as_str(), + ); + for meta in state.project_metadata_service.find_all()? { + let mut url = base_url.to_string() + "projects/"; + url.push_str(&meta.project.shortcode.as_string()); + let line = format!( + "{}weekly\n", + url + ); + xml.push_str(line.as_str()); + } + xml.push_str("\n"); + + let resp = Response::builder() + .status(StatusCode::OK) + .header("Content-Type", "application/xml") + .body(xml) + .expect("Failed to build response"); + Ok(resp) +} diff --git a/dsp-meta/src/api/router.rs b/dsp-meta/src/api/router.rs index 14fad46b..083e9996 100644 --- a/dsp-meta/src/api/router.rs +++ b/dsp-meta/src/api/router.rs @@ -1,19 +1,21 @@ use std::sync::Arc; use std::time::Duration; +use axum::{http, Router}; use axum::body::Bytes; use axum::http::{HeaderMap, Request}; use axum::response::Response; use axum::routing::get; -use axum::{http, Router}; use log::info; use tower_http::classify::ServerErrorsFailureClass; use tower_http::cors::{Any, CorsLayer}; use tower_http::services::{ServeDir, ServeFile}; use tower_http::trace::TraceLayer; -use tracing::{error, info_span, warn, Span}; +use tracing::{error, info_span, Span, warn}; -use crate::api::handler::{health, project_metadata_handler}; +use crate::api::handler::{ + health, project_metadata_handler, robots_txt_handler, sitemap_xml_handler, +}; use crate::app_state::AppState; /// Having a function that produces our router makes it easy to call it from tests @@ -35,6 +37,8 @@ pub fn router(shared_state: Arc) -> Router { ) .route("/health", get(health::health_handler)) .route("/version.txt", get(shared_state.version)) + .route("/robots.txt", get(robots_txt_handler::robots_txt_handler)) + .route("/sitemap.xml", get(sitemap_xml_handler::sitemap_xml_handler)) .fallback_service( ServeDir::new(shared_state.public_dir.as_str()).fallback(ServeFile::new(format!( "{}/index.html", @@ -84,13 +88,17 @@ mod tests { use axum::body::Body; use axum::http::StatusCode; - use http_body_util::BodyExt; // for `collect` - use tower::ServiceExt; // for `oneshot` and `ready` + use http_body_util::BodyExt; + // for `collect` + use tower::ServiceExt; + use url::Url; - use super::*; use crate::domain::service::project_metadata_service::ProjectMetadataService; use crate::repo::service::project_metadata_repository::ProjectMetadataRepository; + // for `oneshot` and `ready` + use super::*; + #[tokio::test] async fn test_health_route() { let data_dir = env::current_dir().unwrap().parent().unwrap().join("data"); @@ -101,6 +109,7 @@ mod tests { )), public_dir: "".to_string(), version: "", + base_url: Url::parse("http://localhost:3000").unwrap(), }); let router = router(shared_state); @@ -133,6 +142,7 @@ mod tests { )), public_dir: "".to_string(), version: "", + base_url: Url::parse("http://localhost:3000").unwrap(), }); let router = router(shared_state); diff --git a/dsp-meta/src/app_state.rs b/dsp-meta/src/app_state.rs index cb4ad636..07faf36b 100644 --- a/dsp-meta/src/app_state.rs +++ b/dsp-meta/src/app_state.rs @@ -1,3 +1,4 @@ +use url::Url; use crate::domain::service::project_metadata_service::ProjectMetadataService; use crate::repo::service::project_metadata_repository::ProjectMetadataRepository; @@ -6,4 +7,5 @@ pub struct AppState { pub project_metadata_service: ProjectMetadataService, pub public_dir: String, pub version: &'static str, + pub base_url: Url } diff --git a/dsp-meta/src/domain/service/project_metadata_api_contract.rs b/dsp-meta/src/domain/service/project_metadata_api_contract.rs index fc3b577a..2c31d86c 100644 --- a/dsp-meta/src/domain/service/project_metadata_api_contract.rs +++ b/dsp-meta/src/domain/service/project_metadata_api_contract.rs @@ -4,6 +4,7 @@ use crate::error::DspMetaError; pub trait ProjectMetadataApiContract { fn find_by_id(&self, id: &Shortcode) -> Result, DspMetaError>; + fn find_all(&self) -> Result, DspMetaError>; fn find( &self, filter: &Filter, diff --git a/dsp-meta/src/domain/service/project_metadata_service.rs b/dsp-meta/src/domain/service/project_metadata_service.rs index be375f0f..32519d10 100644 --- a/dsp-meta/src/domain/service/project_metadata_service.rs +++ b/dsp-meta/src/domain/service/project_metadata_service.rs @@ -28,6 +28,10 @@ where self.repo.find_by_id(id) } + fn find_all(&self) -> Result, DspMetaError> { + self.repo.find_all() + } + #[instrument(skip(self))] fn find( &self, diff --git a/dsp-meta/src/domain/service/repository_contract.rs b/dsp-meta/src/domain/service/repository_contract.rs index 4dd15460..284ae79c 100644 --- a/dsp-meta/src/domain/service/repository_contract.rs +++ b/dsp-meta/src/domain/service/repository_contract.rs @@ -34,9 +34,12 @@ pub trait RepositoryContract { /// If the entity does not exist, `None` is returned. fn find_by_id(&self, id: &Id) -> Result, Error>; - /// Returns all entities. + /// Returns all entities with filter and pagination. fn find(&self, filter: &Filter, pagination: &Pagination) -> Result, Error>; + /// Returns all entities. + fn find_all(&self) -> Result, Error>; + /// Returns the number of entities. fn count(&self) -> Result; } diff --git a/dsp-meta/src/repo/service/project_metadata_repository.rs b/dsp-meta/src/repo/service/project_metadata_repository.rs index 7c8f90c9..815c8793 100644 --- a/dsp-meta/src/repo/service/project_metadata_repository.rs +++ b/dsp-meta/src/repo/service/project_metadata_repository.rs @@ -106,6 +106,12 @@ impl RepositoryContract for ProjectMetad Ok(Page { data, total }) } + fn find_all(&self) -> Result, DspMetaError> { + let db = self.db.read().unwrap(); + let v = db.iter().map(|(_, v)| v.clone()).collect(); + Ok(v) + } + fn count(&self) -> Result { let db = self.db.read().unwrap(); Ok(db.len()) From 87c9eee668a2fe9c3c65df37f423e99910c732af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Kleinb=C3=B6lting?= Date: Mon, 29 Jul 2024 12:49:34 +0200 Subject: [PATCH 2/6] refactor: Align module structure with api --- dsp-meta/src/api/handler/health.rs | 2 +- dsp-meta/src/api/handler/mod.rs | 6 ++--- .../{robots_txt_handler.rs => robots_txt.rs} | 2 +- ...{sitemap_xml_handler.rs => sitemap_xml.rs} | 2 +- dsp-meta/src/api/handler/v1/mod.rs | 1 + .../projects/handler.rs} | 7 +++--- dsp-meta/src/api/handler/v1/projects/mod.rs | 2 ++ .../v1/projects/responses.rs} | 0 dsp-meta/src/api/mod.rs | 1 - dsp-meta/src/api/model/mod.rs | 2 -- .../api/model/project_metadata_graph_dto.rs | 18 --------------- dsp-meta/src/api/router.rs | 23 ++++++++----------- 12 files changed, 22 insertions(+), 44 deletions(-) rename dsp-meta/src/api/handler/{robots_txt_handler.rs => robots_txt.rs} (94%) rename dsp-meta/src/api/handler/{sitemap_xml_handler.rs => sitemap_xml.rs} (97%) create mode 100644 dsp-meta/src/api/handler/v1/mod.rs rename dsp-meta/src/api/handler/{project_metadata_handler.rs => v1/projects/handler.rs} (91%) create mode 100644 dsp-meta/src/api/handler/v1/projects/mod.rs rename dsp-meta/src/api/{model/project_metadata_dto.rs => handler/v1/projects/responses.rs} (100%) delete mode 100644 dsp-meta/src/api/model/mod.rs delete mode 100644 dsp-meta/src/api/model/project_metadata_graph_dto.rs diff --git a/dsp-meta/src/api/handler/health.rs b/dsp-meta/src/api/handler/health.rs index 50d9b26d..ff97b68b 100644 --- a/dsp-meta/src/api/handler/health.rs +++ b/dsp-meta/src/api/handler/health.rs @@ -1,6 +1,6 @@ use tracing::trace; -pub(crate) async fn health_handler() -> &'static str { +pub(crate) async fn health() -> &'static str { trace!("entered health_handler()"); "healthy" } diff --git a/dsp-meta/src/api/handler/mod.rs b/dsp-meta/src/api/handler/mod.rs index 7275e713..d9acf9a1 100644 --- a/dsp-meta/src/api/handler/mod.rs +++ b/dsp-meta/src/api/handler/mod.rs @@ -1,4 +1,4 @@ pub mod health; -pub mod project_metadata_handler; -pub mod sitemap_xml_handler; -pub mod robots_txt_handler; +pub mod v1; +pub mod sitemap_xml; +pub mod robots_txt; diff --git a/dsp-meta/src/api/handler/robots_txt_handler.rs b/dsp-meta/src/api/handler/robots_txt.rs similarity index 94% rename from dsp-meta/src/api/handler/robots_txt_handler.rs rename to dsp-meta/src/api/handler/robots_txt.rs index 1608af8a..2304eccf 100644 --- a/dsp-meta/src/api/handler/robots_txt_handler.rs +++ b/dsp-meta/src/api/handler/robots_txt.rs @@ -6,7 +6,7 @@ use axum::http::{Response, StatusCode}; use crate::app_state::AppState; use crate::error::DspMetaError; -pub async fn robots_txt_handler( +pub async fn robots_txt( State(state): State>, ) -> Result, DspMetaError> { let sitemap_xml = state.base_url.join( "sitemap.xml").expect("valid url").to_string(); diff --git a/dsp-meta/src/api/handler/sitemap_xml_handler.rs b/dsp-meta/src/api/handler/sitemap_xml.rs similarity index 97% rename from dsp-meta/src/api/handler/sitemap_xml_handler.rs rename to dsp-meta/src/api/handler/sitemap_xml.rs index 3ebee813..8adc0110 100644 --- a/dsp-meta/src/api/handler/sitemap_xml_handler.rs +++ b/dsp-meta/src/api/handler/sitemap_xml.rs @@ -10,7 +10,7 @@ use crate::domain::service::project_metadata_api_contract::ProjectMetadataApiCon use crate::error::DspMetaError; #[instrument(skip(state))] -pub async fn sitemap_xml_handler( +pub async fn sitemap_xml( State(state): State>, ) -> Result, DspMetaError> { let base_url = state.base_url.clone(); diff --git a/dsp-meta/src/api/handler/v1/mod.rs b/dsp-meta/src/api/handler/v1/mod.rs new file mode 100644 index 00000000..435b2cda --- /dev/null +++ b/dsp-meta/src/api/handler/v1/mod.rs @@ -0,0 +1 @@ +pub mod projects; \ No newline at end of file diff --git a/dsp-meta/src/api/handler/project_metadata_handler.rs b/dsp-meta/src/api/handler/v1/projects/handler.rs similarity index 91% rename from dsp-meta/src/api/handler/project_metadata_handler.rs rename to dsp-meta/src/api/handler/v1/projects/handler.rs index eb1fea54..4fcda00f 100644 --- a/dsp-meta/src/api/handler/project_metadata_handler.rs +++ b/dsp-meta/src/api/handler/v1/projects/handler.rs @@ -5,8 +5,7 @@ use axum::http::StatusCode; use axum::response::{IntoResponse, Response}; use axum::Json; use tracing::{instrument, trace}; - -use crate::api::model::project_metadata_dto::{ProjectMetadataDto, ProjectMetadataWithInfoDto}; +use crate::api::handler::v1::projects::responses::{ProjectMetadataDto, ProjectMetadataWithInfoDto}; use crate::app_state::AppState; use crate::domain::model::draft_model::Shortcode; use crate::domain::service::project_metadata_api_contract::ProjectMetadataApiContract; @@ -18,7 +17,7 @@ use crate::error::DspMetaError; /// /// TODO: Add error handling with correct status codes #[instrument(skip(state))] -pub async fn get_project_metadata_by_shortcode( +pub async fn get_by_shortcode( Path(shortcode): Path, State(state): State>, ) -> Result { @@ -37,7 +36,7 @@ pub async fn get_project_metadata_by_shortcode( } #[instrument(skip(state))] -pub async fn get_all_project_metadata( +pub async fn get_by_page_and_filter( State(state): State>, pagination: Option>, filter: Option>, diff --git a/dsp-meta/src/api/handler/v1/projects/mod.rs b/dsp-meta/src/api/handler/v1/projects/mod.rs new file mode 100644 index 00000000..75f3ffc6 --- /dev/null +++ b/dsp-meta/src/api/handler/v1/projects/mod.rs @@ -0,0 +1,2 @@ +pub mod responses; +pub mod handler; \ No newline at end of file diff --git a/dsp-meta/src/api/model/project_metadata_dto.rs b/dsp-meta/src/api/handler/v1/projects/responses.rs similarity index 100% rename from dsp-meta/src/api/model/project_metadata_dto.rs rename to dsp-meta/src/api/handler/v1/projects/responses.rs diff --git a/dsp-meta/src/api/mod.rs b/dsp-meta/src/api/mod.rs index 1c78b6d7..f984e2d6 100644 --- a/dsp-meta/src/api/mod.rs +++ b/dsp-meta/src/api/mod.rs @@ -1,4 +1,3 @@ pub mod convert; mod handler; -mod model; pub mod router; diff --git a/dsp-meta/src/api/model/mod.rs b/dsp-meta/src/api/model/mod.rs deleted file mode 100644 index 97b864c9..00000000 --- a/dsp-meta/src/api/model/mod.rs +++ /dev/null @@ -1,2 +0,0 @@ -pub mod project_metadata_dto; -pub mod project_metadata_graph_dto; diff --git a/dsp-meta/src/api/model/project_metadata_graph_dto.rs b/dsp-meta/src/api/model/project_metadata_graph_dto.rs deleted file mode 100644 index 624541bf..00000000 --- a/dsp-meta/src/api/model/project_metadata_graph_dto.rs +++ /dev/null @@ -1,18 +0,0 @@ -use axum::http::StatusCode; -use axum::response::{IntoResponse, Response}; - -use crate::api::convert::rdf::project_metadata::ProjectMetadataGraph; - -pub struct ProjectMetadataGraphDto(pub Option); - -/// Convert `ProjectMetadataGraph` into a response. -impl IntoResponse for ProjectMetadataGraphDto { - fn into_response(self) -> Response { - match self.0 { - Some(metadata_graph) => { - (StatusCode::OK, metadata_graph.to_turtle_string()).into_response() - } - None => StatusCode::NOT_FOUND.into_response(), - } - } -} diff --git a/dsp-meta/src/api/router.rs b/dsp-meta/src/api/router.rs index 083e9996..3bc69f5a 100644 --- a/dsp-meta/src/api/router.rs +++ b/dsp-meta/src/api/router.rs @@ -1,21 +1,19 @@ use std::sync::Arc; use std::time::Duration; -use axum::{http, Router}; use axum::body::Bytes; use axum::http::{HeaderMap, Request}; use axum::response::Response; use axum::routing::get; +use axum::{http, Router}; use log::info; use tower_http::classify::ServerErrorsFailureClass; use tower_http::cors::{Any, CorsLayer}; use tower_http::services::{ServeDir, ServeFile}; use tower_http::trace::TraceLayer; -use tracing::{error, info_span, Span, warn}; +use tracing::{error, info_span, warn, Span}; -use crate::api::handler::{ - health, project_metadata_handler, robots_txt_handler, sitemap_xml_handler, -}; +use crate::api::handler::{health, robots_txt, sitemap_xml, v1}; use crate::app_state::AppState; /// Having a function that produces our router makes it easy to call it from tests @@ -29,16 +27,16 @@ pub fn router(shared_state: Arc) -> Router { Router::new() .route( "/api/v1/projects", - get(project_metadata_handler::get_all_project_metadata), + get(v1::projects::handler::get_by_page_and_filter), ) .route( "/api/v1/projects/:shortcode", - get(project_metadata_handler::get_project_metadata_by_shortcode), + get(v1::projects::handler::get_by_shortcode), ) - .route("/health", get(health::health_handler)) + .route("/health", get(health::health)) .route("/version.txt", get(shared_state.version)) - .route("/robots.txt", get(robots_txt_handler::robots_txt_handler)) - .route("/sitemap.xml", get(sitemap_xml_handler::sitemap_xml_handler)) + .route("/robots.txt", get(robots_txt::robots_txt)) + .route("/sitemap.xml", get(sitemap_xml::sitemap_xml)) .fallback_service( ServeDir::new(shared_state.public_dir.as_str()).fallback(ServeFile::new(format!( "{}/index.html", @@ -93,11 +91,10 @@ mod tests { use tower::ServiceExt; use url::Url; - use crate::domain::service::project_metadata_service::ProjectMetadataService; - use crate::repo::service::project_metadata_repository::ProjectMetadataRepository; - // for `oneshot` and `ready` use super::*; + use crate::domain::service::project_metadata_service::ProjectMetadataService; + use crate::repo::service::project_metadata_repository::ProjectMetadataRepository; #[tokio::test] async fn test_health_route() { From fea4c7d9675dd68f391dd3aa81d57c57f4425931 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Kleinb=C3=B6lting?= Date: Mon, 29 Jul 2024 12:52:09 +0200 Subject: [PATCH 3/6] make snackbar easier on the eyes with fading in and out a bit slower --- web-frontend/src/Snackbar.svelte | 2 +- web-frontend/src/project-page/ProjectPage.svelte | 2 +- web-frontend/src/projects-repository/ProjectsRepository.svelte | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/web-frontend/src/Snackbar.svelte b/web-frontend/src/Snackbar.svelte index 3f786c12..eec1be5f 100644 --- a/web-frontend/src/Snackbar.svelte +++ b/web-frontend/src/Snackbar.svelte @@ -18,7 +18,7 @@ }) -
+
{$handleSnackbar.message}
diff --git a/web-frontend/src/project-page/ProjectPage.svelte b/web-frontend/src/project-page/ProjectPage.svelte index d3ff1446..0a80b597 100644 --- a/web-frontend/src/project-page/ProjectPage.svelte +++ b/web-frontend/src/project-page/ProjectPage.svelte @@ -94,7 +94,7 @@ {/if} {#if $projectMetadata} -
+
{#if mobileResolution}
{/if} -
+
{#if $pagedResults && $pagedResults.length} {#each $pagedResults as project} From d9dcd19eac7571ec0a7c6c1087dd5ccd7a9978e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Kleinb=C3=B6lting?= Date: Mon, 29 Jul 2024 12:52:35 +0200 Subject: [PATCH 4/6] module naming --- .../src/api/handler/v1/projects/{handler.rs => handlers.rs} | 0 dsp-meta/src/api/handler/v1/projects/mod.rs | 2 +- dsp-meta/src/api/router.rs | 4 ++-- 3 files changed, 3 insertions(+), 3 deletions(-) rename dsp-meta/src/api/handler/v1/projects/{handler.rs => handlers.rs} (100%) diff --git a/dsp-meta/src/api/handler/v1/projects/handler.rs b/dsp-meta/src/api/handler/v1/projects/handlers.rs similarity index 100% rename from dsp-meta/src/api/handler/v1/projects/handler.rs rename to dsp-meta/src/api/handler/v1/projects/handlers.rs diff --git a/dsp-meta/src/api/handler/v1/projects/mod.rs b/dsp-meta/src/api/handler/v1/projects/mod.rs index 75f3ffc6..0fff11a2 100644 --- a/dsp-meta/src/api/handler/v1/projects/mod.rs +++ b/dsp-meta/src/api/handler/v1/projects/mod.rs @@ -1,2 +1,2 @@ pub mod responses; -pub mod handler; \ No newline at end of file +pub mod handlers; \ No newline at end of file diff --git a/dsp-meta/src/api/router.rs b/dsp-meta/src/api/router.rs index 3bc69f5a..938edb4f 100644 --- a/dsp-meta/src/api/router.rs +++ b/dsp-meta/src/api/router.rs @@ -27,11 +27,11 @@ pub fn router(shared_state: Arc) -> Router { Router::new() .route( "/api/v1/projects", - get(v1::projects::handler::get_by_page_and_filter), + get(v1::projects::handlers::get_by_page_and_filter), ) .route( "/api/v1/projects/:shortcode", - get(v1::projects::handler::get_by_shortcode), + get(v1::projects::handlers::get_by_shortcode), ) .route("/health", get(health::health)) .route("/version.txt", get(shared_state.version)) From 235046edb0b96c693759d52c8b79a158706515d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Kleinb=C3=B6lting?= Date: Mon, 29 Jul 2024 12:53:26 +0200 Subject: [PATCH 5/6] fmt --- dsp-meta-cmd/src/main-server.rs | 2 +- dsp-meta/src/api/handler/mod.rs | 4 ++-- dsp-meta/src/api/handler/robots_txt.rs | 6 +++++- dsp-meta/src/api/handler/v1/mod.rs | 2 +- dsp-meta/src/api/handler/v1/projects/handlers.rs | 5 ++++- dsp-meta/src/api/handler/v1/projects/mod.rs | 2 +- dsp-meta/src/app_state.rs | 3 ++- 7 files changed, 16 insertions(+), 8 deletions(-) diff --git a/dsp-meta-cmd/src/main-server.rs b/dsp-meta-cmd/src/main-server.rs index c5a93188..308b6820 100644 --- a/dsp-meta-cmd/src/main-server.rs +++ b/dsp-meta-cmd/src/main-server.rs @@ -75,7 +75,7 @@ async fn init_server() { )), public_dir, version: VERSION, - base_url + base_url, }); // start the server diff --git a/dsp-meta/src/api/handler/mod.rs b/dsp-meta/src/api/handler/mod.rs index d9acf9a1..91f59bf3 100644 --- a/dsp-meta/src/api/handler/mod.rs +++ b/dsp-meta/src/api/handler/mod.rs @@ -1,4 +1,4 @@ pub mod health; -pub mod v1; -pub mod sitemap_xml; pub mod robots_txt; +pub mod sitemap_xml; +pub mod v1; diff --git a/dsp-meta/src/api/handler/robots_txt.rs b/dsp-meta/src/api/handler/robots_txt.rs index 2304eccf..beba0c6d 100644 --- a/dsp-meta/src/api/handler/robots_txt.rs +++ b/dsp-meta/src/api/handler/robots_txt.rs @@ -9,7 +9,11 @@ use crate::error::DspMetaError; pub async fn robots_txt( State(state): State>, ) -> Result, DspMetaError> { - let sitemap_xml = state.base_url.join( "sitemap.xml").expect("valid url").to_string(); + let sitemap_xml = state + .base_url + .join("sitemap.xml") + .expect("valid url") + .to_string(); let response = Response::builder() .status(StatusCode::OK) .header("Content-Type", "text/plain") diff --git a/dsp-meta/src/api/handler/v1/mod.rs b/dsp-meta/src/api/handler/v1/mod.rs index 435b2cda..b42e1c67 100644 --- a/dsp-meta/src/api/handler/v1/mod.rs +++ b/dsp-meta/src/api/handler/v1/mod.rs @@ -1 +1 @@ -pub mod projects; \ No newline at end of file +pub mod projects; diff --git a/dsp-meta/src/api/handler/v1/projects/handlers.rs b/dsp-meta/src/api/handler/v1/projects/handlers.rs index 4fcda00f..85e52e1f 100644 --- a/dsp-meta/src/api/handler/v1/projects/handlers.rs +++ b/dsp-meta/src/api/handler/v1/projects/handlers.rs @@ -5,7 +5,10 @@ use axum::http::StatusCode; use axum::response::{IntoResponse, Response}; use axum::Json; use tracing::{instrument, trace}; -use crate::api::handler::v1::projects::responses::{ProjectMetadataDto, ProjectMetadataWithInfoDto}; + +use crate::api::handler::v1::projects::responses::{ + ProjectMetadataDto, ProjectMetadataWithInfoDto, +}; use crate::app_state::AppState; use crate::domain::model::draft_model::Shortcode; use crate::domain::service::project_metadata_api_contract::ProjectMetadataApiContract; diff --git a/dsp-meta/src/api/handler/v1/projects/mod.rs b/dsp-meta/src/api/handler/v1/projects/mod.rs index 0fff11a2..6108acf9 100644 --- a/dsp-meta/src/api/handler/v1/projects/mod.rs +++ b/dsp-meta/src/api/handler/v1/projects/mod.rs @@ -1,2 +1,2 @@ +pub mod handlers; pub mod responses; -pub mod handlers; \ No newline at end of file diff --git a/dsp-meta/src/app_state.rs b/dsp-meta/src/app_state.rs index 07faf36b..868ce50a 100644 --- a/dsp-meta/src/app_state.rs +++ b/dsp-meta/src/app_state.rs @@ -1,4 +1,5 @@ use url::Url; + use crate::domain::service::project_metadata_service::ProjectMetadataService; use crate::repo::service::project_metadata_repository::ProjectMetadataRepository; @@ -7,5 +8,5 @@ pub struct AppState { pub project_metadata_service: ProjectMetadataService, pub public_dir: String, pub version: &'static str, - pub base_url: Url + pub base_url: Url, } From 2b4f8082a0c3371502783be261df7b8976583a00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Kleinb=C3=B6lting?= Date: Mon, 29 Jul 2024 13:04:58 +0200 Subject: [PATCH 6/6] revert non snackbar transistions --- web-frontend/src/project-page/ProjectPage.svelte | 2 +- web-frontend/src/projects-repository/ProjectsRepository.svelte | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/web-frontend/src/project-page/ProjectPage.svelte b/web-frontend/src/project-page/ProjectPage.svelte index 0a80b597..d64c1ca8 100644 --- a/web-frontend/src/project-page/ProjectPage.svelte +++ b/web-frontend/src/project-page/ProjectPage.svelte @@ -94,7 +94,7 @@ {/if} {#if $projectMetadata} -
+
{#if mobileResolution}
{/if} -
+
{#if $pagedResults && $pagedResults.length} {#each $pagedResults as project}