mirror of
https://codeberg.org/Mo8it/git-webhook-client
synced 2024-11-21 11:06:32 +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 {
|
||||
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::states;
|
||||
|
||||
#[get("/<id>")]
|
||||
pub fn index(db_state: &State<states::DB>, id: i32) -> String {
|
||||
#[get("/?<id>")]
|
||||
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);
|
||||
|
||||
format!(
|
||||
"Hook log id:
|
||||
{}
|
||||
|
|
Loading…
Reference in a new issue