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
|
||||
}
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
pub mod create_album;
|
||||
pub mod manage_album_entries;
|
||||
pub mod tag_asset;
|
||||
pub mod update_album;
|
||||
|
||||
pub use create_album::{CreateAlbumCommand, CreateAlbumHandler};
|
||||
pub use manage_album_entries::{AlbumAction, ManageAlbumEntriesCommand, ManageAlbumEntriesHandler};
|
||||
pub use tag_asset::{TagAssetCommand, TagAssetHandler};
|
||||
pub use update_album::{UpdateAlbumCommand, UpdateAlbumHandler};
|
||||
|
||||
44
crates/application/src/organization/commands/update_album.rs
Normal file
44
crates/application/src/organization/commands/update_album.rs
Normal file
@@ -0,0 +1,44 @@
|
||||
use domain::{errors::DomainError, ports::AlbumRepository, value_objects::SystemId};
|
||||
use std::sync::Arc;
|
||||
|
||||
pub struct UpdateAlbumCommand {
|
||||
pub album_id: SystemId,
|
||||
pub user_id: SystemId,
|
||||
pub title: Option<String>,
|
||||
pub description: Option<String>,
|
||||
}
|
||||
|
||||
pub struct UpdateAlbumHandler {
|
||||
album_repo: Arc<dyn AlbumRepository>,
|
||||
}
|
||||
|
||||
impl UpdateAlbumHandler {
|
||||
pub fn new(album_repo: Arc<dyn AlbumRepository>) -> Self {
|
||||
Self { album_repo }
|
||||
}
|
||||
|
||||
pub async fn execute(
|
||||
&self,
|
||||
cmd: UpdateAlbumCommand,
|
||||
) -> Result<domain::entities::Album, DomainError> {
|
||||
let mut album = self
|
||||
.album_repo
|
||||
.find_by_id(&cmd.album_id)
|
||||
.await?
|
||||
.ok_or_else(|| DomainError::NotFound("Album not found".into()))?;
|
||||
|
||||
if album.creator_user_id != cmd.user_id {
|
||||
return Err(DomainError::Forbidden("Not your album".into()));
|
||||
}
|
||||
|
||||
if let Some(title) = cmd.title {
|
||||
album.title = title;
|
||||
}
|
||||
if let Some(desc) = cmd.description {
|
||||
album.description = desc;
|
||||
}
|
||||
|
||||
self.album_repo.save(&album).await?;
|
||||
Ok(album)
|
||||
}
|
||||
}
|
||||
@@ -4,4 +4,6 @@ pub mod queries;
|
||||
pub use commands::{AlbumAction, ManageAlbumEntriesCommand, ManageAlbumEntriesHandler};
|
||||
pub use commands::{CreateAlbumCommand, CreateAlbumHandler};
|
||||
pub use commands::{TagAssetCommand, TagAssetHandler};
|
||||
pub use commands::{UpdateAlbumCommand, UpdateAlbumHandler};
|
||||
pub use queries::get_album::{GetAlbumHandler, GetAlbumQuery};
|
||||
pub use queries::list_albums::{ListAlbumsHandler, ListAlbumsQuery};
|
||||
|
||||
22
crates/application/src/organization/queries/list_albums.rs
Normal file
22
crates/application/src/organization/queries/list_albums.rs
Normal file
@@ -0,0 +1,22 @@
|
||||
use domain::{
|
||||
entities::Album, errors::DomainError, ports::AlbumRepository, value_objects::SystemId,
|
||||
};
|
||||
use std::sync::Arc;
|
||||
|
||||
pub struct ListAlbumsQuery {
|
||||
pub user_id: SystemId,
|
||||
}
|
||||
|
||||
pub struct ListAlbumsHandler {
|
||||
album_repo: Arc<dyn AlbumRepository>,
|
||||
}
|
||||
|
||||
impl ListAlbumsHandler {
|
||||
pub fn new(album_repo: Arc<dyn AlbumRepository>) -> Self {
|
||||
Self { album_repo }
|
||||
}
|
||||
|
||||
pub async fn execute(&self, query: ListAlbumsQuery) -> Result<Vec<Album>, DomainError> {
|
||||
self.album_repo.find_by_creator(&query.user_id).await
|
||||
}
|
||||
}
|
||||
@@ -1 +1,2 @@
|
||||
pub mod get_album;
|
||||
pub mod list_albums;
|
||||
|
||||
@@ -145,6 +145,16 @@ impl AssetRepository for InMemoryAssetRepository {
|
||||
.collect())
|
||||
}
|
||||
|
||||
async fn count_by_owner(&self, owner_id: &SystemId) -> Result<u64, DomainError> {
|
||||
Ok(self
|
||||
.data
|
||||
.lock()
|
||||
.await
|
||||
.values()
|
||||
.filter(|a| &a.owner_user_id == owner_id)
|
||||
.count() as u64)
|
||||
}
|
||||
|
||||
async fn search(
|
||||
&self,
|
||||
owner_id: &SystemId,
|
||||
@@ -155,6 +165,14 @@ impl AssetRepository for InMemoryAssetRepository {
|
||||
self.find_by_owner(owner_id, limit, offset).await
|
||||
}
|
||||
|
||||
async fn count_search(
|
||||
&self,
|
||||
owner_id: &SystemId,
|
||||
_filters: &AssetFilters,
|
||||
) -> Result<u64, DomainError> {
|
||||
self.count_by_owner(owner_id).await
|
||||
}
|
||||
|
||||
async fn save(&self, asset: &Asset) -> Result<(), DomainError> {
|
||||
self.data
|
||||
.lock()
|
||||
|
||||
Reference in New Issue
Block a user