Files
imphnen-backend-service/imphnen-cms/src/v1/landing/events/events_controller.rs
T

133 lines
4.0 KiB
Rust
Raw Normal View History

2025-05-26 14:11:17 +07:00
use super::{
2025-05-26 23:09:01 +07:00
events_dto::{
EventsCreateRequestDto, EventsDetailItemDto, EventsListItemDto,
EventsUpdateRequestDto,
},
events_service::EventsService,
2025-05-26 14:11:17 +07:00
};
use axum::extract::{Path, Query};
use axum::response::IntoResponse;
use axum::{Extension, Json, http::HeaderMap};
2025-05-26 23:09:01 +07:00
use imphnen_libs::{
AppState, MessageResponseDto, MetaRequestDto, ResponseListSuccessDto,
ResponseSuccessDto,
2025-05-26 23:09:01 +07:00
};
use imphnen_iam::{PermissionsEnum, permissions_guard};
2025-05-26 14:11:17 +07:00
#[utoipa::path(
get,
2025-05-26 23:09:01 +07:00
path = "/v1/cms/landing/events",
2025-05-26 14:11:17 +07:00
params(
("page" = Option<i64>, Query, description = "Page number"),
("per_page" = Option<i64>, Query, description = "Items per page"),
("search" = Option<String>, Query, description = "Search keyword"),
("sort_by" = Option<String>, Query, description = "Sort by field"),
("order" = Option<String>, Query, description = "Order ASC or DESC"),
("filter" = Option<String>, Query, description = "Filter value"),
("filter_by" = Option<String>, Query, description = "Field to filter by"),
),
responses(
(status = 200, description = "Get event list", body = ResponseListSuccessDto<Vec<EventsListItemDto>>)
),
tag = "Events"
)]
pub async fn get_event_list(
2025-05-26 23:09:01 +07:00
Extension(state): Extension<AppState>,
Query(meta): Query<MetaRequestDto>,
2025-05-26 14:11:17 +07:00
) -> impl IntoResponse {
2025-05-26 23:09:01 +07:00
EventsService::get_event_list(&state, meta).await
2025-05-26 14:11:17 +07:00
}
#[utoipa::path(
get,
2025-05-26 23:09:01 +07:00
path = "/v1/cms/landing/events/detail/{id}",
2025-05-26 14:11:17 +07:00
params(
("id" = String, Path, description = "Event ID")
),
responses(
(status = 200, description = "Get event by ID", body = ResponseSuccessDto<EventsDetailItemDto>)
),
tag = "Events"
)]
pub async fn get_event_by_id(
2025-05-26 23:09:01 +07:00
Extension(state): Extension<AppState>,
Path(id): Path<String>,
2025-05-26 14:11:17 +07:00
) -> impl IntoResponse {
2025-05-26 23:09:01 +07:00
EventsService::get_event_by_id(&state, id).await
2025-05-26 14:11:17 +07:00
}
#[utoipa::path(
post,
security(
("Bearer" = [])
),
2025-05-26 23:09:01 +07:00
path = "/v1/cms/landing/events/create",
2025-05-26 14:11:17 +07:00
request_body = EventsCreateRequestDto,
responses(
(status = 201, description = "Create new event", body = MessageResponseDto)
),
tag = "Events"
)]
pub async fn post_create_event(
headers: HeaderMap,
Extension(state): Extension<AppState>,
Json(payload): Json<EventsCreateRequestDto>,
2025-05-26 14:11:17 +07:00
) -> impl IntoResponse {
match permissions_guard(headers, Extension(state), vec![PermissionsEnum::Administrator]).await {
Ok((_claims, state)) => EventsService::create_event(&state, payload).await,
Err(response) => response,
}
2025-05-26 14:11:17 +07:00
}
#[utoipa::path(
patch,
security(
("Bearer" = [])
),
2025-05-26 23:09:01 +07:00
path = "/v1/cms/landing/events/update/{id}",
2025-05-26 14:11:17 +07:00
params(
("id" = String, Path, description = "Event ID")
),
request_body = EventsUpdateRequestDto,
responses(
(status = 200, description = "Update event", body = MessageResponseDto)
),
tag = "Events"
)]
pub async fn patch_update_event(
headers: HeaderMap,
Extension(state): Extension<AppState>,
Path(id): Path<String>,
Json(payload): Json<EventsUpdateRequestDto>,
2025-05-26 14:11:17 +07:00
) -> impl IntoResponse {
match permissions_guard(headers, Extension(state), vec![PermissionsEnum::Administrator]).await {
Ok((_claims, state)) => EventsService::update_event(&state, id, payload).await,
Err(response) => response,
}
2025-05-26 14:11:17 +07:00
}
#[utoipa::path(
delete,
security(
("Bearer" = [])
),
2025-05-26 23:09:01 +07:00
path = "/v1/cms/landing/events/delete/{id}",
2025-05-26 14:11:17 +07:00
params(
("id" = String, Path, description = "Event ID")
),
responses(
(status = 200, description = "Soft delete event", body = MessageResponseDto)
),
tag = "Events"
)]
pub async fn delete_event(
headers: HeaderMap,
Extension(state): Extension<AppState>,
Path(id): Path<String>,
2025-05-26 14:11:17 +07:00
) -> impl IntoResponse {
match permissions_guard(headers, Extension(state), vec![PermissionsEnum::Administrator]).await {
Ok((_claims, state)) => EventsService::delete_event(&state, id).await,
Err(response) => response,
}
2025-05-26 14:11:17 +07:00
}