Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions svc/pkg/team/ops/member-relationship-get/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ async fn handle(
.users
.iter()
.map(|x| -> GlobalResult<(Uuid, Uuid)> {
Ok((
Ok(util::sort::id_pair(
unwrap_ref!(x.this_user_id).as_uuid(),
unwrap_ref!(x.other_user_id).as_uuid(),
))
Expand All @@ -19,9 +19,11 @@ async fn handle(

// Query relationships
let relationships = sql_fetch_all!(
[ctx, (Vec<Uuid>,)]
[ctx, (Uuid, Uuid, Vec<Uuid>,)]
"
SELECT
(q->>0)::UUID AS this_user_id,
(q->>1)::UUID AS other_user_id,
ARRAY(
SELECT this_tm.team_id
FROM db_team.team_members AS this_tm
Expand All @@ -35,16 +37,17 @@ async fn handle(
.await?;

let users = relationships
.iter()
.map(
|(team_ids,)| team::member_relationship_get::response::User {
.into_iter()
.map(|(this_user_id, other_user_id, team_ids)| {
team::member_relationship_get::response::User {
this_user_id: Some(this_user_id.into()),
other_user_id: Some(other_user_id.into()),
shared_team_ids: team_ids
.iter()
.cloned()
.into_iter()
.map(Into::<common::Uuid>::into)
.collect(),
},
)
}
})
.collect();

Ok(team::member_relationship_get::Response { users })
Expand Down
50 changes: 26 additions & 24 deletions svc/pkg/team/ops/member-relationship-get/tests/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ async fn basic(ctx: TestCtx) {
.flat_map(|&this_user| {
all_user_ids
.iter()
.map(move |&other_user| (this_user, other_user))
.map(move |&other_user| util::sort::id_pair(this_user, other_user))
})
.collect::<Vec<_>>();
.collect::<HashSet<_>>();
let test_users = tests
.iter()
.map(
Expand All @@ -67,28 +67,30 @@ async fn basic(ctx: TestCtx) {
.await
.unwrap();

res.users
.iter()
.zip(tests.iter())
.for_each(|(relationship, &(this_user, other_user))| {
let res_shared_team_ids = relationship
.shared_team_ids
.iter()
.map(|x| x.as_uuid())
.collect::<HashSet<Uuid>>();
assert_eq!(tests.len(), res.users.len());

let this_team_ids = memberships
.iter()
.filter(|m| m.0 == this_user)
.map(|m| m.1)
.collect::<HashSet<Uuid>>();
let shared_team_ids = memberships
.iter()
.filter(|m| m.0 == other_user)
.filter(|m| this_team_ids.contains(&m.1))
.map(|m| m.1)
.collect::<HashSet<Uuid>>();
res.users.iter().for_each(|relationship| {
let this_user_id = relationship.this_user_id.unwrap().as_uuid();
let other_user_id = relationship.other_user_id.unwrap().as_uuid();

let res_shared_team_ids = relationship
.shared_team_ids
.iter()
.map(|x| x.as_uuid())
.collect::<HashSet<Uuid>>();

let this_team_ids = memberships
.iter()
.filter(|m| m.0 == this_user_id)
.map(|m| m.1)
.collect::<HashSet<Uuid>>();
let shared_team_ids = memberships
.iter()
.filter(|m| m.0 == other_user_id)
.filter(|m| this_team_ids.contains(&m.1))
.map(|m| m.1)
.collect::<HashSet<Uuid>>();

assert_eq!(shared_team_ids, res_shared_team_ids, "bad shared team ids");
});
assert_eq!(shared_team_ids, res_shared_team_ids, "bad shared team ids");
});
}
2 changes: 2 additions & 0 deletions svc/pkg/team/types/member-relationship-get.proto
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ message Request {

message Response {
message User {
rivet.common.Uuid this_user_id = 2;
rivet.common.Uuid other_user_id = 3;
repeated rivet.common.Uuid shared_team_ids = 1;
}

Expand Down