Skip to content

Commit ef8d7e5

Browse files
feat: add MemberRolesResponse struct and update member roles query to return structured response
1 parent 9627c79 commit ef8d7e5

2 files changed

Lines changed: 21 additions & 3 deletions

File tree

src/graphql/queries/member_queries.rs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
use crate::auth::guards::AuthGuard;
22
use crate::auth::AuthContext;
3-
use crate::models::{attendance::AttendanceRecord, status_update::StatusUpdateRecord};
3+
use crate::models::{
4+
attendance::AttendanceRecord, member::MemberRolesResponse, status_update::StatusUpdateRecord,
5+
};
46
use async_graphql::{ComplexObject, Context, Object, Result};
57
use chrono::NaiveDate;
68
use sqlx::PgPool;
@@ -96,7 +98,7 @@ impl MemberQueries {
9698
&self,
9799
ctx: &Context<'_>,
98100
#[graphql(name = "discordId")] discord_id: String,
99-
) -> Result<Option<Vec<String>>> {
101+
) -> Result<MemberRolesResponse> {
100102
let pool = ctx.data::<Arc<PgPool>>()?;
101103

102104
let roles: Option<Vec<String>> =
@@ -105,7 +107,17 @@ impl MemberQueries {
105107
.fetch_optional(pool.as_ref())
106108
.await?;
107109

108-
Ok(roles)
110+
if let Some(r) = roles {
111+
Ok(MemberRolesResponse {
112+
exists: true,
113+
roles: r,
114+
})
115+
} else {
116+
Ok(MemberRolesResponse {
117+
exists: false,
118+
roles: vec![],
119+
})
120+
}
109121
}
110122
}
111123

src/models/member.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,9 @@ pub struct UpdateMemberInput {
6060
pub track: Option<String>,
6161
pub github_user: Option<String>,
6262
}
63+
64+
#[derive(SimpleObject)]
65+
pub struct MemberRolesResponse {
66+
pub exists: bool,
67+
pub roles: Vec<String>,
68+
}

0 commit comments

Comments
 (0)