refactor: clean up album and auth handlers by removing unused structs and imports
This commit is contained in:
@@ -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<String>,
|
||||
is_public: Option<bool>,
|
||||
}
|
||||
use crate::{error::ApiError, middleware::auth::UserId, schema::{AddMediaToAlbumRequest, AlbumResponse, CreateAlbumRequest, ShareAlbumRequest, UpdateAlbumRequest}, state::AppState};
|
||||
|
||||
async fn create_album(
|
||||
State(state): State<AppState>,
|
||||
@@ -37,11 +26,6 @@ async fn create_album(
|
||||
Ok(StatusCode::CREATED)
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct AddMediaToAlbumRequest {
|
||||
media_ids: Vec<Uuid>,
|
||||
}
|
||||
|
||||
async fn add_media_to_album(
|
||||
State(state): State<AppState>,
|
||||
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<AppState>,
|
||||
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<String>,
|
||||
is_public: bool,
|
||||
created_at: chrono::DateTime<chrono::Utc>,
|
||||
updated_at: chrono::DateTime<chrono::Utc>,
|
||||
}
|
||||
|
||||
impl From<Album> 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<String>,
|
||||
description: Option<Option<String>>,
|
||||
is_public: Option<bool>,
|
||||
}
|
||||
|
||||
async fn list_user_albums(
|
||||
State(state): State<AppState>,
|
||||
UserId(user_id): UserId,
|
||||
|
||||
@@ -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<AppState>,
|
||||
@@ -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<AppState>,
|
||||
Json(payload): Json<LoginRequest>,
|
||||
|
||||
@@ -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<AppState>,
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
use libertas_core::models::{Album, AlbumPermission};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use uuid::Uuid;
|
||||
|
||||
#[derive(Serialize)]
|
||||
pub struct MediaResponse {
|
||||
@@ -16,3 +18,78 @@ pub struct ListMediaParams {
|
||||
// You can add future filters here, e.g.:
|
||||
// pub mime_type: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct CreateAlbumRequest {
|
||||
pub name: String,
|
||||
pub description: Option<String>,
|
||||
pub is_public: Option<bool>,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct AddMediaToAlbumRequest {
|
||||
pub media_ids: Vec<Uuid>,
|
||||
}
|
||||
|
||||
#[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<String>,
|
||||
pub is_public: bool,
|
||||
pub created_at: chrono::DateTime<chrono::Utc>,
|
||||
pub updated_at: chrono::DateTime<chrono::Utc>,
|
||||
}
|
||||
|
||||
impl From<Album> 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<String>,
|
||||
pub description: Option<Option<String>>,
|
||||
pub is_public: Option<bool>,
|
||||
}
|
||||
|
||||
#[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,
|
||||
}
|
||||
@@ -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,
|
||||
|
||||
@@ -38,7 +38,7 @@ impl QueryBuilder<ListMediaOptions> for MediaQueryBuilder {
|
||||
mut query: SqlxQueryBuilder<'a, sqlx::Postgres>,
|
||||
options: &'a ListMediaOptions,
|
||||
) -> CoreResult<SqlxQueryBuilder<'a, sqlx::Postgres>> {
|
||||
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 = ");
|
||||
|
||||
Reference in New Issue
Block a user