- Implemented tests for creating, retrieving, updating, and deleting mentors in `mentor_repository_test.rs`. - Added tests for user authentication, including successful login, invalid email formats, and inactive users in `auth_login_tests.rs`. - Created a mock test environment setup in `mock_test.rs` to facilitate database operations during tests. - Updated module structure to include new test files for mentors and authentication. - Ensured cleanup of the database after tests to maintain isolation and prevent side effects.
123 lines
2.9 KiB
Rust
123 lines
2.9 KiB
Rust
use crate::{
|
|
AppState, GachaRollItemDto, GachaRollRequestDto, GachaRollService,
|
|
MessageResponseDto, ResponseSuccessDto,
|
|
};
|
|
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(
|
|
(status = 200, description = "Get Gacha Roll by ID", body = ResponseSuccessDto<GachaRollItemDto>)
|
|
),
|
|
tag = "Gacha"
|
|
)]
|
|
pub async fn get_detail_gacha_roll(
|
|
headers: HeaderMap,
|
|
Extension(state): Extension<AppState>,
|
|
Path(id): Path<String>,
|
|
) -> impl IntoResponse {
|
|
match permissions_guard(
|
|
&headers,
|
|
state.clone(),
|
|
vec![PermissionsEnum::ReadDetailGachaRolls],
|
|
)
|
|
.await
|
|
{
|
|
Ok(_) => GachaRollService::get_gacha_roll_by_id(&state, id).await,
|
|
Err(response) => response,
|
|
}
|
|
}
|
|
|
|
#[utoipa::path(
|
|
post,
|
|
path = "/v1/gacha/rolls/create",
|
|
security(
|
|
("Bearer" = [])
|
|
),
|
|
request_body = GachaRollRequestDto,
|
|
responses(
|
|
(status = 201, description = "Create new gacha roll", body = MessageResponseDto)
|
|
),
|
|
tag = "Gacha"
|
|
)]
|
|
pub async fn post_create_gacha_roll(
|
|
headers: HeaderMap,
|
|
Extension(state): Extension<AppState>,
|
|
Json(payload): Json<GachaRollRequestDto>,
|
|
) -> impl IntoResponse {
|
|
match permissions_guard(
|
|
&headers,
|
|
state.clone(),
|
|
vec![PermissionsEnum::CreateGachaRolls],
|
|
)
|
|
.await
|
|
{
|
|
Ok(_) => GachaRollService::create_gacha_roll(&state, payload).await,
|
|
Err(response) => response,
|
|
}
|
|
}
|
|
|
|
#[utoipa::path(
|
|
post,
|
|
path = "/v1/gacha/rolls/execute",
|
|
security(
|
|
("Bearer" = [])
|
|
),
|
|
responses(
|
|
(status = 200, description = "Execute and get 1 gacha result", body = ResponseSuccessDto<GachaRollItemDto>)
|
|
),
|
|
tag = "Gacha"
|
|
)]
|
|
pub async fn post_execute_gacha_roll(
|
|
headers: HeaderMap,
|
|
Extension(state): Extension<AppState>,
|
|
) -> impl IntoResponse {
|
|
match permissions_guard(
|
|
&headers,
|
|
state.clone(),
|
|
vec![PermissionsEnum::ExecuteGachaRolls],
|
|
)
|
|
.await
|
|
{
|
|
Ok(_) => GachaRollService::execute_roll_once(headers, &state).await,
|
|
Err(response) => response,
|
|
}
|
|
}
|
|
|
|
#[utoipa::path(
|
|
delete,
|
|
path = "/v1/gacha/rolls/delete/{id}",
|
|
security(
|
|
("Bearer" = [])
|
|
),
|
|
params(("id" = String, Path, description = "Gacha Roll ID")),
|
|
responses(
|
|
(status = 200, description = "Delete Gacha Roll (soft delete)", body = MessageResponseDto)
|
|
),
|
|
tag = "Gacha"
|
|
)]
|
|
pub async fn delete_gacha_roll(
|
|
headers: HeaderMap,
|
|
Extension(state): Extension<AppState>,
|
|
Path(id): Path<String>,
|
|
) -> impl IntoResponse {
|
|
match permissions_guard(
|
|
&headers,
|
|
state.clone(),
|
|
vec![PermissionsEnum::DeleteGachaRolls],
|
|
)
|
|
.await
|
|
{
|
|
Ok(_) => GachaRollService::soft_delete_gacha_roll(&state, id).await,
|
|
Err(response) => response,
|
|
}
|
|
}
|