Skip to content

Conversation

tsurbs
Copy link
Contributor

@tsurbs tsurbs commented Aug 20, 2025

No description provided.

@tsurbs tsurbs requested a review from ap-1 August 20, 2025 02:00
Self { db }
}

pub async fn get_ccup_total_purchased(&self, user_dorm: &str) -> Result<i32, sea_orm::DbErr> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can probably be done with one database call. I haven't read into this code thoroughly, but something like this may work:

let total: Option<i32> = Transaction::find()
    .inner_join(User)
    .filter(transaction::Column::RewardName.eq("Carnegie Cup Contribution"))
    .filter(user::Column::Dorm.eq(user_dorm))
    .select_only()
    .column_as(transaction::Column::Count.sum(), "total")
    .into_tuple::<i32>()
    .one(&self.db)
    .await?;
    
Ok(total.unwrap_or(0))

@tsurbs tsurbs merged commit 0e85bc1 into main Aug 20, 2025
0 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants