feat: gacha roll
This commit is contained in:
+1
-4
@@ -1,6 +1,5 @@
|
||||
use crate::{AppState, RedisClient, SurrealClient};
|
||||
use axum::{response::Redirect, routing::get, Extension, Router};
|
||||
use utoipa_swagger_ui::SwaggerUi;
|
||||
use axum::{Extension, Router};
|
||||
|
||||
pub mod v1;
|
||||
pub mod v2;
|
||||
@@ -8,9 +7,7 @@ pub mod v2;
|
||||
pub async fn apps(surrealdb: SurrealClient, redisdb: RedisClient) -> Router {
|
||||
let state = AppState { surrealdb, redisdb };
|
||||
Router::new()
|
||||
.route("/", get(Redirect::to("/docs")))
|
||||
.nest("/v1", v1::routes().await)
|
||||
.nest("/v2", v2::routes().await)
|
||||
.merge(SwaggerUi::new("/docs").url("/openapi.json", v1::docs_router()))
|
||||
.layer(Extension(state))
|
||||
}
|
||||
|
||||
@@ -61,7 +61,12 @@ impl<'a> AuthRepository<'a> {
|
||||
let db = &self.state.surrealdb;
|
||||
let record: Option<UsersItemDto> = db
|
||||
.create((ResourceEnum::Users.to_string(), &data.email))
|
||||
.content(data)
|
||||
.content(UsersSchema {
|
||||
fullname: data.fullname.clone(),
|
||||
email: data.email.clone(),
|
||||
password: data.password.clone(),
|
||||
is_active: false,
|
||||
})
|
||||
.await?;
|
||||
match record {
|
||||
Some(_) => Ok("Success create user".into()),
|
||||
|
||||
@@ -4,11 +4,11 @@ use axum::{http::HeaderMap, response::IntoResponse, Extension, Json};
|
||||
|
||||
#[utoipa::path(
|
||||
post,
|
||||
path = "/v1/gacha/create/claims",
|
||||
path = "/v1/gacha/create/claim",
|
||||
request_body = GachaCreateClaimRequestDto,
|
||||
responses(
|
||||
(status = 200, description = "Create gacha claims successful", body = MessageResponseDto),
|
||||
(status = 401, description = "Create gacha claims failed", body = MessageResponseDto)
|
||||
(status = 200, description = "Create gacha claim successful", body = MessageResponseDto),
|
||||
(status = 401, description = "Create gacha claim failed", body = MessageResponseDto)
|
||||
),
|
||||
tag = "Gacha"
|
||||
)]
|
||||
|
||||
@@ -5,6 +5,7 @@ use crate::v1::UsersItemDto;
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize, ToSchema)]
|
||||
pub struct GachaCreateClaimRequestDto {
|
||||
pub item_name: String,
|
||||
pub transaction_number: String,
|
||||
}
|
||||
|
||||
|
||||
@@ -61,6 +61,11 @@ impl<'a> GachaRepository<'a> {
|
||||
let user_thing =
|
||||
Thing::from((ResourceEnum::Users.to_string(), Id::String(user.email)));
|
||||
|
||||
let item_thing = Thing::from((
|
||||
ResourceEnum::GachaItems.to_string(),
|
||||
Id::String(data.item_name.clone()),
|
||||
));
|
||||
|
||||
let record: Option<GachaClaimSchema> = db
|
||||
.create((
|
||||
ResourceEnum::GachaClaims.to_string(),
|
||||
@@ -68,6 +73,7 @@ impl<'a> GachaRepository<'a> {
|
||||
))
|
||||
.content(GachaClaimSchema {
|
||||
transaction_number: data.transaction_number.clone(),
|
||||
item: item_thing,
|
||||
user: user_thing,
|
||||
})
|
||||
.await?;
|
||||
|
||||
@@ -4,6 +4,7 @@ use surrealdb::sql::Thing;
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
pub struct GachaClaimSchema {
|
||||
pub transaction_number: String,
|
||||
pub item: Thing,
|
||||
pub user: Thing,
|
||||
}
|
||||
|
||||
|
||||
+7
-1
@@ -8,11 +8,17 @@ pub use auth::*;
|
||||
pub use docs::*;
|
||||
pub use gacha::*;
|
||||
pub use users::*;
|
||||
use utoipa_swagger_ui::SwaggerUi;
|
||||
|
||||
pub async fn routes() -> Router {
|
||||
let public_routes = Router::new().nest("/auth", auth_router());
|
||||
|
||||
let protected_routes = Router::new()
|
||||
.nest("/gacha", gacha_router())
|
||||
.layer(from_fn(auth::auth_middleware::auth_middleware));
|
||||
Router::new().merge(public_routes).merge(protected_routes)
|
||||
|
||||
Router::new()
|
||||
.merge(public_routes)
|
||||
.merge(protected_routes)
|
||||
.merge(SwaggerUi::new("/v1/docs").url("/openapi.json", docs_router()))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user