mirror of
https://codeberg.org/Mo8it/git-webhook-client
synced 2024-11-24 11:21:36 +00:00
Accept negative and missing ids
This commit is contained in:
parent
f32d7a2451
commit
6c3157f049
2 changed files with 17 additions and 4 deletions
11
src/db.rs
11
src/db.rs
|
@ -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()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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:
|
||||||
{}
|
{}
|
||||||
|
|
Loading…
Reference in a new issue