mirror of
https://github.com/storytold/artcraft.git
synced 2026-10-30 05:22:51 -04:00
Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f6bf9d3ab1 |
+91
@@ -0,0 +1,91 @@
|
||||
{
|
||||
"db_name": "MySQL",
|
||||
"query": "\nSELECT\n w.token as `token: tokens::tokens::wallets::WalletToken`,\n w.wallet_namespace as `wallet_namespace: enums::common::payments_namespace::PaymentsNamespace`,\n w.banked_credits as `banked_credits: u32`,\n w.monthly_credits as `monthly_credits: u32`,\n w.version,\n w.created_at as `created_at: DateTime<Utc>`,\n w.updated_at as `updated_at: DateTime<Utc>`\nFROM wallets as w\nWHERE w.owner_user_token = ?\nORDER BY w.id DESC\n ",
|
||||
"describe": {
|
||||
"columns": [
|
||||
{
|
||||
"ordinal": 0,
|
||||
"name": "token: tokens::tokens::wallets::WalletToken",
|
||||
"type_info": {
|
||||
"type": "VarString",
|
||||
"flags": "NOT_NULL | UNIQUE_KEY | BINARY | NO_DEFAULT_VALUE",
|
||||
"char_set": 224,
|
||||
"max_size": 128
|
||||
}
|
||||
},
|
||||
{
|
||||
"ordinal": 1,
|
||||
"name": "wallet_namespace: enums::common::payments_namespace::PaymentsNamespace",
|
||||
"type_info": {
|
||||
"type": "VarString",
|
||||
"flags": "NOT_NULL | MULTIPLE_KEY | BINARY | NO_DEFAULT_VALUE",
|
||||
"char_set": 224,
|
||||
"max_size": 128
|
||||
}
|
||||
},
|
||||
{
|
||||
"ordinal": 2,
|
||||
"name": "banked_credits: u32",
|
||||
"type_info": {
|
||||
"type": "Long",
|
||||
"flags": "NOT_NULL | UNSIGNED",
|
||||
"char_set": 63,
|
||||
"max_size": 10
|
||||
}
|
||||
},
|
||||
{
|
||||
"ordinal": 3,
|
||||
"name": "monthly_credits: u32",
|
||||
"type_info": {
|
||||
"type": "Long",
|
||||
"flags": "NOT_NULL | UNSIGNED",
|
||||
"char_set": 63,
|
||||
"max_size": 10
|
||||
}
|
||||
},
|
||||
{
|
||||
"ordinal": 4,
|
||||
"name": "version",
|
||||
"type_info": {
|
||||
"type": "Long",
|
||||
"flags": "NOT_NULL",
|
||||
"char_set": 63,
|
||||
"max_size": 11
|
||||
}
|
||||
},
|
||||
{
|
||||
"ordinal": 5,
|
||||
"name": "created_at: DateTime<Utc>",
|
||||
"type_info": {
|
||||
"type": "Timestamp",
|
||||
"flags": "NOT_NULL | BINARY | TIMESTAMP",
|
||||
"char_set": 63,
|
||||
"max_size": 19
|
||||
}
|
||||
},
|
||||
{
|
||||
"ordinal": 6,
|
||||
"name": "updated_at: DateTime<Utc>",
|
||||
"type_info": {
|
||||
"type": "Timestamp",
|
||||
"flags": "NOT_NULL | BINARY | TIMESTAMP | ON_UPDATE_NOW",
|
||||
"char_set": 63,
|
||||
"max_size": 19
|
||||
}
|
||||
}
|
||||
],
|
||||
"parameters": {
|
||||
"Right": 1
|
||||
},
|
||||
"nullable": [
|
||||
false,
|
||||
false,
|
||||
false,
|
||||
false,
|
||||
false,
|
||||
false,
|
||||
false
|
||||
]
|
||||
},
|
||||
"hash": "69b6e933ad400bc574204de301dde6748d2a1723f47c12e86afc05033a60d3a2"
|
||||
}
|
||||
@@ -1,2 +1,3 @@
|
||||
pub mod jobs;
|
||||
pub mod user;
|
||||
pub mod wallets;
|
||||
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
use chrono::{DateTime, Utc};
|
||||
use enums::common::payments_namespace::PaymentsNamespace;
|
||||
use serde_derive::{Deserialize, Serialize};
|
||||
use tokens::tokens::users::UserToken;
|
||||
use tokens::tokens::wallets::WalletToken;
|
||||
use utoipa::ToSchema;
|
||||
|
||||
pub const LIST_USER_WALLETS_PATH: &str = "/v1/moderation/wallets/user/{user_token}/list";
|
||||
|
||||
#[derive(Deserialize, ToSchema)]
|
||||
pub struct ListUserWalletsPathInfo {
|
||||
pub user_token: UserToken,
|
||||
}
|
||||
|
||||
#[derive(Serialize, ToSchema)]
|
||||
pub struct ListUserWalletsResponse {
|
||||
pub success: bool,
|
||||
pub wallets: Vec<ListUserWalletsEntry>,
|
||||
}
|
||||
|
||||
#[derive(Serialize, ToSchema)]
|
||||
pub struct ListUserWalletsEntry {
|
||||
pub token: WalletToken,
|
||||
pub wallet_namespace: PaymentsNamespace,
|
||||
pub banked_credits: u32,
|
||||
pub monthly_credits: u32,
|
||||
pub version: i32,
|
||||
pub created_at: DateTime<Utc>,
|
||||
pub updated_at: DateTime<Utc>,
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
pub mod list_user_wallets;
|
||||
+52
@@ -0,0 +1,52 @@
|
||||
use anyhow::anyhow;
|
||||
use log::warn;
|
||||
use sqlx::MySqlPool;
|
||||
|
||||
use chrono::{DateTime, Utc};
|
||||
use enums::common::payments_namespace::PaymentsNamespace;
|
||||
use errors::AnyhowResult;
|
||||
use tokens::tokens::users::UserToken;
|
||||
use tokens::tokens::wallets::WalletToken;
|
||||
|
||||
pub struct UserWalletForModerationResult {
|
||||
pub token: WalletToken,
|
||||
pub wallet_namespace: PaymentsNamespace,
|
||||
pub banked_credits: u32,
|
||||
pub monthly_credits: u32,
|
||||
pub version: i32,
|
||||
pub created_at: DateTime<Utc>,
|
||||
pub updated_at: DateTime<Utc>,
|
||||
}
|
||||
|
||||
pub async fn list_user_wallets_for_moderation(
|
||||
user_token: &UserToken,
|
||||
mysql_pool: &MySqlPool,
|
||||
) -> AnyhowResult<Vec<UserWalletForModerationResult>> {
|
||||
let results = sqlx::query_as!(
|
||||
UserWalletForModerationResult,
|
||||
r#"
|
||||
SELECT
|
||||
w.token as `token: tokens::tokens::wallets::WalletToken`,
|
||||
w.wallet_namespace as `wallet_namespace: enums::common::payments_namespace::PaymentsNamespace`,
|
||||
w.banked_credits as `banked_credits: u32`,
|
||||
w.monthly_credits as `monthly_credits: u32`,
|
||||
w.version,
|
||||
w.created_at as `created_at: DateTime<Utc>`,
|
||||
w.updated_at as `updated_at: DateTime<Utc>`
|
||||
FROM wallets as w
|
||||
WHERE w.owner_user_token = ?
|
||||
ORDER BY w.id DESC
|
||||
"#,
|
||||
user_token,
|
||||
)
|
||||
.fetch_all(mysql_pool)
|
||||
.await;
|
||||
|
||||
match results {
|
||||
Ok(records) => Ok(records),
|
||||
Err(err) => {
|
||||
warn!("list_user_wallets_for_moderation query error: {:?}", err);
|
||||
Err(anyhow!("query error"))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6,4 +6,5 @@ pub mod find_primary_wallet_token_for_owner;
|
||||
pub mod refill_monthly_credits_balance_on_wallet;
|
||||
pub mod refund;
|
||||
pub mod spend;
|
||||
pub mod list_user_wallets_for_moderation;
|
||||
pub mod wallet_update_summary;
|
||||
@@ -268,6 +268,7 @@ use crate::http_server::endpoints::moderation::info::moderator_token_info_handle
|
||||
use artcraft_api_defs::moderation::user::user_lookup::*;
|
||||
use artcraft_api_defs::moderation::user::user_lookup_by_stripe_customer_id::*;
|
||||
use artcraft_api_defs::moderation::jobs::user::list_user_jobs::*;
|
||||
use artcraft_api_defs::moderation::wallets::list_user_wallets::*;
|
||||
use crate::http_server::endpoints::webhooks::fal_webhook_handler::*;
|
||||
use crate::http_server::endpoints::image_studio::update_gpt_image_job_status_handler::*;
|
||||
use crate::http_server::endpoints::voice_conversion::enqueue_seed_vc_inference_handler::*;
|
||||
@@ -440,6 +441,7 @@ use crate::http_server::endpoints::media_files::list::list_batch_generated_redux
|
||||
crate::http_server::endpoints::moderation::user::moderator_user_lookup_handler::moderator_user_lookup_handler,
|
||||
crate::http_server::endpoints::moderation::user::moderator_user_lookup_by_stripe_customer_id_handler::moderator_user_lookup_by_stripe_customer_id_handler,
|
||||
crate::http_server::endpoints::moderation::jobs::user::list_user_jobs_handler::list_user_jobs_handler,
|
||||
crate::http_server::endpoints::moderation::wallets::list_user_wallets_handler::list_user_wallets_handler,
|
||||
// Credits
|
||||
crate::http_server::endpoints::credits::get_session_credits_handler::get_session_credits_handler,
|
||||
// Subscriptions
|
||||
@@ -626,6 +628,9 @@ use crate::http_server::endpoints::media_files::list::list_batch_generated_redux
|
||||
ListUserJobsPathInfo,
|
||||
ListUserJobsResponse,
|
||||
ListUserJobsEntry,
|
||||
ListUserWalletsPathInfo,
|
||||
ListUserWalletsResponse,
|
||||
ListUserWalletsEntry,
|
||||
GptImage1EditImageRequest,
|
||||
GptImage1EditImageImageSize,
|
||||
GptImage1EditImageNumImages,
|
||||
|
||||
@@ -4,3 +4,4 @@ pub mod jobs;
|
||||
pub mod user;
|
||||
pub mod user_bans;
|
||||
pub mod user_feature_flags;
|
||||
pub mod wallets;
|
||||
|
||||
+63
@@ -0,0 +1,63 @@
|
||||
use std::sync::Arc;
|
||||
|
||||
use actix_web::web::{Json, Path};
|
||||
use actix_web::{web, HttpRequest};
|
||||
use log::warn;
|
||||
|
||||
use artcraft_api_defs::moderation::wallets::list_user_wallets::{
|
||||
ListUserWalletsEntry,
|
||||
ListUserWalletsPathInfo,
|
||||
ListUserWalletsResponse,
|
||||
};
|
||||
use mysql_queries::queries::wallets::list_user_wallets_for_moderation::list_user_wallets_for_moderation;
|
||||
|
||||
use crate::http_server::common_responses::common_web_error::CommonWebError;
|
||||
use crate::http_server::web_utils::user_session::require_moderator::{require_moderator, UseDatabase};
|
||||
use crate::state::server_state::ServerState;
|
||||
|
||||
/// List wallets for a user (moderation)
|
||||
#[utoipa::path(
|
||||
get,
|
||||
tag = "Moderation",
|
||||
path = "/v1/moderation/wallets/user/{user_token}/list",
|
||||
responses(
|
||||
(status = 200, description = "Success", body = ListUserWalletsResponse),
|
||||
(status = 401, description = "Unauthorized"),
|
||||
(status = 500, description = "Server error"),
|
||||
),
|
||||
params(
|
||||
("user_token" = UserToken, Path, description = "User token to look up wallets for"),
|
||||
)
|
||||
)]
|
||||
pub async fn list_user_wallets_handler(
|
||||
http_request: HttpRequest,
|
||||
path: Path<ListUserWalletsPathInfo>,
|
||||
server_state: web::Data<Arc<ServerState>>,
|
||||
) -> Result<Json<ListUserWalletsResponse>, CommonWebError> {
|
||||
|
||||
let _user_session = require_moderator(&http_request, &server_state, UseDatabase::Implicit)
|
||||
.await
|
||||
.map_err(|_| CommonWebError::NotAuthorized)?;
|
||||
|
||||
let results = list_user_wallets_for_moderation(&path.user_token, &server_state.mysql_pool)
|
||||
.await
|
||||
.map_err(|err| {
|
||||
warn!("list_user_wallets error: {:?}", err);
|
||||
CommonWebError::ServerError
|
||||
})?;
|
||||
|
||||
let wallets = results.into_iter().map(|row| ListUserWalletsEntry {
|
||||
token: row.token,
|
||||
wallet_namespace: row.wallet_namespace,
|
||||
banked_credits: row.banked_credits,
|
||||
monthly_credits: row.monthly_credits,
|
||||
version: row.version,
|
||||
created_at: row.created_at,
|
||||
updated_at: row.updated_at,
|
||||
}).collect();
|
||||
|
||||
Ok(Json(ListUserWalletsResponse {
|
||||
success: true,
|
||||
wallets,
|
||||
}))
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
pub mod list_user_wallets_handler;
|
||||
+7
@@ -20,6 +20,7 @@ use crate::http_server::endpoints::moderation::ip_bans::delete_ip_ban::delete_ip
|
||||
use crate::http_server::endpoints::moderation::ip_bans::get_ip_ban::get_ip_ban_handler;
|
||||
use crate::http_server::endpoints::moderation::ip_bans::list_ip_bans::list_ip_bans_handler;
|
||||
use crate::http_server::endpoints::moderation::jobs::user::list_user_jobs_handler::list_user_jobs_handler;
|
||||
use crate::http_server::endpoints::moderation::wallets::list_user_wallets_handler::list_user_wallets_handler;
|
||||
use crate::http_server::endpoints::moderation::jobs::get_tts_inference_queue_count::get_tts_inference_queue_count_handler;
|
||||
use crate::http_server::endpoints::moderation::jobs::get_w2l_inference_queue_count::get_w2l_inference_queue_count_handler;
|
||||
use crate::http_server::endpoints::moderation::jobs::kill_tts_inference_jobs::kill_tts_inference_jobs_handler;
|
||||
@@ -61,6 +62,12 @@ pub fn add_moderator_routes<T, B> (app: App<T>) -> App<T>
|
||||
.route(web::head().to(|| HttpResponse::Ok()))
|
||||
)
|
||||
)
|
||||
.service(web::scope("/wallets")
|
||||
.service(web::resource("/user/{user_token}/list")
|
||||
.route(web::get().to(list_user_wallets_handler))
|
||||
.route(web::head().to(|| HttpResponse::Ok()))
|
||||
)
|
||||
)
|
||||
)
|
||||
// NB: Old paths are not under /v1 -
|
||||
.service(web::scope("/moderation")
|
||||
|
||||
Reference in New Issue
Block a user