Phase 1.5: Migrate main events handler to service layer only
- Remove all direct db:: calls from events.rs handler - Add missing get_pending_by_id method to EventService - Use specific error types (ApiError::event_not_found) - Clean handler → service → database pattern - First step in eliminating maintenance nightmare of multiple DB patterns
This commit is contained in:
parent
e0fffbc4b9
commit
e2ab29505a
|
@ -24,7 +24,7 @@ use crate::{
|
|||
services::EventService,
|
||||
error::Result,
|
||||
models::{Event, PendingEvent, ApiResponse, PaginatedResponse},
|
||||
AppState, db,
|
||||
AppState,
|
||||
};
|
||||
|
||||
// Use shared ListQueryParams instead of custom EventQuery
|
||||
|
@ -210,8 +210,8 @@ pub async fn approve(
|
|||
State(state): State<AppState>,
|
||||
Json(req): Json<ApproveRejectRequest>,
|
||||
) -> Result<Json<ApiResponse<Event>>> {
|
||||
let pending_event = db::events::get_pending_by_id(&state.pool, &id).await?
|
||||
.ok_or_else(|| ApiError::NotFound("Pending event not found".to_string()))?;
|
||||
let pending_event = EventService::get_pending_by_id(&state.pool, &id).await?
|
||||
.ok_or_else(|| ApiError::event_not_found(&id))?;
|
||||
|
||||
let event = EventService::approve_pending_event(&state.pool, &id).await?;
|
||||
|
||||
|
@ -231,8 +231,8 @@ pub async fn reject(
|
|||
State(state): State<AppState>,
|
||||
Json(req): Json<ApproveRejectRequest>,
|
||||
) -> Result<Json<ApiResponse<String>>> {
|
||||
let pending_event = db::events::get_pending_by_id(&state.pool, &id).await?
|
||||
.ok_or_else(|| ApiError::NotFound("Pending event not found".to_string()))?;
|
||||
let pending_event = EventService::get_pending_by_id(&state.pool, &id).await?
|
||||
.ok_or_else(|| ApiError::event_not_found(&id))?;
|
||||
|
||||
EventService::reject_pending_event(&state.pool, &id, req.admin_notes.clone()).await?;
|
||||
|
||||
|
|
|
@ -127,4 +127,10 @@ impl EventService {
|
|||
// Future: Add business logic like authorization checks, cleanup, etc.
|
||||
db::events::delete_pending(pool, id).await
|
||||
}
|
||||
|
||||
/// Get pending event by ID
|
||||
pub async fn get_pending_by_id(pool: &PgPool, id: &Uuid) -> Result<Option<PendingEvent>> {
|
||||
// Future: Add business logic like authorization checks, etc.
|
||||
db::events::get_pending_by_id(pool, id).await
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue