feat: Implement pagination for user media retrieval and update related structures

This commit is contained in:
2025-11-15 18:06:09 +01:00
parent dd10211c63
commit ccb9f09d4a
8 changed files with 144 additions and 47 deletions

View File

@@ -19,7 +19,7 @@ pub trait MediaRepository: Send + Sync {
&self,
user_id: Uuid,
options: &ListMediaOptions,
) -> CoreResult<Vec<Media>>;
) -> CoreResult<(Vec<Media>, i64)>;
async fn update_thumbnail_path(&self, id: Uuid, thumbnail_path: String) -> CoreResult<()>;
async fn delete(&self, id: Uuid) -> CoreResult<()>;
}

View File

@@ -87,3 +87,37 @@ pub struct MediaImportBundle {
pub metadata_models: Vec<MediaMetadata>,
pub file_size: i64,
}
#[derive(Debug, Clone)]
pub struct PaginatedResponse<T> {
pub data: Vec<T>,
pub page: u32,
pub limit: u32,
pub total_items: i64,
pub total_pages: u32,
pub has_next_page: bool,
pub has_prev_page: bool,
}
impl<T> PaginatedResponse<T> {
pub fn new(data: Vec<T>, page: u32, limit: u32, total_items: i64) -> Self {
let total_pages = if limit == 0 {
0
} else {
(total_items as f64 / limit as f64).ceil() as u32
};
let has_next_page = page < total_pages;
let has_prev_page = page > 1;
Self {
data,
page,
limit,
total_items,
total_pages,
has_next_page,
has_prev_page,
}
}
}

View File

@@ -10,7 +10,7 @@ use crate::{
},
schema::{
AddMediaToAlbumData, CreateAlbumData, CreateUserData, ListMediaOptions, LoginUserData,
ShareAlbumData, UpdateAlbumData, UploadMediaData,
PaginatedResponse, ShareAlbumData, UpdateAlbumData, UploadMediaData,
},
};
@@ -22,7 +22,7 @@ pub trait MediaService: Send + Sync {
&self,
user_id: Uuid,
options: ListMediaOptions,
) -> CoreResult<Vec<Media>>;
) -> CoreResult<PaginatedResponse<Media>>;
async fn get_media_filepath(&self, id: Uuid, user_id: Option<Uuid>) -> CoreResult<String>;
async fn get_media_thumbnail_path(&self, id: Uuid, user_id: Option<Uuid>)
-> CoreResult<String>;