Fix block user route, send correct user struct.

Add route for fetching members.
Cargo fmt on accident.
This commit is contained in:
Paul
2021-05-14 22:29:43 +01:00
parent cc0307f702
commit 6cc92b877e
19 changed files with 184 additions and 133 deletions

View File

@@ -14,7 +14,7 @@ use validator::Validate;
#[derive(Serialize, Deserialize, FromFormValue)]
pub enum Sort {
Latest,
Oldest
Oldest,
}
#[derive(Validate, Serialize, Deserialize, FromForm)]
@@ -25,7 +25,7 @@ pub struct Options {
before: Option<String>,
#[validate(length(min = 26, max = 26))]
after: Option<String>,
sort: Option<Sort>
sort: Option<Sort>,
}
#[get("/<target>/messages?<options..>")]
@@ -54,7 +54,11 @@ pub async fn req(user: User, target: Ref, options: Form<Options>) -> Result<Json
query.insert("_id", doc! { "$gt": after });
}
let sort = if let Sort::Latest = options.sort.as_ref().unwrap_or_else(|| &Sort::Latest) { -1 } else { 1 };
let sort = if let Sort::Latest = options.sort.as_ref().unwrap_or_else(|| &Sort::Latest) {
-1
} else {
1
};
let mut cursor = get_collection("messages")
.find(
query,