feat: frontend-ready backend — pagination, auto-derivatives, list endpoints, bulk ops, OpenAPI
Pagination: count_by_owner + count_search on AssetRepository,
timeline/search return real total count (not page len).
Auto-derivatives: worker enqueues GenerateDerivative when
ExtractMetadata job completes, closing the upload→thumbnail gap.
List endpoints: GET /albums, GET /stacks with user scoping.
ListAlbumsHandler, ListStacksHandler, find_by_owner on AssetStackRepository.
Tag filtering: tag_name field on AssetFilters, JOIN asset_tags+tags
in postgres search/count queries.
Bulk operations: POST /assets/bulk-delete, POST /assets/bulk-tag.
Album update: PUT /albums/{id} with UpdateAlbumHandler (title, description).
OpenAPI: utoipa annotations on all 47 endpoints + all request/response
schemas registered. Scalar UI at /scalar covers full API.
This commit is contained in:
@@ -14,10 +14,11 @@ pub use commands::resolve_duplicate::{
|
||||
pub use commands::update_metadata::{UpdateMetadataCommand, UpdateMetadataHandler};
|
||||
pub use queries::get_asset::{GetAssetHandler, GetAssetQuery};
|
||||
pub use queries::get_stack::{GetStackHandler, GetStackQuery};
|
||||
pub use queries::get_timeline::{GetTimelineHandler, GetTimelineQuery};
|
||||
pub use queries::get_timeline::{GetTimelineHandler, GetTimelineQuery, TimelineResult};
|
||||
pub use queries::list_stacks::{ListStacksHandler, ListStacksQuery};
|
||||
pub use queries::read_asset_file::{AssetFileResult, ReadAssetFileHandler, ReadAssetFileQuery};
|
||||
pub use queries::read_derivative::{
|
||||
DerivativeFileResult, ReadDerivativeHandler, ReadDerivativeQuery,
|
||||
};
|
||||
pub use queries::search_assets::{SearchAssetsHandler, SearchAssetsQuery};
|
||||
pub use queries::search_assets::{SearchAssetsHandler, SearchAssetsQuery, SearchResult};
|
||||
pub use visibility::VisibilityFilteredAssetRepository;
|
||||
|
||||
@@ -16,6 +16,11 @@ pub struct GetTimelineQuery {
|
||||
pub offset: u32,
|
||||
}
|
||||
|
||||
pub struct TimelineResult {
|
||||
pub items: Vec<(Asset, StructuredData)>,
|
||||
pub total: u64,
|
||||
}
|
||||
|
||||
pub struct GetTimelineHandler {
|
||||
asset_repo: Arc<dyn AssetRepository>,
|
||||
metadata_repo: Arc<dyn AssetMetadataRepository>,
|
||||
@@ -51,13 +56,11 @@ impl GetTimelineHandler {
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn execute(
|
||||
&self,
|
||||
query: GetTimelineQuery,
|
||||
) -> Result<Vec<(Asset, StructuredData)>, DomainError> {
|
||||
pub async fn execute(&self, query: GetTimelineQuery) -> Result<TimelineResult, DomainError> {
|
||||
let caller_id = query.caller_id.unwrap_or(query.owner_id);
|
||||
let repo = self.effective_repo(caller_id);
|
||||
|
||||
let total = repo.count_by_owner(&query.owner_id).await?;
|
||||
let assets = repo
|
||||
.find_by_owner(&query.owner_id, query.limit, query.offset)
|
||||
.await?;
|
||||
@@ -65,7 +68,7 @@ impl GetTimelineHandler {
|
||||
let asset_ids: Vec<SystemId> = assets.iter().map(|a| a.asset_id).collect();
|
||||
let all_layers = self.metadata_repo.find_by_assets(&asset_ids).await?;
|
||||
|
||||
let results = assets
|
||||
let items = assets
|
||||
.into_iter()
|
||||
.map(|asset| {
|
||||
let layers: Vec<_> = all_layers
|
||||
@@ -78,6 +81,6 @@ impl GetTimelineHandler {
|
||||
})
|
||||
.collect();
|
||||
|
||||
Ok(results)
|
||||
Ok(TimelineResult { items, total })
|
||||
}
|
||||
}
|
||||
|
||||
22
crates/application/src/catalog/queries/list_stacks.rs
Normal file
22
crates/application/src/catalog/queries/list_stacks.rs
Normal file
@@ -0,0 +1,22 @@
|
||||
use domain::{
|
||||
entities::AssetStack, errors::DomainError, ports::AssetStackRepository, value_objects::SystemId,
|
||||
};
|
||||
use std::sync::Arc;
|
||||
|
||||
pub struct ListStacksQuery {
|
||||
pub owner_id: SystemId,
|
||||
}
|
||||
|
||||
pub struct ListStacksHandler {
|
||||
stack_repo: Arc<dyn AssetStackRepository>,
|
||||
}
|
||||
|
||||
impl ListStacksHandler {
|
||||
pub fn new(stack_repo: Arc<dyn AssetStackRepository>) -> Self {
|
||||
Self { stack_repo }
|
||||
}
|
||||
|
||||
pub async fn execute(&self, query: ListStacksQuery) -> Result<Vec<AssetStack>, DomainError> {
|
||||
self.stack_repo.find_by_owner(&query.owner_id).await
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
pub mod get_asset;
|
||||
pub mod get_stack;
|
||||
pub mod get_timeline;
|
||||
pub mod list_stacks;
|
||||
pub mod read_asset_file;
|
||||
pub mod read_derivative;
|
||||
pub mod search_assets;
|
||||
|
||||
@@ -14,6 +14,11 @@ pub struct SearchAssetsQuery {
|
||||
pub offset: u32,
|
||||
}
|
||||
|
||||
pub struct SearchResult {
|
||||
pub items: Vec<Asset>,
|
||||
pub total: u64,
|
||||
}
|
||||
|
||||
pub struct SearchAssetsHandler {
|
||||
asset_repo: Arc<dyn AssetRepository>,
|
||||
}
|
||||
@@ -23,9 +28,15 @@ impl SearchAssetsHandler {
|
||||
Self { asset_repo }
|
||||
}
|
||||
|
||||
pub async fn execute(&self, query: SearchAssetsQuery) -> Result<Vec<Asset>, DomainError> {
|
||||
self.asset_repo
|
||||
pub async fn execute(&self, query: SearchAssetsQuery) -> Result<SearchResult, DomainError> {
|
||||
let total = self
|
||||
.asset_repo
|
||||
.count_search(&query.owner_id, &query.filters)
|
||||
.await?;
|
||||
let items = self
|
||||
.asset_repo
|
||||
.search(&query.owner_id, &query.filters, query.limit, query.offset)
|
||||
.await
|
||||
.await?;
|
||||
Ok(SearchResult { items, total })
|
||||
}
|
||||
}
|
||||
|
||||
@@ -122,6 +122,18 @@ impl AssetRepository for VisibilityFilteredAssetRepository {
|
||||
self.filter_visible(assets).await
|
||||
}
|
||||
|
||||
async fn count_by_owner(&self, owner_id: &SystemId) -> Result<u64, DomainError> {
|
||||
self.inner.count_by_owner(owner_id).await
|
||||
}
|
||||
|
||||
async fn count_search(
|
||||
&self,
|
||||
owner_id: &SystemId,
|
||||
filters: &AssetFilters,
|
||||
) -> Result<u64, DomainError> {
|
||||
self.inner.count_search(owner_id, filters).await
|
||||
}
|
||||
|
||||
async fn save(&self, asset: &Asset) -> Result<(), DomainError> {
|
||||
self.inner.save(asset).await
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user