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,
|
http::StatusCode,
|
||||||
routing::{get, post},
|
routing::{get, post},
|
||||||
};
|
};
|
||||||
use libertas_core::{
|
use libertas_core::schema::{AddMediaToAlbumData, CreateAlbumData, ShareAlbumData, UpdateAlbumData};
|
||||||
models::{Album, AlbumPermission},
|
|
||||||
schema::{AddMediaToAlbumData, CreateAlbumData, ShareAlbumData, UpdateAlbumData},
|
|
||||||
};
|
|
||||||
use serde::{Deserialize, Serialize};
|
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
|
||||||
use crate::{error::ApiError, middleware::auth::UserId, state::AppState};
|
use crate::{error::ApiError, middleware::auth::UserId, schema::{AddMediaToAlbumRequest, AlbumResponse, CreateAlbumRequest, ShareAlbumRequest, UpdateAlbumRequest}, state::AppState};
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
|
||||||
pub struct CreateAlbumRequest {
|
|
||||||
name: String,
|
|
||||||
description: Option<String>,
|
|
||||||
is_public: Option<bool>,
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn create_album(
|
async fn create_album(
|
||||||
State(state): State<AppState>,
|
State(state): State<AppState>,
|
||||||
@@ -37,11 +26,6 @@ async fn create_album(
|
|||||||
Ok(StatusCode::CREATED)
|
Ok(StatusCode::CREATED)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
|
||||||
pub struct AddMediaToAlbumRequest {
|
|
||||||
media_ids: Vec<Uuid>,
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn add_media_to_album(
|
async fn add_media_to_album(
|
||||||
State(state): State<AppState>,
|
State(state): State<AppState>,
|
||||||
UserId(user_id): UserId,
|
UserId(user_id): UserId,
|
||||||
@@ -61,12 +45,6 @@ async fn add_media_to_album(
|
|||||||
Ok(StatusCode::OK)
|
Ok(StatusCode::OK)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
|
||||||
pub struct ShareAlbumRequest {
|
|
||||||
target_user_id: Uuid,
|
|
||||||
permission: AlbumPermission,
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn share_album(
|
async fn share_album(
|
||||||
State(state): State<AppState>,
|
State(state): State<AppState>,
|
||||||
UserId(owner_id): UserId,
|
UserId(owner_id): UserId,
|
||||||
@@ -84,38 +62,6 @@ async fn share_album(
|
|||||||
Ok(StatusCode::OK)
|
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(
|
async fn list_user_albums(
|
||||||
State(state): State<AppState>,
|
State(state): State<AppState>,
|
||||||
UserId(user_id): UserId,
|
UserId(user_id): UserId,
|
||||||
|
|||||||
@@ -1,15 +1,8 @@
|
|||||||
use axum::{Json, extract::State, http::StatusCode};
|
use axum::{Json, extract::State, http::StatusCode};
|
||||||
use libertas_core::schema::{CreateUserData, LoginUserData, UserResponse};
|
use libertas_core::schema::{CreateUserData, LoginUserData};
|
||||||
use serde::{Deserialize, Serialize};
|
|
||||||
|
|
||||||
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(
|
pub async fn register(
|
||||||
State(state): State<AppState>,
|
State(state): State<AppState>,
|
||||||
@@ -32,17 +25,6 @@ pub async fn register(
|
|||||||
Ok((StatusCode::CREATED, Json(response)))
|
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(
|
pub async fn login(
|
||||||
State(state): State<AppState>,
|
State(state): State<AppState>,
|
||||||
Json(payload): Json<LoginRequest>,
|
Json(payload): Json<LoginRequest>,
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
use axum::{Json, Router, extract::State};
|
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(
|
pub async fn get_me(
|
||||||
State(state): State<AppState>,
|
State(state): State<AppState>,
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
|
use libertas_core::models::{Album, AlbumPermission};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
use uuid::Uuid;
|
||||||
|
|
||||||
#[derive(Serialize)]
|
#[derive(Serialize)]
|
||||||
pub struct MediaResponse {
|
pub struct MediaResponse {
|
||||||
@@ -15,4 +17,79 @@ pub struct ListMediaParams {
|
|||||||
pub order: Option<String>,
|
pub order: Option<String>,
|
||||||
// You can add future filters here, e.g.:
|
// You can add future filters here, e.g.:
|
||||||
// pub mime_type: Option<String>,
|
// 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;
|
use crate::models::AlbumPermission;
|
||||||
|
|
||||||
pub struct UploadMediaData<'a> {
|
pub struct UploadMediaData<'a> {
|
||||||
@@ -46,13 +43,6 @@ pub struct ShareAlbumData {
|
|||||||
pub permission: AlbumPermission,
|
pub permission: AlbumPermission,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize)]
|
|
||||||
pub struct UserResponse {
|
|
||||||
pub id: Uuid,
|
|
||||||
pub username: String,
|
|
||||||
pub email: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub enum SortOrder {
|
pub enum SortOrder {
|
||||||
Asc,
|
Asc,
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ impl QueryBuilder<ListMediaOptions> for MediaQueryBuilder {
|
|||||||
mut query: SqlxQueryBuilder<'a, sqlx::Postgres>,
|
mut query: SqlxQueryBuilder<'a, sqlx::Postgres>,
|
||||||
options: &'a ListMediaOptions,
|
options: &'a ListMediaOptions,
|
||||||
) -> CoreResult<SqlxQueryBuilder<'a, sqlx::Postgres>> {
|
) -> 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:
|
// In the future, you would add logic here:
|
||||||
// if let Some(mime) = &filter.mime_type {
|
// if let Some(mime) = &filter.mime_type {
|
||||||
// query.push(" AND mime_type = ");
|
// query.push(" AND mime_type = ");
|
||||||
|
|||||||
Reference in New Issue
Block a user