diff --git a/libertas_api/src/handlers/album_handlers.rs b/libertas_api/src/handlers/album_handlers.rs index 4155c83..6612b49 100644 --- a/libertas_api/src/handlers/album_handlers.rs +++ b/libertas_api/src/handlers/album_handlers.rs @@ -4,21 +4,10 @@ use axum::{ http::StatusCode, routing::{get, post}, }; -use libertas_core::{ - models::{Album, AlbumPermission}, - schema::{AddMediaToAlbumData, CreateAlbumData, ShareAlbumData, UpdateAlbumData}, -}; -use serde::{Deserialize, Serialize}; +use libertas_core::schema::{AddMediaToAlbumData, CreateAlbumData, ShareAlbumData, UpdateAlbumData}; use uuid::Uuid; -use crate::{error::ApiError, middleware::auth::UserId, state::AppState}; - -#[derive(Deserialize)] -pub struct CreateAlbumRequest { - name: String, - description: Option, - is_public: Option, -} +use crate::{error::ApiError, middleware::auth::UserId, schema::{AddMediaToAlbumRequest, AlbumResponse, CreateAlbumRequest, ShareAlbumRequest, UpdateAlbumRequest}, state::AppState}; async fn create_album( State(state): State, @@ -37,11 +26,6 @@ async fn create_album( Ok(StatusCode::CREATED) } -#[derive(Deserialize)] -pub struct AddMediaToAlbumRequest { - media_ids: Vec, -} - async fn add_media_to_album( State(state): State, UserId(user_id): UserId, @@ -61,12 +45,6 @@ async fn add_media_to_album( Ok(StatusCode::OK) } -#[derive(Deserialize)] -pub struct ShareAlbumRequest { - target_user_id: Uuid, - permission: AlbumPermission, -} - async fn share_album( State(state): State, UserId(owner_id): UserId, @@ -84,38 +62,6 @@ async fn share_album( Ok(StatusCode::OK) } -#[derive(Serialize)] -pub struct AlbumResponse { - id: Uuid, - owner_id: Uuid, - name: String, - description: Option, - is_public: bool, - created_at: chrono::DateTime, - updated_at: chrono::DateTime, -} - -impl From for AlbumResponse { - fn from(album: Album) -> Self { - Self { - id: album.id, - owner_id: album.owner_id, - name: album.name, - description: album.description, - is_public: album.is_public, - created_at: album.created_at, - updated_at: album.updated_at, - } - } -} - -#[derive(Deserialize)] -pub struct UpdateAlbumRequest { - name: Option, - description: Option>, - is_public: Option, -} - async fn list_user_albums( State(state): State, UserId(user_id): UserId, diff --git a/libertas_api/src/handlers/auth_handlers.rs b/libertas_api/src/handlers/auth_handlers.rs index 8d811a5..ef27cc4 100644 --- a/libertas_api/src/handlers/auth_handlers.rs +++ b/libertas_api/src/handlers/auth_handlers.rs @@ -1,15 +1,8 @@ use axum::{Json, extract::State, http::StatusCode}; -use libertas_core::schema::{CreateUserData, LoginUserData, UserResponse}; -use serde::{Deserialize, Serialize}; +use libertas_core::schema::{CreateUserData, LoginUserData}; -use crate::{error::ApiError, state::AppState}; +use crate::{error::ApiError, schema::{LoginRequest, LoginResponse, RegisterRequest, UserResponse}, state::AppState}; -#[derive(Deserialize)] -pub struct RegisterRequest { - pub username: String, - pub email: String, - pub password: String, -} pub async fn register( State(state): State, @@ -32,17 +25,6 @@ pub async fn register( Ok((StatusCode::CREATED, Json(response))) } -#[derive(Deserialize)] -pub struct LoginRequest { - pub username_or_email: String, - pub password: String, -} - -#[derive(Serialize)] -pub struct LoginResponse { - token: String, -} - pub async fn login( State(state): State, Json(payload): Json, diff --git a/libertas_api/src/handlers/user_handlers.rs b/libertas_api/src/handlers/user_handlers.rs index ac132b0..e8c1fb9 100644 --- a/libertas_api/src/handlers/user_handlers.rs +++ b/libertas_api/src/handlers/user_handlers.rs @@ -1,7 +1,6 @@ use axum::{Json, Router, extract::State}; -use libertas_core::schema::UserResponse; -use crate::{error::ApiError, middleware::auth::UserId, state::AppState}; +use crate::{error::ApiError, middleware::auth::UserId, schema::UserResponse, state::AppState}; pub async fn get_me( State(state): State, diff --git a/libertas_api/src/schema.rs b/libertas_api/src/schema.rs index b00167f..0323cc5 100644 --- a/libertas_api/src/schema.rs +++ b/libertas_api/src/schema.rs @@ -1,4 +1,6 @@ +use libertas_core::models::{Album, AlbumPermission}; use serde::{Deserialize, Serialize}; +use uuid::Uuid; #[derive(Serialize)] pub struct MediaResponse { @@ -15,4 +17,79 @@ pub struct ListMediaParams { pub order: Option, // You can add future filters here, e.g.: // pub mime_type: Option, +} + +#[derive(Deserialize)] +pub struct CreateAlbumRequest { + pub name: String, + pub description: Option, + pub is_public: Option, +} + +#[derive(Deserialize)] +pub struct AddMediaToAlbumRequest { + pub media_ids: Vec, +} + +#[derive(Deserialize)] +pub struct ShareAlbumRequest { + pub target_user_id: Uuid, + pub permission: AlbumPermission, +} + +#[derive(Serialize)] +pub struct AlbumResponse { + pub id: Uuid, + pub owner_id: Uuid, + pub name: String, + pub description: Option, + pub is_public: bool, + pub created_at: chrono::DateTime, + pub updated_at: chrono::DateTime, +} + +impl From for AlbumResponse { + fn from(album: Album) -> Self { + Self { + id: album.id, + owner_id: album.owner_id, + name: album.name, + description: album.description, + is_public: album.is_public, + created_at: album.created_at, + updated_at: album.updated_at, + } + } +} + +#[derive(Deserialize)] +pub struct UpdateAlbumRequest { + pub name: Option, + pub description: Option>, + pub is_public: Option, +} + +#[derive(Deserialize)] +pub struct RegisterRequest { + pub username: String, + pub email: String, + pub password: String, +} + +#[derive(Deserialize)] +pub struct LoginRequest { + pub username_or_email: String, + pub password: String, +} + +#[derive(Serialize)] +pub struct LoginResponse { + pub token: String, +} + +#[derive(Serialize)] +pub struct UserResponse { + pub id: Uuid, + pub username: String, + pub email: String, } \ No newline at end of file diff --git a/libertas_core/src/schema.rs b/libertas_core/src/schema.rs index fd613ce..82901da 100644 --- a/libertas_core/src/schema.rs +++ b/libertas_core/src/schema.rs @@ -1,6 +1,3 @@ -use serde::Serialize; -use uuid::Uuid; - use crate::models::AlbumPermission; pub struct UploadMediaData<'a> { @@ -46,13 +43,6 @@ pub struct ShareAlbumData { pub permission: AlbumPermission, } -#[derive(Serialize)] -pub struct UserResponse { - pub id: Uuid, - pub username: String, - pub email: String, -} - #[derive(Debug, Clone)] pub enum SortOrder { Asc, diff --git a/libertas_infra/src/query_builder.rs b/libertas_infra/src/query_builder.rs index b9ca840..5203f8d 100644 --- a/libertas_infra/src/query_builder.rs +++ b/libertas_infra/src/query_builder.rs @@ -38,7 +38,7 @@ impl QueryBuilder for MediaQueryBuilder { mut query: SqlxQueryBuilder<'a, sqlx::Postgres>, options: &'a ListMediaOptions, ) -> CoreResult> { - if let Some(filter) = &options.filter { + if let Some(_filter) = &options.filter { // In the future, you would add logic here: // if let Some(mime) = &filter.mime_type { // query.push(" AND mime_type = ");