mirror of https://github.com/raftario/filite.git
Added delete routes
This commit is contained in:
parent
e81acf7349
commit
014f593303
|
@ -58,6 +58,24 @@ fn find_error<T>(error: BlockingError<diesel::result::Error>) -> Result<T, actix
|
|||
}
|
||||
}
|
||||
|
||||
/// DELETE an entry
|
||||
macro_rules! delete {
|
||||
($m:ident) => {
|
||||
pub fn delete(
|
||||
path: web::Path<String>,
|
||||
pool: web::Data<Pool>,
|
||||
) -> impl Future<Item = HttpResponse, Error = Error> {
|
||||
let id = parse_id!(&path);
|
||||
Either::A(web::block(move || queries::$m::delete(id, pool)).then(
|
||||
|result| match result {
|
||||
Ok(()) => Ok(HttpResponse::NoContent().finish()),
|
||||
Err(e) => find_error(e),
|
||||
},
|
||||
))
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/// Formats a timestamp to the "Last-Modified" header format
|
||||
fn timestamp_to_last_modified(timestamp: i32) -> String {
|
||||
let datetime =
|
||||
|
@ -177,6 +195,8 @@ pub mod files {
|
|||
}),
|
||||
)
|
||||
}
|
||||
|
||||
delete!(files);
|
||||
}
|
||||
|
||||
pub mod links {
|
||||
|
@ -225,6 +245,8 @@ pub mod links {
|
|||
pool
|
||||
))))
|
||||
}
|
||||
|
||||
delete!(links);
|
||||
}
|
||||
|
||||
pub mod texts {
|
||||
|
@ -272,4 +294,6 @@ pub mod texts {
|
|||
pool
|
||||
))))
|
||||
}
|
||||
|
||||
delete!(texts);
|
||||
}
|
||||
|
|
15
src/main.rs
15
src/main.rs
|
@ -83,10 +83,19 @@ fn main() {
|
|||
.data(web::Json::<handlers::files::PutFile>::configure(|cfg| {
|
||||
cfg.limit(max_filesize)
|
||||
}))
|
||||
.route(web::put().to_async(handlers::files::put)),
|
||||
.route(web::put().to_async(handlers::files::put))
|
||||
.route(web::delete().to_async(handlers::files::delete)),
|
||||
)
|
||||
.service(
|
||||
web::resource("/l/{id}")
|
||||
.route(web::put().to_async(handlers::links::put))
|
||||
.route(web::delete().to_async(handlers::links::delete)),
|
||||
)
|
||||
.service(
|
||||
web::resource("/t/{id}")
|
||||
.route(web::put().to_async(handlers::texts::put))
|
||||
.route(web::delete().to_async(handlers::texts::delete)),
|
||||
)
|
||||
.service(web::resource("/l/{id}").route(web::put().to_async(handlers::links::put)))
|
||||
.service(web::resource("/t/{id}").route(web::put().to_async(handlers::texts::put)))
|
||||
})
|
||||
.bind(&format!("localhost:{}", port))
|
||||
.unwrap_or_else(|e| {
|
||||
|
|
Loading…
Reference in New Issue