user_client_consented_scope_repository.rs
1 use sqlx::Transaction; 2 3 use crate::{ 4 models::{ 5 client_scope::ClientScope, user_client_consent::UserClientConsent, 6 user_client_consented_scope::UserClientConsentedScope, 7 }, 8 util::accounts_error::AccountsResult, 9 }; 10 11 use super::DB; 12 13 pub async fn insert( 14 transaction: &mut Transaction<'_, DB>, 15 client_consent: &UserClientConsent, 16 client_scope: &ClientScope, 17 ) -> AccountsResult<UserClientConsentedScope> { 18 Ok(sqlx::query_as!( 19 UserClientConsentedScope, 20 " 21 INSERT INTO user_client_consented_scope(user_client_consent_id, client_scope_id) 22 VALUES ($1, $2) 23 RETURNING id, user_client_consent_id, client_scope_id, created_at 24 ", 25 client_consent.id, 26 client_scope.id 27 ) 28 .fetch_one(&mut **transaction) 29 .await?) 30 } 31 32 pub async fn delete_by_client_scope( 33 transaction: &mut Transaction<'_, DB>, 34 client_scope: &ClientScope, 35 ) -> AccountsResult<Vec<UserClientConsentedScope>> { 36 Ok(sqlx::query_as!( 37 UserClientConsentedScope, 38 " 39 DELETE 40 FROM user_client_consented_scope 41 WHERE client_scope_id =$1 42 RETURNING id, user_client_consent_id, client_scope_id, created_at 43 ", 44 client_scope.id 45 ) 46 .fetch_all(&mut **transaction) 47 .await?) 48 }