Bump to latest diesel, stub search function
This commit is contained in:
parent
96f8480b2d
commit
65f3e268dc
6 changed files with 43 additions and 8 deletions
12
Cargo.lock
generated
12
Cargo.lock
generated
|
@ -4,7 +4,7 @@ version = "0.7.1"
|
|||
dependencies = [
|
||||
"ape 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"app_dirs 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"diesel 0.16.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"diesel 0.16.0 (git+https://github.com/diesel-rs/diesel?rev=034049d)",
|
||||
"diesel_codegen 0.16.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"error-chain 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"getopts 0.2.15 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
|
@ -311,6 +311,15 @@ dependencies = [
|
|||
"syn 0.11.11 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "diesel"
|
||||
version = "0.16.0"
|
||||
source = "git+https://github.com/diesel-rs/diesel?rev=034049d#034049d38565393bf09d59dbe1e7ad38a8934295"
|
||||
dependencies = [
|
||||
"byteorder 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"libsqlite3-sys 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "diesel"
|
||||
version = "0.16.0"
|
||||
|
@ -1770,6 +1779,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||
"checksum derive-error-chain 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)" = "3c9ca9ade651388daad7c993f005d0d20c4f6fe78c1cdc93e95f161c6f5ede4a"
|
||||
"checksum derive_builder 0.4.7 (registry+https://github.com/rust-lang/crates.io-index)" = "c614a69851b5fbf329a89c612c193d256c0dbb31b7a35eecff6f4b9578521c33"
|
||||
"checksum derive_builder_core 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "eed37eae64daa5511467b1a55cebdf472deeaef108d22f62f25e8bbcaffd56ac"
|
||||
"checksum diesel 0.16.0 (git+https://github.com/diesel-rs/diesel?rev=034049d)" = "<none>"
|
||||
"checksum diesel 0.16.0 (registry+https://github.com/rust-lang/crates.io-index)" = "304226fa7a3982b0405f6bb95dd9c10c3e2000709f194038a60ec2c277150951"
|
||||
"checksum diesel_codegen 0.16.0 (registry+https://github.com/rust-lang/crates.io-index)" = "18a42ca5c9b660add51d58bc5a50a87123380e1e458069c5504528a851ed7384"
|
||||
"checksum diesel_infer_schema 0.16.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bf1957ff5cd3b04772e43c162c2f69c2aa918080ff9b020276792d236be8be52"
|
||||
|
|
|
@ -9,7 +9,7 @@ ui = []
|
|||
[dependencies]
|
||||
ape = "0.1.2"
|
||||
app_dirs = "1.1.1"
|
||||
diesel = { version = "0.16.0", features = ["sqlite"] }
|
||||
diesel = { git = "https://github.com/diesel-rs/diesel", rev = "034049d", features = ["sqlite"] }
|
||||
diesel_codegen = { version = "0.16.0", features = ["sqlite"] }
|
||||
error-chain = "0.11.0"
|
||||
getopts = "0.2.15"
|
||||
|
|
16
src/api.rs
16
src/api.rs
|
@ -112,6 +112,11 @@ fn get_endpoints(db: Arc<DB>, index_channel: Arc<Mutex<Sender<index::Command>>>)
|
|||
auth_api_mount.mount("/recent/",
|
||||
move |request: &mut Request| self::recent(request, db.deref()));
|
||||
}
|
||||
{
|
||||
let db = db.clone();
|
||||
auth_api_mount.mount("/search/",
|
||||
move |request: &mut Request| self::search(request, db.deref()));
|
||||
}
|
||||
{
|
||||
let db = db.clone();
|
||||
auth_api_mount.mount("/serve/",
|
||||
|
@ -429,6 +434,17 @@ fn recent(_: &mut Request, db: &DB) -> IronResult<Response> {
|
|||
Ok(Response::with((status::Ok, result_json)))
|
||||
}
|
||||
|
||||
fn search(request: &mut Request, db: &DB) -> IronResult<Response> {
|
||||
let query = "Stratovarius"; // TODO
|
||||
let search_result = index::search(db, &query)?;
|
||||
let result_json = serde_json::to_string(&search_result);
|
||||
let result_json = match result_json {
|
||||
Ok(j) => j,
|
||||
Err(e) => return Err(IronError::new(e, status::InternalServerError)),
|
||||
};
|
||||
Ok(Response::with((status::Ok, result_json)))
|
||||
}
|
||||
|
||||
fn serve(request: &mut Request, db: &DB) -> IronResult<Response> {
|
||||
let virtual_path = path_from_request(request);
|
||||
let virtual_path = match virtual_path {
|
||||
|
|
13
src/index.rs
13
src/index.rs
|
@ -1,6 +1,6 @@
|
|||
use core::ops::Deref;
|
||||
use diesel;
|
||||
use diesel::expression::sql;
|
||||
use diesel::dsl::sql;
|
||||
use diesel::prelude::*;
|
||||
use diesel::sqlite::SqliteConnection;
|
||||
use diesel::types;
|
||||
|
@ -576,6 +576,17 @@ pub fn get_recent_albums<T>(db: &T, count: i64) -> Result<Vec<Directory>>
|
|||
Ok(virtual_directories.collect::<Vec<_>>())
|
||||
}
|
||||
|
||||
pub fn search<T>(db: &T, query: &str) -> Result<Vec<CollectionFile>>
|
||||
where T: ConnectionSource + VFSSource
|
||||
{
|
||||
Ok(vec![])
|
||||
// Find dirs with matching path and parent not matching
|
||||
|
||||
|
||||
// Find songs with matching title/album/artist
|
||||
// Remove songs within a matched directory
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_populate() {
|
||||
let db = db::_get_test_db("populate.sqlite");
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use core::clone::Clone;
|
||||
use core::ops::Deref;
|
||||
use diesel;
|
||||
use diesel::expression::sql;
|
||||
use diesel::dsl::sql;
|
||||
use diesel::prelude::*;
|
||||
use diesel::BelongingToDsl;
|
||||
use diesel::types::*;
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
use core::ops::Deref;
|
||||
use diesel;
|
||||
use diesel::expression;
|
||||
use diesel::prelude::*;
|
||||
use rand;
|
||||
use ring::{digest, pbkdf2};
|
||||
|
@ -76,9 +75,8 @@ pub fn count<T>(db: &T) -> Result<i64>
|
|||
{
|
||||
use db::users::dsl::*;
|
||||
let connection = db.get_connection();
|
||||
Ok(users
|
||||
.select(expression::count(name))
|
||||
.first(connection.deref())?)
|
||||
let count = users.count().get_result(connection.deref())?;
|
||||
Ok(count)
|
||||
}
|
||||
|
||||
pub fn is_admin<T>(db: &T, username: &str) -> Result<bool>
|
||||
|
|
Loading…
Add table
Reference in a new issue