213 lines
4.7 KiB
Rust
213 lines
4.7 KiB
Rust
use libertas_core::models::{Album, AlbumPermission, FaceRegion, Media, MediaMetadata, Person, PersonPermission, Tag};
|
|
use serde::{Deserialize, Serialize};
|
|
use uuid::Uuid;
|
|
|
|
#[derive(Serialize)]
|
|
pub struct MediaResponse {
|
|
pub id: uuid::Uuid,
|
|
pub storage_path: String,
|
|
pub original_filename: String,
|
|
pub mime_type: String,
|
|
pub hash: String,
|
|
pub thumbnail_path: Option<String>,
|
|
}
|
|
|
|
impl From<Media> for MediaResponse {
|
|
fn from(media: Media) -> Self {
|
|
Self {
|
|
id: media.id,
|
|
storage_path: media.storage_path,
|
|
original_filename: media.original_filename,
|
|
mime_type: media.mime_type,
|
|
hash: media.hash,
|
|
thumbnail_path: media.thumbnail_path,
|
|
}
|
|
}
|
|
}
|
|
|
|
#[derive(Deserialize)]
|
|
pub struct ListMediaParams {
|
|
pub sort_by: Option<String>,
|
|
pub order: Option<String>,
|
|
pub mime_type: Option<String>,
|
|
#[serde(default)]
|
|
pub metadata: Vec<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,
|
|
}
|
|
|
|
#[derive(Serialize)]
|
|
pub struct MediaMetadataResponse {
|
|
pub source: String,
|
|
pub tag_name: String,
|
|
pub tag_value: String,
|
|
}
|
|
|
|
impl From<MediaMetadata> for MediaMetadataResponse {
|
|
fn from(metadata: MediaMetadata) -> Self {
|
|
Self {
|
|
source: metadata.source.as_str().to_string(),
|
|
tag_name: metadata.tag_name,
|
|
tag_value: metadata.tag_value,
|
|
}
|
|
}
|
|
}
|
|
|
|
#[derive(Serialize)]
|
|
pub struct MediaDetailsResponse {
|
|
pub id: uuid::Uuid,
|
|
pub storage_path: String,
|
|
pub original_filename: String,
|
|
pub mime_type: String,
|
|
pub hash: String,
|
|
pub thumbnail_path: Option<String>,
|
|
pub metadata: Vec<MediaMetadataResponse>,
|
|
}
|
|
|
|
#[derive(Serialize)]
|
|
pub struct TagResponse {
|
|
pub id: Uuid,
|
|
pub name: String,
|
|
}
|
|
|
|
impl From<Tag> for TagResponse {
|
|
fn from(tag: Tag) -> Self {
|
|
Self { id: tag.id, name: tag.name }
|
|
}
|
|
}
|
|
|
|
#[derive(Deserialize)]
|
|
pub struct MediaTagsRequest {
|
|
pub tags: Vec<String>,
|
|
}
|
|
|
|
#[derive(Serialize)]
|
|
pub struct PersonResponse {
|
|
pub id: Uuid,
|
|
pub owner_id: Uuid,
|
|
pub name: String,
|
|
}
|
|
|
|
impl From<Person> for PersonResponse {
|
|
fn from(person: Person) -> Self {
|
|
Self { id: person.id, owner_id: person.owner_id, name: person.name }
|
|
}
|
|
}
|
|
|
|
#[derive(Deserialize)]
|
|
pub struct CreatePersonRequest {
|
|
pub name: String,
|
|
}
|
|
|
|
#[derive(Deserialize)]
|
|
pub struct UpdatePersonRequest {
|
|
pub name: String,
|
|
}
|
|
|
|
#[derive(Serialize)]
|
|
pub struct FaceRegionResponse {
|
|
pub id: Uuid,
|
|
pub media_id: Uuid,
|
|
pub person_id: Option<Uuid>,
|
|
pub x_min: f32,
|
|
pub y_min: f32,
|
|
pub x_max: f32,
|
|
pub y_max: f32,
|
|
}
|
|
|
|
impl From<FaceRegion> for FaceRegionResponse {
|
|
fn from(face: FaceRegion) -> Self {
|
|
Self {
|
|
id: face.id,
|
|
media_id: face.media_id,
|
|
person_id: face.person_id,
|
|
x_min: face.x_min,
|
|
y_min: face.y_min,
|
|
x_max: face.x_max,
|
|
y_max: face.y_max,
|
|
}
|
|
}
|
|
}
|
|
|
|
#[derive(Deserialize)]
|
|
pub struct AssignFaceRequest {
|
|
pub person_id: Uuid,
|
|
}
|
|
|
|
#[derive(Deserialize)]
|
|
pub struct SharePersonRequest {
|
|
pub target_user_id: Uuid,
|
|
pub permission: PersonPermission,
|
|
} |