summaryrefslogtreecommitdiff
path: root/app/models
diff options
context:
space:
mode:
authorl3wdfut4pwr <l3wdfut4pwr@gmail.com>2026-03-17 14:11:45 +0200
committerl3wdfut4pwr <l3wdfut4pwr@gmail.com>2026-03-17 14:11:45 +0200
commit47fd81a5910eab3483f79d03eedf9307bc81252f (patch)
tree3e1ebd1bddcea649eb968e65161555afd4c2898c /app/models
parentf01cb6703710b7df4c7c022047cd35e1d5e9c70e (diff)
simple registration prototype
Diffstat (limited to 'app/models')
-rw-r--r--app/models/auth.py0
-rw-r--r--app/models/collections.py40
-rw-r--r--app/models/image.py70
-rw-r--r--app/models/integrations.py19
-rw-r--r--app/models/profile.py21
-rw-r--r--app/models/upload.py0
-rw-r--r--app/models/user.py23
7 files changed, 173 insertions, 0 deletions
diff --git a/app/models/auth.py b/app/models/auth.py
deleted file mode 100644
index e69de29..0000000
--- a/app/models/auth.py
+++ /dev/null
diff --git a/app/models/collections.py b/app/models/collections.py
new file mode 100644
index 0000000..7dc5bb7
--- /dev/null
+++ b/app/models/collections.py
@@ -0,0 +1,40 @@
+from __future__ import annotations
+
+from datetime import datetime
+from typing import TYPE_CHECKING
+
+from sqlalchemy import Boolean, DateTime, ForeignKey, Integer, String, Table
+from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column, relationship
+
+Base = DeclarativeBase()
+
+if TYPE_CHECKING:
+ from .image import Image
+
+collection_images = Table(
+ "collection_images",
+ Base.metadata,
+ mapped_column(
+ "collection_id", Integer, ForeignKey("collections.id"), primary_key=True
+ ),
+ mapped_column("image_id", Integer, ForeignKey("images.id"), primary_key=True),
+)
+
+
+class Collection(Base):
+ __tablename__ = "collections"
+
+ id: Mapped[int] = mapped_column(Integer, primary_key=True)
+ user_id: Mapped[int] = mapped_column(ForeignKey("users.id"), nullable=False)
+ name: Mapped[str] = mapped_column(String(100), nullable=False)
+ description: Mapped[str | None] = mapped_column(String(500), nullable=True)
+ is_private: Mapped[bool] = mapped_column(Boolean, default=False, nullable=False)
+ created_at: Mapped[datetime] = mapped_column(
+ DateTime(timezone=True), default=datetime.utcnow
+ )
+
+ images: Mapped[list["Image"]] = relationship(
+ "Image",
+ secondary=collection_images,
+ back_populates="collections",
+ )
diff --git a/app/models/image.py b/app/models/image.py
new file mode 100644
index 0000000..e139123
--- /dev/null
+++ b/app/models/image.py
@@ -0,0 +1,70 @@
+from __future__ import annotations
+
+from datetime import datetime
+
+from sqlalchemy import (
+ Boolean,
+ Column,
+ DateTime,
+ ForeignKey,
+ Integer,
+ String,
+ Table,
+ func,
+)
+from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column, relationship
+
+from .collections import Collection
+
+Base = DeclarativeBase()
+
+image_tags = Table(
+ "image_tags",
+ Base.metadata,
+ Column("image_id", Integer, ForeignKey("images.id"), primary_key=True),
+ Column("tag_id", Integer, ForeignKey("tags.id"), primary_key=True),
+)
+
+
+class Tag(Base):
+ __tablename__ = "tags"
+
+ id: Mapped[int] = mapped_column(Integer, primary_key=True)
+ name: Mapped[str] = mapped_column(String(50), unique=True, nullable=False)
+ category: Mapped[str | None] = mapped_column(String(50), nullable=True)
+
+ images: Mapped[list["Image"]] = relationship(
+ "Image",
+ secondary=image_tags,
+ back_populates="tags",
+ )
+
+
+class Image(Base):
+ __tablename__ = "images"
+
+ id: Mapped[int] = mapped_column(Integer, primary_key=True)
+ image_file: Mapped[str] = mapped_column(String(255), nullable=False)
+ original_file: Mapped[str] = mapped_column(String(255), nullable=False)
+ user_id: Mapped[int] = mapped_column(ForeignKey("users.id"), nullable=False)
+ publication_date: Mapped[datetime] = mapped_column(
+ DateTime(timezone=True), server_default=func.now()
+ )
+ source: Mapped[str] = mapped_column(String(255), nullable=False)
+ views: Mapped[int] = mapped_column(Integer, default=0, nullable=False)
+ likes: Mapped[int] = mapped_column(Integer, default=0, nullable=False)
+ is_verified: Mapped[bool] = mapped_column(Boolean, default=False, nullable=False)
+ is_rejected: Mapped[bool] = mapped_column(Boolean, default=False, nullable=False)
+
+ tags: Mapped[list[Tag]] = relationship(
+ "Tag",
+ secondary=image_tags,
+ back_populates="images",
+ )
+
+
+collections: Mapped[list["Collection"]] = relationship(
+ "Collection",
+ secondary="collection_images",
+ back_populates="images",
+)
diff --git a/app/models/integrations.py b/app/models/integrations.py
new file mode 100644
index 0000000..4a1ddb9
--- /dev/null
+++ b/app/models/integrations.py
@@ -0,0 +1,19 @@
+from sqlalchemy import ForeignKey, Integer, String
+from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column
+
+Base = DeclarativeBase()
+
+
+class UserIntegration(Base):
+ __tablename__ = "user_integrations"
+
+ id: Mapped[int] = mapped_column(Integer, primary_key=True)
+ user_id: Mapped[int] = mapped_column(ForeignKey("users.id"), nullable=False)
+
+ facebook: Mapped[str | None] = mapped_column(String(255), nullable=True)
+ pinterest: Mapped[str | None] = mapped_column(String(255), nullable=True)
+ discord: Mapped[str | None] = mapped_column(String(255), nullable=True)
+ artstation: Mapped[str | None] = mapped_column(String(255), nullable=True)
+ x: Mapped[str | None] = mapped_column(String(255), nullable=True) # Twitter/X
+ behance: Mapped[str | None] = mapped_column(String(255), nullable=True)
+ instagram: Mapped[str | None] = mapped_column(String(255), nullable=True)
diff --git a/app/models/profile.py b/app/models/profile.py
new file mode 100644
index 0000000..b19d796
--- /dev/null
+++ b/app/models/profile.py
@@ -0,0 +1,21 @@
+from sqlalchemy import ForeignKey, Integer, String
+from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column
+
+Base = DeclarativeBase()
+
+
+class Profile(Base):
+ __tablename__ = "profiles"
+
+ id: Mapped[int] = mapped_column(Integer, primary_key=True)
+ user_id: Mapped[int] = mapped_column(ForeignKey("users.id"), unique=True)
+
+ avatar_file: Mapped[str | None] = mapped_column(String(255), nullable=True)
+ banner_file: Mapped[str | None] = mapped_column(String(255), nullable=True)
+ description: Mapped[str | None] = mapped_column(String(500), nullable=True)
+
+ publications_count: Mapped[int] = mapped_column(Integer, default=0, nullable=False)
+ collections_count: Mapped[int] = mapped_column(Integer, default=0, nullable=False)
+ subscriptions_count: Mapped[int] = mapped_column(Integer, default=0, nullable=False)
+ followers_count: Mapped[int] = mapped_column(Integer, default=0, nullable=False)
+ following_count: Mapped[int] = mapped_column(Integer, default=0, nullable=False)
diff --git a/app/models/upload.py b/app/models/upload.py
deleted file mode 100644
index e69de29..0000000
--- a/app/models/upload.py
+++ /dev/null
diff --git a/app/models/user.py b/app/models/user.py
new file mode 100644
index 0000000..de9fa98
--- /dev/null
+++ b/app/models/user.py
@@ -0,0 +1,23 @@
+from sqlalchemy import Boolean, Integer, String
+from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column
+
+
+class Base(DeclarativeBase):
+ pass
+
+
+class User(Base):
+ __tablename__ = "users"
+
+ id: Mapped[int] = mapped_column(Integer, primary_key=True)
+ username: Mapped[str] = mapped_column(String(20), unique=True, nullable=False)
+ password: Mapped[str | None] = mapped_column(String(255), nullable=True)
+ email: Mapped[str | None] = mapped_column(String(120), unique=True, nullable=True)
+ google_id: Mapped[str | None] = mapped_column(
+ String(255), unique=True, nullable=True
+ )
+ avatar_file: Mapped[str | None] = mapped_column(String(255), nullable=True)
+ banner_file: Mapped[str | None] = mapped_column(String(255), nullable=True)
+ premium: Mapped[bool] = mapped_column(Boolean, default=False, nullable=False)
+ is_banned: Mapped[bool] = mapped_column(Boolean, default=False, nullable=False)
+ is_moderator: Mapped[bool] = mapped_column(Boolean, default=False, nullable=False)