Track and untrack refs
This commit is contained in:
parent
4af950b6a4
commit
7e0bf21223
10 changed files with 134 additions and 25 deletions
58
src/server/web/admin/refs.rs
Normal file
58
src/server/web/admin/refs.rs
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
use axum::{
|
||||
extract::State,
|
||||
response::{IntoResponse, Redirect},
|
||||
Form,
|
||||
};
|
||||
use log::info;
|
||||
use serde::Deserialize;
|
||||
use sqlx::SqlitePool;
|
||||
|
||||
use crate::{
|
||||
config::ServerConfig,
|
||||
server::web::{
|
||||
base::Base,
|
||||
paths::{PathAdminRefsTrack, PathAdminRefsUntrack, PathIndex},
|
||||
},
|
||||
somehow,
|
||||
};
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct FormAdminRefsTrack {
|
||||
r#ref: String,
|
||||
}
|
||||
|
||||
pub async fn post_admin_refs_track(
|
||||
_path: PathAdminRefsTrack,
|
||||
State(config): State<&'static ServerConfig>,
|
||||
State(db): State<SqlitePool>,
|
||||
Form(form): Form<FormAdminRefsTrack>,
|
||||
) -> somehow::Result<impl IntoResponse> {
|
||||
let result = sqlx::query!("UPDATE refs SET tracked = 1 WHERE name = ?", form.r#ref)
|
||||
.execute(&db)
|
||||
.await?;
|
||||
|
||||
if result.rows_affected() > 0 {
|
||||
info!("Admin tracked {}", form.r#ref);
|
||||
}
|
||||
|
||||
let link = Base::link_with_config(config, PathIndex {});
|
||||
Ok(Redirect::to(&link.to_string()))
|
||||
}
|
||||
|
||||
pub async fn post_admin_refs_untrack(
|
||||
_path: PathAdminRefsUntrack,
|
||||
State(config): State<&'static ServerConfig>,
|
||||
State(db): State<SqlitePool>,
|
||||
Form(form): Form<FormAdminRefsTrack>,
|
||||
) -> somehow::Result<impl IntoResponse> {
|
||||
let result = sqlx::query!("UPDATE refs SET tracked = 0 WHERE name = ?", form.r#ref)
|
||||
.execute(&db)
|
||||
.await?;
|
||||
|
||||
if result.rows_affected() > 0 {
|
||||
info!("Admin untracked {}", form.r#ref);
|
||||
}
|
||||
|
||||
let link = Base::link_with_config(config, PathIndex {});
|
||||
Ok(Redirect::to(&link.to_string()))
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue