Show individual tasks

This commit is contained in:
Joscha 2023-08-06 21:47:48 +02:00
parent 171505d7ec
commit 2b81d497bc
5 changed files with 176 additions and 0 deletions

View file

@ -2,6 +2,7 @@ mod commit;
mod commit_hash;
mod index;
mod queue;
mod queue_id;
mod r#static;
use axum::{routing::get, Router, Server};
@ -45,6 +46,7 @@ pub async fn run(state: AppState) -> somehow::Result<()> {
.route("/commit/:hash", get(commit_hash::get))
.route("/queue/", get(queue::get))
.route("/queue/table", get(queue::get_table))
.route("/queue/:id", get(queue_id::get))
.fallback(get(r#static::static_handler))
.with_state(state.clone());

65
src/web/queue_id.rs Normal file
View file

@ -0,0 +1,65 @@
use askama::Template;
use axum::{
extract::{Path, State},
http::StatusCode,
response::{IntoResponse, Response},
};
use sqlx::SqlitePool;
use crate::{config::Config, somehow, util};
use super::{Base, Tab};
#[derive(Template)]
#[template(path = "queue_id.html")]
struct QueueIdTemplate {
base: Base,
// Task
id: String,
hash: String,
date: String,
priority: i64,
// Commit
summary: String,
short: String,
reachable: i64,
}
pub async fn get(
Path(id): Path<String>,
State(config): State<&'static Config>,
State(db): State<SqlitePool>,
) -> somehow::Result<Response> {
let Some(task) = sqlx::query!(
"\
SELECT \
id, \
hash, \
date AS \"date: time::OffsetDateTime\", \
priority, \
message, \
reachable \
FROM queue \
JOIN commits USING (hash) \
WHERE id = ? \
",
id
)
.fetch_optional(&db)
.await?
else {
return Ok(StatusCode::NOT_FOUND.into_response());
};
Ok(QueueIdTemplate {
base: Base::new(config, Tab::Queue),
date: util::format_time(task.date),
id: task.id,
priority: task.priority,
summary: util::format_commit_summary(&task.message),
short: util::format_commit_short(&task.hash, &task.message),
hash: task.hash,
reachable: task.reachable,
}
.into_response())
}