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,4 +1,3 @@
-- Create the 'albums' table
CREATE TABLE albums (
id UUID PRIMARY KEY,
owner_id UUID NOT NULL REFERENCES users (id),
@@ -9,15 +8,12 @@ CREATE TABLE albums (
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
);
-- Create the 'album_media' join table
-- This links media items to albums
CREATE TABLE album_media (
album_id UUID NOT NULL REFERENCES albums (id) ON DELETE CASCADE,
media_id UUID NOT NULL REFERENCES media (id) ON DELETE CASCADE,
PRIMARY KEY (album_id, media_id) -- Ensures no duplicates
PRIMARY KEY (album_id, media_id)
);
-- Indexes for faster lookups
CREATE INDEX idx_albums_owner_id ON albums (owner_id);
CREATE INDEX idx_album_media_media_id ON album_media (media_id);

View File

@@ -0,0 +1,12 @@
CREATE TABLE tags (
id UUID PRIMARY KEY,
name TEXT NOT NULL UNIQUE
);
CREATE TABLE media_tags (
media_id UUID NOT NULL REFERENCES media (id) ON DELETE CASCADE,
tag_id UUID NOT NULL REFERENCES tags (id) ON DELETE CASCADE,
PRIMARY KEY (media_id, tag_id)
);
CREATE INDEX idx_media_tags_tag_id ON media_tags (tag_id);

View File

@@ -0,0 +1,21 @@
CREATE TABLE people (
id UUID PRIMARY KEY,
owner_id UUID NOT NULL REFERENCES users (id) ON DELETE CASCADE,
name TEXT NOT NULL
);
CREATE TABLE face_regions (
id UUID PRIMARY KEY,
media_id UUID NOT NULL REFERENCES media (id) ON DELETE CASCADE,
person_id UUID REFERENCES people (id) ON DELETE SET NULL,
x_min REAL NOT NULL,
y_min REAL NOT NULL,
x_max REAL NOT NULL,
y_max REAL NOT NULL
);
CREATE INDEX idx_people_owner_id ON people (owner_id);
CREATE INDEX idx_face_regions_media_id ON face_regions (media_id);
CREATE INDEX idx_face_regions_person_id ON face_regions (person_id);

View File

@@ -0,0 +1,13 @@
CREATE TYPE person_permission AS ENUM (
'view',
'can_use'
);
CREATE TABLE person_shares (
person_id UUID NOT NULL REFERENCES people (id) ON DELETE CASCADE,
user_id UUID NOT NULL REFERENCES users (id) ON DELETE CASCADE,
permission person_permission NOT NULL,
PRIMARY KEY (person_id, user_id)
);
CREATE INDEX idx_person_shares_user_id ON person_shares (user_id);