feat: Implement person and tag management services

- Added `Person` and `Tag` models to the core library.
- Created `PersonService` and `TagService` traits with implementations for managing persons and tags.
- Introduced repositories for `Person`, `Tag`, `FaceRegion`, and `PersonShare` with PostgreSQL support.
- Updated authorization logic to include permissions for accessing and editing persons.
- Enhanced the schema to support new models and relationships.
- Implemented database migrations for new tables related to persons and tags.
- Added request and response structures for API interactions with persons and tags.
This commit is contained in:
2025-11-15 11:18:11 +01:00
parent 370d55f0b3
commit 4675285603
26 changed files with 1465 additions and 18 deletions

View File

@@ -1,6 +1,6 @@
use libertas_core::models::{Album, AlbumPermission, AlbumShare, Media, MediaMetadata, MediaMetadataSource, Role, User};
use libertas_core::models::{Album, AlbumPermission, AlbumShare, FaceRegion, Media, MediaMetadata, MediaMetadataSource, Person, PersonPermission, Role, Tag, User};
use crate::db_models::{PostgresAlbum, PostgresAlbumPermission, PostgresAlbumShare, PostgresMedia, PostgresMediaMetadata, PostgresMediaMetadataSource, PostgresRole, PostgresUser};
use crate::db_models::{PostgresAlbum, PostgresAlbumPermission, PostgresAlbumShare, PostgresFaceRegion, PostgresMedia, PostgresMediaMetadata, PostgresMediaMetadataSource, PostgresPerson, PostgresPersonPermission, PostgresPersonShared, PostgresRole, PostgresTag, PostgresUser};
impl From<PostgresRole> for Role {
fn from(pg_role: PostgresRole) -> Self {
@@ -121,4 +121,69 @@ impl From<PostgresAlbumShare> for AlbumShare {
permission: AlbumPermission::from(pg_share.permission),
}
}
}
impl From<PostgresTag> for Tag {
fn from(pg_tag: PostgresTag) -> Self {
Tag {
id: pg_tag.id,
name: pg_tag.name,
}
}
}
impl From<PostgresPerson> for Person {
fn from(pg_person: PostgresPerson) -> Self {
Person {
id: pg_person.id,
owner_id: pg_person.owner_id,
name: pg_person.name,
thumbnail_media_id: None, // Not in the DB schema
}
}
}
impl From<PostgresFaceRegion> for FaceRegion {
fn from(pg_face: PostgresFaceRegion) -> Self {
FaceRegion {
id: pg_face.id,
media_id: pg_face.media_id,
person_id: pg_face.person_id,
x_min: pg_face.x_min,
y_min: pg_face.y_min,
x_max: pg_face.x_max,
y_max: pg_face.y_max,
}
}
}
impl From<PostgresPersonPermission> for PersonPermission {
fn from(pg_perm: PostgresPersonPermission) -> Self {
match pg_perm {
PostgresPersonPermission::View => PersonPermission::View,
PostgresPersonPermission::CanUse => PersonPermission::CanUse,
}
}
}
impl From<PersonPermission> for PostgresPersonPermission {
fn from(perm: PersonPermission) -> Self {
match perm {
PersonPermission::View => PostgresPersonPermission::View,
PersonPermission::CanUse => PostgresPersonPermission::CanUse,
}
}
}
impl From<PostgresPersonShared> for (Person, PersonPermission) {
fn from(pg_shared: PostgresPersonShared) -> Self {
let person = Person {
id: pg_shared.id,
owner_id: pg_shared.owner_id,
name: pg_shared.name,
thumbnail_media_id: None,
};
let permission = PersonPermission::from(pg_shared.permission);
(person, permission)
}
}