mirror of
https://github.com/storytold/artcraft.git
synced 2026-11-05 01:38:44 +00:00
wip
This commit is contained in:
1 parent
70bed32f51
commit
f6ed5abdb7
3 files changed
+46
-1
No files matched your search
+36
@@ -0,0 +1,36 @@
|
||||
use errors::AnyhowResult;
|
||||
use sqlx::MySql;
|
||||
use tokens::tokens::users::UserToken;
|
||||
use tokens::tokens::wallets::WalletToken;
|
||||
|
||||
pub async fn create_new_wallet_for_owner_user(
|
||||
user_token: &UserToken,
|
||||
transaction: &mut sqlx::Transaction<'_, MySql>,
|
||||
) -> AnyhowResult<WalletToken> {
|
||||
let token = WalletToken::generate();
|
||||
|
||||
let result = sqlx::query!(
|
||||
r#"
|
||||
INSERT INTO wallets
|
||||
SET
|
||||
token = ?,
|
||||
|
||||
owner_user_token = ?,
|
||||
|
||||
banked_credits = 0,
|
||||
monthly_credits = 0,
|
||||
|
||||
subscription_is_active = false,
|
||||
subscription_is_paid = false
|
||||
"#,
|
||||
token.as_str(),
|
||||
user_token.as_str()
|
||||
)
|
||||
.execute(&mut **transaction)
|
||||
.await;
|
||||
|
||||
match result {
|
||||
Ok(_) => Ok(token),
|
||||
Err(e) => Err(anyhow::anyhow!("Database query error when creating wallet: {}", e)),
|
||||
}
|
||||
}
|
||||
+8
@@ -9,6 +9,9 @@ pub async fn find_wallet_token_for_owner_user_using_connection(
|
||||
connection: &mut PoolConnection<MySql>,
|
||||
) -> anyhow::Result<Option<WalletToken>> {
|
||||
|
||||
// NB: We want to eventually support multiple wallets per user (eg. company use case),
|
||||
// so we do not have a unique key on user token. In the meantime, to ensure we use the
|
||||
// same wallet each time, we order by id and take the first one.
|
||||
// TODO(bt,2025-08-07): DO NOT COPY THIS. For some reason the query macro can't
|
||||
// decide which impl to use to deserialize typed tokens.
|
||||
let result = sqlx::query_as!(
|
||||
@@ -18,6 +21,7 @@ pub async fn find_wallet_token_for_owner_user_using_connection(
|
||||
token as `token: tokens::tokens::wallets::WalletToken`
|
||||
FROM wallets
|
||||
WHERE owner_user_token = ?
|
||||
ORDER BY id ASC
|
||||
LIMIT 1
|
||||
"#,
|
||||
user_token.as_str()
|
||||
@@ -38,6 +42,9 @@ pub async fn find_wallet_token_for_owner_user_using_transaction(
|
||||
transaction: &mut sqlx::Transaction<'_, MySql>,
|
||||
) -> anyhow::Result<Option<WalletToken>> {
|
||||
|
||||
// NB: We want to eventually support multiple wallets per user (eg. company use case),
|
||||
// so we do not have a unique key on user token. In the meantime, to ensure we use the
|
||||
// same wallet each time, we order by id and take the first one.
|
||||
// TODO(bt,2025-08-07): DO NOT COPY THIS. For some reason the query macro can't
|
||||
// decide which impl to use to deserialize typed tokens.
|
||||
let result = sqlx::query_as!(
|
||||
@@ -47,6 +54,7 @@ pub async fn find_wallet_token_for_owner_user_using_transaction(
|
||||
token as `token: tokens::tokens::wallets::WalletToken`
|
||||
FROM wallets
|
||||
WHERE owner_user_token = ?
|
||||
ORDER BY id ASC
|
||||
LIMIT 1
|
||||
"#,
|
||||
user_token.as_str()
|
||||
|
||||
@@ -1,2 +1,3 @@
|
||||
pub (crate) mod internal_select_wallet_balance_for_update;
|
||||
pub mod find_wallet_token_for_owner_user;
|
||||
pub mod find_wallet_token_for_owner_user;
|
||||
mod create_new_wallet_for_owner_user;
|
||||
Reference in new issue
Block a user