2025-09-26 17:35:30 +07:00
|
|
|
use crate::AppState;
|
|
|
|
|
use imphnen_entities::{MessageResponseDto, ResponseSuccessDto};
|
|
|
|
|
use crate::v1::gacha_rolls::gacha_rolls_dto::{GachaRollItemDto, GachaRollRequestDto};
|
|
|
|
|
use crate::v1::gacha_rolls::gacha_rolls_service::GachaRollService;
|
2025-05-20 10:45:01 +07:00
|
|
|
use axum::{
|
|
|
|
|
Extension, Json, extract::Path, http::HeaderMap, response::IntoResponse,
|
|
|
|
|
};
|
|
|
|
|
use imphnen_iam::{PermissionsEnum, permissions_guard};
|
|
|
|
|
|
|
|
|
|
#[utoipa::path(
|
|
|
|
|
get,
|
|
|
|
|
path = "/v1/gacha/rolls/detail/{id}",
|
|
|
|
|
security(
|
|
|
|
|
("Bearer" = [])
|
|
|
|
|
),
|
|
|
|
|
params(("id" = String, Path, description = "Gacha Roll ID")),
|
|
|
|
|
responses(
|
2025-10-07 17:45:47 +07:00
|
|
|
(status = 200, description = "[ADMIN] Get Gacha Roll by ID", body = ResponseSuccessDto<GachaRollItemDto>)
|
2025-05-20 10:45:01 +07:00
|
|
|
),
|
|
|
|
|
tag = "Gacha"
|
|
|
|
|
)]
|
|
|
|
|
pub async fn get_detail_gacha_roll(
|
|
|
|
|
headers: HeaderMap,
|
|
|
|
|
Extension(state): Extension<AppState>,
|
|
|
|
|
Path(id): Path<String>,
|
|
|
|
|
) -> impl IntoResponse {
|
|
|
|
|
match permissions_guard(
|
2025-08-14 22:46:42 +07:00
|
|
|
headers,
|
|
|
|
|
Extension(state),
|
2025-05-20 10:45:01 +07:00
|
|
|
vec![PermissionsEnum::ReadDetailGachaRolls],
|
|
|
|
|
)
|
|
|
|
|
.await
|
|
|
|
|
{
|
2025-08-14 22:46:42 +07:00
|
|
|
Ok((_user, state)) => GachaRollService::get_gacha_roll_by_id(&state, id).await,
|
2025-05-20 10:45:01 +07:00
|
|
|
Err(response) => response,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[utoipa::path(
|
|
|
|
|
post,
|
|
|
|
|
path = "/v1/gacha/rolls/create",
|
|
|
|
|
security(
|
|
|
|
|
("Bearer" = [])
|
|
|
|
|
),
|
|
|
|
|
request_body = GachaRollRequestDto,
|
|
|
|
|
responses(
|
2025-10-07 17:45:47 +07:00
|
|
|
(status = 201, description = "[ADMIN] Create new gacha roll", body = MessageResponseDto)
|
2025-05-20 10:45:01 +07:00
|
|
|
),
|
|
|
|
|
tag = "Gacha"
|
|
|
|
|
)]
|
|
|
|
|
pub async fn post_create_gacha_roll(
|
|
|
|
|
headers: HeaderMap,
|
|
|
|
|
Extension(state): Extension<AppState>,
|
|
|
|
|
Json(payload): Json<GachaRollRequestDto>,
|
|
|
|
|
) -> impl IntoResponse {
|
|
|
|
|
match permissions_guard(
|
2025-08-14 22:46:42 +07:00
|
|
|
headers,
|
|
|
|
|
Extension(state),
|
2025-05-20 10:45:01 +07:00
|
|
|
vec![PermissionsEnum::CreateGachaRolls],
|
|
|
|
|
)
|
|
|
|
|
.await
|
|
|
|
|
{
|
2025-08-14 22:46:42 +07:00
|
|
|
Ok((_user, state)) => GachaRollService::create_gacha_roll(&state, payload).await,
|
2025-05-20 10:45:01 +07:00
|
|
|
Err(response) => response,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[utoipa::path(
|
|
|
|
|
post,
|
|
|
|
|
path = "/v1/gacha/rolls/execute",
|
|
|
|
|
security(
|
|
|
|
|
("Bearer" = [])
|
|
|
|
|
),
|
|
|
|
|
responses(
|
2025-10-07 17:45:47 +07:00
|
|
|
(status = 200, description = "[ADMIN] Execute and get 1 gacha result", body = ResponseSuccessDto<GachaRollItemDto>)
|
2025-05-20 10:45:01 +07:00
|
|
|
),
|
|
|
|
|
tag = "Gacha"
|
|
|
|
|
)]
|
|
|
|
|
pub async fn post_execute_gacha_roll(
|
|
|
|
|
headers: HeaderMap,
|
|
|
|
|
Extension(state): Extension<AppState>,
|
|
|
|
|
) -> impl IntoResponse {
|
|
|
|
|
match permissions_guard(
|
2025-08-14 22:46:42 +07:00
|
|
|
headers.clone(),
|
|
|
|
|
Extension(state),
|
2025-05-20 10:45:01 +07:00
|
|
|
vec![PermissionsEnum::ExecuteGachaRolls],
|
|
|
|
|
)
|
|
|
|
|
.await
|
|
|
|
|
{
|
2025-08-14 22:46:42 +07:00
|
|
|
Ok((_user, state)) => GachaRollService::execute_roll_once(headers, &state).await,
|
2025-05-20 10:45:01 +07:00
|
|
|
Err(response) => response,
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-07-21 21:29:04 +07:00
|
|
|
|
|
|
|
|
#[utoipa::path(
|
|
|
|
|
delete,
|
|
|
|
|
path = "/v1/gacha/rolls/delete/{id}",
|
|
|
|
|
security(
|
|
|
|
|
("Bearer" = [])
|
|
|
|
|
),
|
|
|
|
|
params(("id" = String, Path, description = "Gacha Roll ID")),
|
|
|
|
|
responses(
|
2025-10-07 17:45:47 +07:00
|
|
|
(status = 200, description = "[ADMIN] Delete Gacha Roll (soft delete)", body = MessageResponseDto)
|
2025-07-21 21:29:04 +07:00
|
|
|
),
|
|
|
|
|
tag = "Gacha"
|
|
|
|
|
)]
|
|
|
|
|
pub async fn delete_gacha_roll(
|
|
|
|
|
headers: HeaderMap,
|
|
|
|
|
Extension(state): Extension<AppState>,
|
|
|
|
|
Path(id): Path<String>,
|
|
|
|
|
) -> impl IntoResponse {
|
|
|
|
|
match permissions_guard(
|
2025-08-14 22:46:42 +07:00
|
|
|
headers,
|
|
|
|
|
Extension(state),
|
2025-07-21 21:29:04 +07:00
|
|
|
vec![PermissionsEnum::DeleteGachaRolls],
|
|
|
|
|
)
|
|
|
|
|
.await
|
|
|
|
|
{
|
2025-08-14 22:46:42 +07:00
|
|
|
Ok((_user, state)) => GachaRollService::soft_delete_gacha_roll(&state, id).await,
|
2025-07-21 21:29:04 +07:00
|
|
|
Err(response) => response,
|
|
|
|
|
}
|
|
|
|
|
}
|