fix: landing

This commit is contained in:
Maulana Sodiqin
2025-05-26 23:09:01 +07:00
parent a3c2715a85
commit f1e4e02697
9 changed files with 83 additions and 63 deletions
+1
View File
@@ -4,6 +4,7 @@ RUN apt-get update && apt-get install -y \
curl \ curl \
build-essential \ build-essential \
libssl-dev \ libssl-dev \
libssl1.1 \
pkg-config \ pkg-config \
&& rm -rf /var/lib/apt/lists/* && rm -rf /var/lib/apt/lists/*
+1 -15
View File
@@ -1,16 +1,2 @@
pub mod v1; pub mod v1;
pub use v1::*;
pub fn add(left: u64, right: u64) -> u64 {
left + right
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn it_works() {
let result = add(2, 2);
assert_eq!(result, 4);
}
}
@@ -1,18 +1,21 @@
use super::{ use super::{
events_dto::{EventsCreateRequestDto, EventsDetailItemDto, EventsListItemDto, EventsUpdateRequestDto}, events_dto::{
events_service::EventsService, EventsCreateRequestDto, EventsDetailItemDto, EventsListItemDto,
EventsUpdateRequestDto,
},
events_service::EventsService,
}; };
use imphnen_libs::{AppState, MetaRequestDto, ResponseListSuccessDto, ResponseSuccessDto, MessageResponseDto};
use axum::extract::{Path, Query}; use axum::extract::{Path, Query};
use axum::response::IntoResponse; use axum::response::IntoResponse;
use axum::{Extension, Json}; use axum::{Extension, Json};
use imphnen_libs::{
AppState, MessageResponseDto, MetaRequestDto, ResponseListSuccessDto,
ResponseSuccessDto,
};
#[utoipa::path( #[utoipa::path(
get, get,
security( path = "/v1/cms/landing/events",
("Bearer" = [])
),
path = "/v1/events",
params( params(
("page" = Option<i64>, Query, description = "Page number"), ("page" = Option<i64>, Query, description = "Page number"),
("per_page" = Option<i64>, Query, description = "Items per page"), ("per_page" = Option<i64>, Query, description = "Items per page"),
@@ -28,18 +31,15 @@ use axum::{Extension, Json};
tag = "Events" tag = "Events"
)] )]
pub async fn get_event_list( pub async fn get_event_list(
Extension(state): Extension<AppState>, Extension(state): Extension<AppState>,
Query(meta): Query<MetaRequestDto>, Query(meta): Query<MetaRequestDto>,
) -> impl IntoResponse { ) -> impl IntoResponse {
EventsService::get_event_list(&state, meta).await EventsService::get_event_list(&state, meta).await
} }
#[utoipa::path( #[utoipa::path(
get, get,
security( path = "/v1/cms/landing/events/detail/{id}",
("Bearer" = [])
),
path = "/v1/events/detail/{id}",
params( params(
("id" = String, Path, description = "Event ID") ("id" = String, Path, description = "Event ID")
), ),
@@ -49,10 +49,10 @@ pub async fn get_event_list(
tag = "Events" tag = "Events"
)] )]
pub async fn get_event_by_id( pub async fn get_event_by_id(
Extension(state): Extension<AppState>, Extension(state): Extension<AppState>,
Path(id): Path<String>, Path(id): Path<String>,
) -> impl IntoResponse { ) -> impl IntoResponse {
EventsService::get_event_by_id(&state, id).await EventsService::get_event_by_id(&state, id).await
} }
#[utoipa::path( #[utoipa::path(
@@ -60,7 +60,7 @@ pub async fn get_event_by_id(
security( security(
("Bearer" = []) ("Bearer" = [])
), ),
path = "/v1/events/create", path = "/v1/cms/landing/events/create",
request_body = EventsCreateRequestDto, request_body = EventsCreateRequestDto,
responses( responses(
(status = 201, description = "Create new event", body = MessageResponseDto) (status = 201, description = "Create new event", body = MessageResponseDto)
@@ -68,10 +68,10 @@ pub async fn get_event_by_id(
tag = "Events" tag = "Events"
)] )]
pub async fn post_create_event( pub async fn post_create_event(
Extension(state): Extension<AppState>, Extension(state): Extension<AppState>,
Json(payload): Json<EventsCreateRequestDto>, Json(payload): Json<EventsCreateRequestDto>,
) -> impl IntoResponse { ) -> impl IntoResponse {
EventsService::create_event(&state, payload).await EventsService::create_event(&state, payload).await
} }
#[utoipa::path( #[utoipa::path(
@@ -79,7 +79,7 @@ pub async fn post_create_event(
security( security(
("Bearer" = []) ("Bearer" = [])
), ),
path = "/v1/events/update/{id}", path = "/v1/cms/landing/events/update/{id}",
params( params(
("id" = String, Path, description = "Event ID") ("id" = String, Path, description = "Event ID")
), ),
@@ -90,11 +90,11 @@ pub async fn post_create_event(
tag = "Events" tag = "Events"
)] )]
pub async fn patch_update_event( pub async fn patch_update_event(
Extension(state): Extension<AppState>, Extension(state): Extension<AppState>,
Path(id): Path<String>, Path(id): Path<String>,
Json(payload): Json<EventsUpdateRequestDto>, Json(payload): Json<EventsUpdateRequestDto>,
) -> impl IntoResponse { ) -> impl IntoResponse {
EventsService::update_event(&state, id, payload).await EventsService::update_event(&state, id, payload).await
} }
#[utoipa::path( #[utoipa::path(
@@ -102,7 +102,7 @@ pub async fn patch_update_event(
security( security(
("Bearer" = []) ("Bearer" = [])
), ),
path = "/v1/events/delete/{id}", path = "/v1/cms/landing/events/delete/{id}",
params( params(
("id" = String, Path, description = "Event ID") ("id" = String, Path, description = "Event ID")
), ),
@@ -112,8 +112,8 @@ pub async fn patch_update_event(
tag = "Events" tag = "Events"
)] )]
pub async fn delete_event( pub async fn delete_event(
Extension(state): Extension<AppState>, Extension(state): Extension<AppState>,
Path(id): Path<String>, Path(id): Path<String>,
) -> impl IntoResponse { ) -> impl IntoResponse {
EventsService::delete_event(&state, id).await EventsService::delete_event(&state, id).await
} }
@@ -1,9 +1,8 @@
use super::{events_dto::EventsQueryDto, events_schema::EventsSchema};
use anyhow::{Result, bail}; use anyhow::{Result, bail};
use imphnen_libs::{AppState, MetaRequestDto, ResourceEnum, ResponseListSuccessDto}; use imphnen_libs::{AppState, MetaRequestDto, ResourceEnum, ResponseListSuccessDto};
use imphnen_utils::{DetailQueryBuilder, ListQueryBuilder, get_id, get_iso_date}; use imphnen_utils::{DetailQueryBuilder, ListQueryBuilder, get_id, get_iso_date};
use super::{events_dto::EventsQueryDto, events_schema::EventsSchema};
pub struct EventsRepository<'a> { pub struct EventsRepository<'a> {
state: &'a AppState, state: &'a AppState,
} }
@@ -13,7 +12,6 @@ impl<'a> EventsRepository<'a> {
Self { state } Self { state }
} }
// Get list of events with pagination and sorting by newest
pub async fn query_event_list( pub async fn query_event_list(
&self, &self,
meta: MetaRequestDto, meta: MetaRequestDto,
+35 -8
View File
@@ -1,17 +1,44 @@
use axum::{
Router,
routing::{delete, get, patch, post},
};
pub mod events_controller;
pub mod events_dto; pub mod events_dto;
pub mod events_repository;
pub mod events_schema; pub mod events_schema;
pub mod events_repository;
pub mod events_service; pub mod events_service;
pub mod events_controller;
use axum::{routing::{delete, get, patch, post}, Router};
pub use events_controller::*; pub use events_controller::*;
pub use events_dto::*;
pub use events_repository::*;
pub use events_schema::*;
pub use events_service::*;
pub fn events_public_routes() -> Router { pub fn events_public_routes() -> Router {
Router::new() Router::new()
.route("/events", get(events_controller::get_event_list)) .route(
.route("/events/detail/{id}", get(events_controller::get_event_by_id)) "/cms/landing/events",
.route("/events/create", post(events_controller::post_create_event)) get(events_controller::get_event_list),
.route("/events/update/{id}", patch(events_controller::patch_update_event)) )
.route("/events/delete/{id}", delete(events_controller::delete_event)) .route(
"/cms/landing/events/detail/{id}",
get(events_controller::get_event_by_id),
)
}
pub fn events_protected_routes() -> Router {
Router::new()
.route(
"/cms/landing/events/create",
post(events_controller::post_create_event),
)
.route(
"/cms/landing/events/update/{id}",
patch(events_controller::patch_update_event),
)
.route(
"/cms/landing/events/delete/{id}",
delete(events_controller::delete_event),
)
} }
+2
View File
@@ -1 +1,3 @@
pub mod events; pub mod events;
pub use events::*;
+2
View File
@@ -1 +1,3 @@
pub mod landing; pub mod landing;
pub use landing::*;
+1 -1
View File
@@ -6,7 +6,7 @@ use utoipa::{
Modify, OpenApi, Modify, OpenApi,
}; };
use imphnen_gacha::{gacha_claims, gacha_items, gacha_rolls, GachaClaimItemDto, GachaClaimRequestDto, GachaItemDto, GachaItemRequestDto, GachaRollItemDto, GachaRollRequestDto}; use imphnen_gacha::{gacha_claims, gacha_items, gacha_rolls, GachaClaimItemDto, GachaClaimRequestDto, GachaItemDto, GachaItemRequestDto, GachaRollItemDto, GachaRollRequestDto};
use imphnen_cms::v1::landing::events::{events_controller, events_dto::{EventsDetailItemDto, EventsListItemDto}}; use imphnen_cms::{events_controller, events_dto::{EventsDetailItemDto, EventsListItemDto}};
#[derive(OpenApi)] #[derive(OpenApi)]
+8 -4
View File
@@ -1,7 +1,7 @@
use axum::{ use axum::{
Extension, Router, middleware::from_fn, response::Redirect, routing::get, Extension, Router, middleware::from_fn, response::Redirect, routing::get,
}; };
use imphnen_cms::v1::landing::events::events_public_routes; use imphnen_cms::{events_protected_routes, events_public_routes};
use imphnen_entities::{AppState, SurrealMemClient, SurrealWsClient}; use imphnen_entities::{AppState, SurrealMemClient, SurrealWsClient};
use imphnen_gacha::gacha_router; use imphnen_gacha::gacha_router;
use imphnen_iam::{iam_protected_routes, iam_public_routes}; use imphnen_iam::{iam_protected_routes, iam_public_routes};
@@ -20,17 +20,21 @@ pub async fn gateway_service(
surrealdb_mem, surrealdb_mem,
}; };
let public_routes = iam_public_routes(); let public_routes = Router::new()
let events_public_routes = events_public_routes(); .merge(iam_public_routes())
.merge(events_public_routes());
let protected_routes = Router::new() let protected_routes = Router::new()
.merge(iam_protected_routes()) .merge(iam_protected_routes())
.merge(events_protected_routes())
.merge(gacha_router()) .merge(gacha_router())
.layer(from_fn(auth_middleware)); .layer(from_fn(auth_middleware));
let routes = public_routes.merge(protected_routes);
Router::new() Router::new()
.route("/", get(Redirect::to("/docs"))) .route("/", get(Redirect::to("/docs")))
.nest("/v1", public_routes.merge(protected_routes).merge(events_public_routes)) .nest("/v1", routes)
.merge(SwaggerUi::new("/docs").url("/openapi.json", docs_router())) .merge(SwaggerUi::new("/docs").url("/openapi.json", docs_router()))
.layer(cors_middleware()) .layer(cors_middleware())
.layer(Extension(state)) .layer(Extension(state))