forked from jmug/stoatchat
feat: strongly type and remaining routes
This commit is contained in:
@@ -1,15 +1,25 @@
|
||||
use revolt_quark::models::User;
|
||||
use revolt_quark::{perms, Database, Error, Ref, Result};
|
||||
|
||||
use rocket::serde::json::Value;
|
||||
use rocket::serde::json::Json;
|
||||
use rocket::State;
|
||||
use serde::Serialize;
|
||||
|
||||
/// # Mutual Friends and Servers Response
|
||||
#[derive(Serialize, JsonSchema)]
|
||||
pub struct MutualResponse {
|
||||
/// Array of mutual user IDs that both users are friends with
|
||||
users: Vec<String>,
|
||||
/// Array of mutual server IDs that both users are in
|
||||
servers: Vec<String>,
|
||||
}
|
||||
|
||||
/// # Fetch Mutual Friends And Servers
|
||||
///
|
||||
/// Retrieve a list of mutual friends and servers with another user.
|
||||
#[openapi(tag = "Relationships")]
|
||||
#[get("/<target>/mutual")]
|
||||
pub async fn req(db: &State<Database>, user: User, target: Ref) -> Result<Value> {
|
||||
pub async fn req(db: &State<Database>, user: User, target: Ref) -> Result<Json<MutualResponse>> {
|
||||
let target = target.as_user(db).await?;
|
||||
|
||||
if perms(&user)
|
||||
@@ -18,9 +28,9 @@ pub async fn req(db: &State<Database>, user: User, target: Ref) -> Result<Value>
|
||||
.await
|
||||
.get_view_profile()
|
||||
{
|
||||
Ok(json!({
|
||||
"users": db.fetch_mutual_user_ids(&user.id, &target.id).await?,
|
||||
"servers": db.fetch_mutual_server_ids(&user.id, &target.id).await?
|
||||
Ok(Json(MutualResponse {
|
||||
users: db.fetch_mutual_user_ids(&user.id, &target.id).await?,
|
||||
servers: db.fetch_mutual_server_ids(&user.id, &target.id).await?,
|
||||
}))
|
||||
} else {
|
||||
Err(Error::NotFound)
|
||||
|
||||
Reference in New Issue
Block a user