Skip to content
Snippets Groups Projects
Commit 1b711a88 authored by insert's avatar insert
Browse files

Include relationship when fetching a user.

parent b87f396f
Branches
Tags
No related merge requests found
Pipeline #422 passed with stage
in 2 minutes and 22 seconds
use crate::database::entities::User; use crate::database::entities::{RelationshipStatus, User};
use crate::database::guards::reference::Ref; use crate::database::guards::reference::Ref;
use crate::util::result::{Error, Result}; use crate::util::result::{Error, Result};
use rocket_contrib::json::JsonValue; use rocket_contrib::json::JsonValue;
...@@ -16,6 +16,19 @@ pub async fn req(user: User, target: Ref) -> Result<JsonValue> { ...@@ -16,6 +16,19 @@ pub async fn req(user: User, target: Ref) -> Result<JsonValue> {
// Only return user relationships if the target is the caller. // Only return user relationships if the target is the caller.
target.relations = None; target.relations = None;
// Add relevant relationship
if let Some(relationships) = &user.relations {
target.relationship = relationships
.iter()
.find(|x| x.id == user.id)
.map(|x| x.status.clone())
.or_else(|| Some(RelationshipStatus::None));
} else {
target.relationship = Some(RelationshipStatus::None);
}
} else {
target.relationship = Some(RelationshipStatus::User);
} }
Ok(json!(target)) Ok(json!(target))
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment