- Added hooks for listing, creating, updating, deleting, sharing, and merging people. - Introduced a new route for person details and media. - Implemented clustering faces functionality. - Created services for person-related API interactions. feat: Introduce tag management functionality - Added hooks for listing, adding, and removing tags from media. - Created services for tag-related API interactions. feat: Enhance user authentication handling - Added a hook to fetch current user details. - Updated auth storage to manage user state more effectively. feat: Update album management features - Enhanced album service to return created album details. - Updated API handlers to return album responses upon creation. - Modified album repository to return created album. feat: Implement media management improvements - Added media details fetching and processing of media URLs. - Enhanced media upload functionality to return processed media. feat: Introduce face management features - Added services for listing faces for media and assigning faces to persons. fix: Update API client to clear authentication state on 401 errors.
51 lines
1.4 KiB
Rust
51 lines
1.4 KiB
Rust
use axum::{Json, extract::State, http::StatusCode};
|
|
use libertas_core::schema::{CreateUserData, LoginUserData};
|
|
|
|
use crate::{
|
|
error::ApiError,
|
|
schema::{LoginRequest, LoginResponse, RegisterRequest, UserResponse},
|
|
state::AppState,
|
|
};
|
|
|
|
pub async fn register(
|
|
State(state): State<AppState>,
|
|
Json(payload): Json<RegisterRequest>,
|
|
) -> Result<(StatusCode, Json<UserResponse>), ApiError> {
|
|
let user_data = CreateUserData {
|
|
username: &payload.username,
|
|
email: &payload.email,
|
|
password: &payload.password,
|
|
};
|
|
|
|
let user = state.user_service.register(user_data).await?;
|
|
|
|
let response = UserResponse {
|
|
id: user.id,
|
|
username: user.username,
|
|
email: user.email,
|
|
storage_used: user.storage_used,
|
|
storage_quota: user.storage_quota,
|
|
};
|
|
|
|
Ok((StatusCode::CREATED, Json(response)))
|
|
}
|
|
|
|
pub async fn login(
|
|
State(state): State<AppState>,
|
|
Json(payload): Json<LoginRequest>,
|
|
) -> Result<Json<LoginResponse>, ApiError> {
|
|
let login_data = LoginUserData {
|
|
username_or_email: &payload.username_or_email,
|
|
password: &payload.password,
|
|
};
|
|
|
|
let token = state.user_service.login(login_data).await?;
|
|
Ok(Json(LoginResponse { token }))
|
|
}
|
|
|
|
pub fn auth_routes() -> axum::Router<AppState> {
|
|
axum::Router::new()
|
|
.route("/register", axum::routing::post(register))
|
|
.route("/login", axum::routing::post(login))
|
|
}
|