Some checks failed
Build and Push Docker Image / docker (push) Failing after 1m7s
Moved event fetching logic from CalendarView to Calendar component to properly use the visible date range instead of hardcoded current month. The Calendar component already tracks the current visible date through navigation, so events now load correctly for August and other months when navigating. Changes: - Calendar component now manages its own events state and fetching - Event fetching responds to current_date changes from navigation - CalendarView simplified to just render Calendar component - Fixed cargo fmt/clippy formatting across codebase 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
95 lines
2.7 KiB
Rust
95 lines
2.7 KiB
Rust
use axum::{extract::State, http::HeaderMap, response::Json};
|
|
use std::sync::Arc;
|
|
|
|
use crate::calendar::CalDAVClient;
|
|
use crate::{
|
|
models::{
|
|
ApiError, CreateCalendarRequest, CreateCalendarResponse, DeleteCalendarRequest,
|
|
DeleteCalendarResponse,
|
|
},
|
|
AppState,
|
|
};
|
|
|
|
use super::auth::{extract_bearer_token, extract_password_header};
|
|
|
|
pub async fn create_calendar(
|
|
State(state): State<Arc<AppState>>,
|
|
headers: HeaderMap,
|
|
Json(request): Json<CreateCalendarRequest>,
|
|
) -> Result<Json<CreateCalendarResponse>, ApiError> {
|
|
let token = extract_bearer_token(&headers)?;
|
|
let password = extract_password_header(&headers)?;
|
|
|
|
// Validate request
|
|
if request.name.trim().is_empty() {
|
|
return Err(ApiError::BadRequest(
|
|
"Calendar name is required".to_string(),
|
|
));
|
|
}
|
|
|
|
// Create CalDAV config from token and password
|
|
let config = state
|
|
.auth_service
|
|
.caldav_config_from_token(&token, &password)?;
|
|
let client = CalDAVClient::new(config);
|
|
|
|
// Create calendar on CalDAV server
|
|
match client
|
|
.create_calendar(
|
|
&request.name,
|
|
request.description.as_deref(),
|
|
request.color.as_deref(),
|
|
)
|
|
.await
|
|
{
|
|
Ok(_) => Ok(Json(CreateCalendarResponse {
|
|
success: true,
|
|
message: "Calendar created successfully".to_string(),
|
|
})),
|
|
Err(e) => {
|
|
eprintln!("Failed to create calendar: {}", e);
|
|
Err(ApiError::Internal(format!(
|
|
"Failed to create calendar: {}",
|
|
e
|
|
)))
|
|
}
|
|
}
|
|
}
|
|
|
|
pub async fn delete_calendar(
|
|
State(state): State<Arc<AppState>>,
|
|
headers: HeaderMap,
|
|
Json(request): Json<DeleteCalendarRequest>,
|
|
) -> Result<Json<DeleteCalendarResponse>, ApiError> {
|
|
let token = extract_bearer_token(&headers)?;
|
|
let password = extract_password_header(&headers)?;
|
|
|
|
// Validate request
|
|
if request.path.trim().is_empty() {
|
|
return Err(ApiError::BadRequest(
|
|
"Calendar path is required".to_string(),
|
|
));
|
|
}
|
|
|
|
// Create CalDAV config from token and password
|
|
let config = state
|
|
.auth_service
|
|
.caldav_config_from_token(&token, &password)?;
|
|
let client = CalDAVClient::new(config);
|
|
|
|
// Delete calendar on CalDAV server
|
|
match client.delete_calendar(&request.path).await {
|
|
Ok(_) => Ok(Json(DeleteCalendarResponse {
|
|
success: true,
|
|
message: "Calendar deleted successfully".to_string(),
|
|
})),
|
|
Err(e) => {
|
|
eprintln!("Failed to delete calendar: {}", e);
|
|
Err(ApiError::Internal(format!(
|
|
"Failed to delete calendar: {}",
|
|
e
|
|
)))
|
|
}
|
|
}
|
|
}
|