Move /commit/:hash/enqueue to /admin/queue/add
This commit is contained in:
parent
08e240d7db
commit
087ecfd783
9 changed files with 113 additions and 40 deletions
46
src/server/web/admin/queue.rs
Normal file
46
src/server/web/admin/queue.rs
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
use axum::{
|
||||
extract::State,
|
||||
response::{IntoResponse, Redirect},
|
||||
Form,
|
||||
};
|
||||
use axum_extra::routing::TypedPath;
|
||||
use serde::Deserialize;
|
||||
use sqlx::SqlitePool;
|
||||
use time::OffsetDateTime;
|
||||
|
||||
use crate::{config::Config, somehow};
|
||||
|
||||
#[derive(Deserialize, TypedPath)]
|
||||
#[typed_path("/admin/queue/add")]
|
||||
pub struct PathAdminQueueAdd {}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct FormAdminQueueAdd {
|
||||
hash: String,
|
||||
#[serde(default)]
|
||||
priority: i32,
|
||||
}
|
||||
|
||||
pub async fn post_admin_queue_add(
|
||||
_path: PathAdminQueueAdd,
|
||||
State(config): State<&'static Config>,
|
||||
State(db): State<SqlitePool>,
|
||||
Form(form): Form<FormAdminQueueAdd>,
|
||||
) -> somehow::Result<impl IntoResponse> {
|
||||
let date = OffsetDateTime::now_utc();
|
||||
sqlx::query!(
|
||||
"\
|
||||
INSERT INTO queue (hash, date, priority) VALUES (?, ?, ?) \
|
||||
ON CONFLICT (hash) DO UPDATE \
|
||||
SET priority = excluded.priority WHERE priority < excluded.priority \
|
||||
",
|
||||
form.hash,
|
||||
date,
|
||||
form.priority,
|
||||
)
|
||||
.execute(&db)
|
||||
.await?;
|
||||
|
||||
// TODO Replace with typed link
|
||||
Ok(Redirect::to(&format!("{}queue/", config.web_base)))
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue