Skip to content

Commit

Permalink
Merge branch 'main' into dependabot/npm_and_yarn/web-frontend/ws-7.5.10
Browse files Browse the repository at this point in the history
  • Loading branch information
seakayone authored Jul 29, 2024
2 parents e59102e + 3d5d1ca commit 9a7e341
Show file tree
Hide file tree
Showing 23 changed files with 143 additions and 71 deletions.
55 changes: 21 additions & 34 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ tokio = { version = "1", features = ["rt", "macros", "rt-multi-thread"] }
tokio-test = "0.4.2"
tower = "0.4.13"
tower-http = { version = "0.5.0", features = ["trace", "fs", "cors"] }
hyper = "1.0.1"
hyper = "1.4.1"
regex = "1.5.4"
thiserror = "1.0.56"
tracing = "0.1"
Expand Down
6 changes: 6 additions & 0 deletions dsp-meta-cmd/src/main-server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -64,12 +65,17 @@ async fn init_server() {
.get::<String>("public_dir")
.unwrap_or("/public".to_string());

let base_url = settings
.get::<Url>("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
Expand Down
2 changes: 1 addition & 1 deletion dsp-meta/src/api/handler/health.rs
Original file line number Diff line number Diff line change
@@ -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"
}
4 changes: 3 additions & 1 deletion dsp-meta/src/api/handler/mod.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
pub mod health;
pub mod project_metadata_handler;
pub mod robots_txt;
pub mod sitemap_xml;
pub mod v1;
26 changes: 26 additions & 0 deletions dsp-meta/src/api/handler/robots_txt.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
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(
State(state): State<Arc<AppState>>,
) -> Result<Response<String>, 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)
}
43 changes: 43 additions & 0 deletions dsp-meta/src/api/handler/sitemap_xml.rs
Original file line number Diff line number Diff line change
@@ -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(
State(state): State<Arc<AppState>>,
) -> Result<Response<String>, DspMetaError> {
let base_url = state.base_url.clone();
let mut xml = String::from("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
xml.push_str("<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">\n");
xml.push_str(
format!(
"<url><loc>{}</loc><changefreq>weekly</changefreq></url>\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!(
"<url><loc>{}</loc><changefreq>weekly</changefreq></url>\n",
url
);
xml.push_str(line.as_str());
}
xml.push_str("</urlset>\n");

let resp = Response::builder()
.status(StatusCode::OK)
.header("Content-Type", "application/xml")
.body(xml)
.expect("Failed to build response");
Ok(resp)
}
1 change: 1 addition & 0 deletions dsp-meta/src/api/handler/v1/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod projects;
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ 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;
Expand All @@ -18,7 +20,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<Shortcode>,
State(state): State<Arc<AppState>>,
) -> Result<Response, DspMetaError> {
Expand All @@ -37,7 +39,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<Arc<AppState>>,
pagination: Option<Query<Pagination>>,
filter: Option<Query<Filter>>,
Expand Down
2 changes: 2 additions & 0 deletions dsp-meta/src/api/handler/v1/projects/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pub mod handlers;
pub mod responses;
1 change: 0 additions & 1 deletion dsp-meta/src/api/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
pub mod convert;
mod handler;
mod model;
pub mod router;
2 changes: 0 additions & 2 deletions dsp-meta/src/api/model/mod.rs

This file was deleted.

18 changes: 0 additions & 18 deletions dsp-meta/src/api/model/project_metadata_graph_dto.rs

This file was deleted.

Loading

0 comments on commit 9a7e341

Please sign in to comment.