1
0
Fork 0
mirror of https://codeberg.org/Mo8it/git-webhook-client synced 2024-10-18 07:22:39 +00:00

Accept negative and missing ids

This commit is contained in:
Mo 2022-10-13 21:59:14 +02:00
parent f32d7a2451
commit 6c3157f049
2 changed files with 17 additions and 4 deletions

View file

@ -45,7 +45,14 @@ pub fn add_hook_log(pool: &DBPool, hook: &Hook, output: &Output) -> i32 {
pub fn get_hook_log(pool: &DBPool, id: i32) -> HookLog { pub fn get_hook_log(pool: &DBPool, id: i32) -> HookLog {
let conn = &mut pool.get().unwrap(); let conn = &mut pool.get().unwrap();
use hooklog::dsl::hooklog;
hooklog.find(id).first(conn).unwrap() if id >= 0 {
hooklog::dsl::hooklog.find(id).first(conn).unwrap()
} else {
hooklog::dsl::hooklog
.order(hooklog::dsl::id.desc())
.offset((-id - 1).into())
.first(conn)
.unwrap()
}
} }

View file

@ -5,9 +5,15 @@ use crate::db;
use crate::guards; use crate::guards;
use crate::states; use crate::states;
#[get("/<id>")] #[get("/?<id>")]
pub fn index(db_state: &State<states::DB>, id: i32) -> String { pub fn index(db_state: &State<states::DB>, id: Option<i32>) -> String {
let id = match id {
Some(id) => id,
None => -1,
};
let hook_log = db::get_hook_log(&db_state.pool, id); let hook_log = db::get_hook_log(&db_state.pool, id);
format!( format!(
"Hook log id: "Hook log id:
{} {}