
- Eliminate manual ApiResponse construction in 5 handlers - Add MemberService + sql::members following established pattern - Create success_message_only() utility for empty responses - Fix members handler: db::members direct calls → service layer - Add SanitizeOutput for LoginResponse trait consistency - All examined handlers now follow Handler → Service → SQL pattern
29 lines
729 B
Rust
29 lines
729 B
Rust
use axum::Json;
|
|
use crate::models::ApiResponse;
|
|
use crate::utils::sanitize::SanitizeOutput;
|
|
|
|
pub fn success_response<T: SanitizeOutput>(data: T) -> Json<ApiResponse<T>> {
|
|
Json(ApiResponse {
|
|
success: true,
|
|
data: Some(data.sanitize_output()),
|
|
message: None,
|
|
})
|
|
}
|
|
|
|
pub fn success_with_message<T: SanitizeOutput>(data: T, message: &str) -> Json<ApiResponse<T>> {
|
|
Json(ApiResponse {
|
|
success: true,
|
|
data: Some(data.sanitize_output()),
|
|
message: Some(message.to_string()),
|
|
})
|
|
}
|
|
|
|
pub fn success_message_only(message: &str) -> Json<ApiResponse<()>> {
|
|
Json(ApiResponse {
|
|
success: true,
|
|
data: Some(()),
|
|
message: Some(message.to_string()),
|
|
})
|
|
}
|
|
|