feat: Implement pagination for user media retrieval and update related structures
This commit is contained in:
@@ -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<()>;
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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>;
|
||||
|
||||
Reference in New Issue
Block a user