initial commit - LeDiscord plateforme des copains
This commit is contained in:
30
backend/models/__init__.py
Normal file
30
backend/models/__init__.py
Normal file
@@ -0,0 +1,30 @@
|
||||
from .user import User
|
||||
from .event import Event, EventParticipation
|
||||
from .album import Album, Media, MediaLike
|
||||
from .post import Post, PostMention
|
||||
from .vlog import Vlog, VlogLike, VlogComment
|
||||
from .notification import Notification
|
||||
from .settings import SystemSettings
|
||||
from .information import Information
|
||||
from .ticket import Ticket, TicketType, TicketStatus, TicketPriority
|
||||
|
||||
__all__ = [
|
||||
"User",
|
||||
"Event",
|
||||
"EventParticipation",
|
||||
"Album",
|
||||
"Media",
|
||||
"MediaLike",
|
||||
"Post",
|
||||
"PostMention",
|
||||
"Vlog",
|
||||
"VlogLike",
|
||||
"VlogComment",
|
||||
"Notification",
|
||||
"SystemSettings",
|
||||
"Information",
|
||||
"Ticket",
|
||||
"TicketType",
|
||||
"TicketStatus",
|
||||
"TicketPriority"
|
||||
]
|
||||
58
backend/models/album.py
Normal file
58
backend/models/album.py
Normal file
@@ -0,0 +1,58 @@
|
||||
from sqlalchemy import Column, Integer, String, DateTime, ForeignKey, Text, Enum as SQLEnum
|
||||
from sqlalchemy.orm import relationship
|
||||
from datetime import datetime
|
||||
import enum
|
||||
from config.database import Base
|
||||
|
||||
class MediaType(enum.Enum):
|
||||
IMAGE = "image"
|
||||
VIDEO = "video"
|
||||
|
||||
class Album(Base):
|
||||
__tablename__ = "albums"
|
||||
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
title = Column(String, nullable=False)
|
||||
description = Column(Text)
|
||||
creator_id = Column(Integer, ForeignKey("users.id"), nullable=False)
|
||||
event_id = Column(Integer, ForeignKey("events.id"), nullable=True)
|
||||
cover_image = Column(String)
|
||||
created_at = Column(DateTime, default=datetime.utcnow)
|
||||
updated_at = Column(DateTime, default=datetime.utcnow, onupdate=datetime.utcnow)
|
||||
|
||||
# Relationships
|
||||
creator = relationship("User", back_populates="albums")
|
||||
event = relationship("Event", back_populates="albums")
|
||||
media = relationship("Media", back_populates="album", cascade="all, delete-orphan")
|
||||
|
||||
class Media(Base):
|
||||
__tablename__ = "media"
|
||||
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
album_id = Column(Integer, ForeignKey("albums.id"), nullable=False)
|
||||
file_path = Column(String, nullable=False)
|
||||
thumbnail_path = Column(String)
|
||||
media_type = Column(SQLEnum(MediaType), nullable=False)
|
||||
caption = Column(Text)
|
||||
file_size = Column(Integer) # in bytes
|
||||
width = Column(Integer)
|
||||
height = Column(Integer)
|
||||
duration = Column(Integer) # in seconds for videos
|
||||
likes_count = Column(Integer, default=0)
|
||||
created_at = Column(DateTime, default=datetime.utcnow)
|
||||
|
||||
# Relationships
|
||||
album = relationship("Album", back_populates="media")
|
||||
likes = relationship("MediaLike", back_populates="media", cascade="all, delete-orphan")
|
||||
|
||||
class MediaLike(Base):
|
||||
__tablename__ = "media_likes"
|
||||
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
media_id = Column(Integer, ForeignKey("media.id"), nullable=False)
|
||||
user_id = Column(Integer, ForeignKey("users.id"), nullable=False)
|
||||
created_at = Column(DateTime, default=datetime.utcnow)
|
||||
|
||||
# Relationships
|
||||
media = relationship("Media", back_populates="likes")
|
||||
user = relationship("User", back_populates="media_likes")
|
||||
46
backend/models/event.py
Normal file
46
backend/models/event.py
Normal file
@@ -0,0 +1,46 @@
|
||||
from sqlalchemy import Column, Integer, String, DateTime, ForeignKey, Text, Enum as SQLEnum, Float
|
||||
from sqlalchemy.orm import relationship
|
||||
from datetime import datetime
|
||||
import enum
|
||||
from config.database import Base
|
||||
|
||||
class ParticipationStatus(enum.Enum):
|
||||
PRESENT = "present"
|
||||
ABSENT = "absent"
|
||||
MAYBE = "maybe"
|
||||
PENDING = "pending"
|
||||
|
||||
class Event(Base):
|
||||
__tablename__ = "events"
|
||||
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
title = Column(String, nullable=False)
|
||||
description = Column(Text)
|
||||
location = Column(String)
|
||||
latitude = Column(Float, nullable=True) # Coordonnée latitude
|
||||
longitude = Column(Float, nullable=True) # Coordonnée longitude
|
||||
date = Column(DateTime, nullable=False)
|
||||
end_date = Column(DateTime)
|
||||
creator_id = Column(Integer, ForeignKey("users.id"), nullable=False)
|
||||
cover_image = Column(String)
|
||||
created_at = Column(DateTime, default=datetime.utcnow)
|
||||
updated_at = Column(DateTime, default=datetime.utcnow, onupdate=datetime.utcnow)
|
||||
|
||||
# Relationships
|
||||
creator = relationship("User", back_populates="created_events")
|
||||
participations = relationship("EventParticipation", back_populates="event", cascade="all, delete-orphan")
|
||||
albums = relationship("Album", back_populates="event")
|
||||
|
||||
class EventParticipation(Base):
|
||||
__tablename__ = "event_participations"
|
||||
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
event_id = Column(Integer, ForeignKey("events.id"), nullable=False)
|
||||
user_id = Column(Integer, ForeignKey("users.id"), nullable=False)
|
||||
status = Column(SQLEnum(ParticipationStatus), default=ParticipationStatus.PENDING)
|
||||
response_date = Column(DateTime, default=datetime.utcnow)
|
||||
created_at = Column(DateTime, default=datetime.utcnow)
|
||||
|
||||
# Relationships
|
||||
event = relationship("Event", back_populates="participations")
|
||||
user = relationship("User", back_populates="event_participations")
|
||||
15
backend/models/information.py
Normal file
15
backend/models/information.py
Normal file
@@ -0,0 +1,15 @@
|
||||
from sqlalchemy import Column, Integer, String, DateTime, Text, Boolean
|
||||
from datetime import datetime
|
||||
from config.database import Base
|
||||
|
||||
class Information(Base):
|
||||
__tablename__ = "informations"
|
||||
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
title = Column(String, nullable=False)
|
||||
content = Column(Text, nullable=False)
|
||||
category = Column(String, default="general") # general, release, upcoming, etc.
|
||||
is_published = Column(Boolean, default=True)
|
||||
priority = Column(Integer, default=0) # Pour l'ordre d'affichage
|
||||
created_at = Column(DateTime, default=datetime.utcnow)
|
||||
updated_at = Column(DateTime, default=datetime.utcnow, onupdate=datetime.utcnow)
|
||||
29
backend/models/notification.py
Normal file
29
backend/models/notification.py
Normal file
@@ -0,0 +1,29 @@
|
||||
from sqlalchemy import Column, Integer, String, DateTime, ForeignKey, Boolean, Text, Enum as SQLEnum
|
||||
from sqlalchemy.orm import relationship
|
||||
from datetime import datetime
|
||||
import enum
|
||||
from config.database import Base
|
||||
|
||||
class NotificationType(enum.Enum):
|
||||
EVENT_INVITATION = "event_invitation"
|
||||
EVENT_REMINDER = "event_reminder"
|
||||
POST_MENTION = "post_mention"
|
||||
NEW_ALBUM = "new_album"
|
||||
NEW_VLOG = "new_vlog"
|
||||
SYSTEM = "system"
|
||||
|
||||
class Notification(Base):
|
||||
__tablename__ = "notifications"
|
||||
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
user_id = Column(Integer, ForeignKey("users.id"), nullable=False)
|
||||
type = Column(SQLEnum(NotificationType), nullable=False)
|
||||
title = Column(String, nullable=False)
|
||||
message = Column(Text, nullable=False)
|
||||
link = Column(String) # Link to the related content
|
||||
is_read = Column(Boolean, default=False)
|
||||
created_at = Column(DateTime, default=datetime.utcnow)
|
||||
read_at = Column(DateTime, nullable=True)
|
||||
|
||||
# Relationships
|
||||
user = relationship("User", back_populates="notifications")
|
||||
60
backend/models/post.py
Normal file
60
backend/models/post.py
Normal file
@@ -0,0 +1,60 @@
|
||||
from sqlalchemy import Column, Integer, String, DateTime, ForeignKey, Text
|
||||
from sqlalchemy.orm import relationship
|
||||
from datetime import datetime
|
||||
from config.database import Base
|
||||
|
||||
class Post(Base):
|
||||
__tablename__ = "posts"
|
||||
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
author_id = Column(Integer, ForeignKey("users.id"), nullable=False)
|
||||
content = Column(Text, nullable=False)
|
||||
image_url = Column(String)
|
||||
likes_count = Column(Integer, default=0)
|
||||
comments_count = Column(Integer, default=0)
|
||||
created_at = Column(DateTime, default=datetime.utcnow)
|
||||
updated_at = Column(DateTime, default=datetime.utcnow, onupdate=datetime.utcnow)
|
||||
|
||||
# Relationships
|
||||
author = relationship("User", back_populates="posts")
|
||||
mentions = relationship("PostMention", back_populates="post", cascade="all, delete-orphan")
|
||||
likes = relationship("PostLike", back_populates="post", cascade="all, delete-orphan")
|
||||
comments = relationship("PostComment", back_populates="post", cascade="all, delete-orphan")
|
||||
|
||||
class PostMention(Base):
|
||||
__tablename__ = "post_mentions"
|
||||
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
post_id = Column(Integer, ForeignKey("posts.id"), nullable=False)
|
||||
mentioned_user_id = Column(Integer, ForeignKey("users.id"), nullable=False)
|
||||
created_at = Column(DateTime, default=datetime.utcnow)
|
||||
|
||||
# Relationships
|
||||
post = relationship("Post", back_populates="mentions")
|
||||
mentioned_user = relationship("User", back_populates="mentions")
|
||||
|
||||
class PostLike(Base):
|
||||
__tablename__ = "post_likes"
|
||||
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
post_id = Column(Integer, ForeignKey("posts.id"), nullable=False)
|
||||
user_id = Column(Integer, ForeignKey("users.id"), nullable=False)
|
||||
created_at = Column(DateTime, default=datetime.utcnow)
|
||||
|
||||
# Relationships
|
||||
post = relationship("Post", back_populates="likes")
|
||||
user = relationship("User", back_populates="post_likes")
|
||||
|
||||
class PostComment(Base):
|
||||
__tablename__ = "post_comments"
|
||||
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
post_id = Column(Integer, ForeignKey("posts.id"), nullable=False)
|
||||
author_id = Column(Integer, ForeignKey("users.id"), nullable=False)
|
||||
content = Column(Text, nullable=False)
|
||||
created_at = Column(DateTime, default=datetime.utcnow)
|
||||
updated_at = Column(DateTime, default=datetime.utcnow, onupdate=datetime.utcnow)
|
||||
|
||||
# Relationships
|
||||
post = relationship("Post", back_populates="comments")
|
||||
author = relationship("User", back_populates="post_comments")
|
||||
15
backend/models/settings.py
Normal file
15
backend/models/settings.py
Normal file
@@ -0,0 +1,15 @@
|
||||
from sqlalchemy import Column, Integer, String, Float, Boolean, DateTime
|
||||
from datetime import datetime
|
||||
from config.database import Base
|
||||
|
||||
class SystemSettings(Base):
|
||||
__tablename__ = "system_settings"
|
||||
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
key = Column(String, unique=True, nullable=False, index=True)
|
||||
value = Column(String, nullable=False)
|
||||
description = Column(String)
|
||||
category = Column(String, default="general") # general, uploads, notifications, etc.
|
||||
is_editable = Column(Boolean, default=True)
|
||||
created_at = Column(DateTime, default=datetime.utcnow)
|
||||
updated_at = Column(DateTime, default=datetime.utcnow, onupdate=datetime.utcnow)
|
||||
45
backend/models/ticket.py
Normal file
45
backend/models/ticket.py
Normal file
@@ -0,0 +1,45 @@
|
||||
from sqlalchemy import Column, Integer, String, DateTime, ForeignKey, Text, Enum as SQLEnum
|
||||
from sqlalchemy.orm import relationship
|
||||
from datetime import datetime
|
||||
import enum
|
||||
from config.database import Base
|
||||
|
||||
class TicketType(enum.Enum):
|
||||
BUG = "bug"
|
||||
FEATURE_REQUEST = "feature_request"
|
||||
IMPROVEMENT = "improvement"
|
||||
SUPPORT = "support"
|
||||
OTHER = "other"
|
||||
|
||||
class TicketStatus(enum.Enum):
|
||||
OPEN = "open"
|
||||
IN_PROGRESS = "in_progress"
|
||||
RESOLVED = "resolved"
|
||||
CLOSED = "closed"
|
||||
|
||||
class TicketPriority(enum.Enum):
|
||||
LOW = "low"
|
||||
MEDIUM = "medium"
|
||||
HIGH = "high"
|
||||
URGENT = "urgent"
|
||||
|
||||
class Ticket(Base):
|
||||
__tablename__ = "tickets"
|
||||
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
title = Column(String, nullable=False)
|
||||
description = Column(Text, nullable=False)
|
||||
ticket_type = Column(SQLEnum(TicketType), nullable=False, default=TicketType.OTHER)
|
||||
status = Column(SQLEnum(TicketStatus), nullable=False, default=TicketStatus.OPEN)
|
||||
priority = Column(SQLEnum(TicketPriority), nullable=False, default=TicketPriority.MEDIUM)
|
||||
user_id = Column(Integer, ForeignKey("users.id"), nullable=False)
|
||||
assigned_to = Column(Integer, ForeignKey("users.id"), nullable=True)
|
||||
screenshot_path = Column(String, nullable=True)
|
||||
admin_notes = Column(Text, nullable=True)
|
||||
created_at = Column(DateTime, default=datetime.utcnow)
|
||||
updated_at = Column(DateTime, default=datetime.utcnow, onupdate=datetime.utcnow)
|
||||
resolved_at = Column(DateTime, nullable=True)
|
||||
|
||||
# Relationships
|
||||
user = relationship("User", foreign_keys=[user_id], back_populates="tickets")
|
||||
assigned_admin = relationship("User", foreign_keys=[assigned_to])
|
||||
35
backend/models/user.py
Normal file
35
backend/models/user.py
Normal file
@@ -0,0 +1,35 @@
|
||||
from sqlalchemy import Column, Integer, String, Boolean, DateTime, Float
|
||||
from sqlalchemy.orm import relationship
|
||||
from datetime import datetime
|
||||
from config.database import Base
|
||||
|
||||
class User(Base):
|
||||
__tablename__ = "users"
|
||||
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
email = Column(String, unique=True, index=True, nullable=False)
|
||||
username = Column(String, unique=True, index=True, nullable=False)
|
||||
full_name = Column(String, nullable=False)
|
||||
hashed_password = Column(String, nullable=False)
|
||||
is_active = Column(Boolean, default=True)
|
||||
is_admin = Column(Boolean, default=False)
|
||||
avatar_url = Column(String, nullable=True)
|
||||
bio = Column(String, nullable=True)
|
||||
attendance_rate = Column(Float, default=0.0)
|
||||
created_at = Column(DateTime, default=datetime.utcnow)
|
||||
updated_at = Column(DateTime, default=datetime.utcnow, onupdate=datetime.utcnow)
|
||||
|
||||
# Relationships
|
||||
event_participations = relationship("EventParticipation", back_populates="user", cascade="all, delete-orphan")
|
||||
created_events = relationship("Event", back_populates="creator", cascade="all, delete-orphan")
|
||||
albums = relationship("Album", back_populates="creator", cascade="all, delete-orphan")
|
||||
posts = relationship("Post", back_populates="author", cascade="all, delete-orphan")
|
||||
mentions = relationship("PostMention", back_populates="mentioned_user", cascade="all, delete-orphan")
|
||||
vlogs = relationship("Vlog", back_populates="author", cascade="all, delete-orphan")
|
||||
notifications = relationship("Notification", back_populates="user", cascade="all, delete-orphan")
|
||||
vlog_likes = relationship("VlogLike", back_populates="user", cascade="all, delete-orphan")
|
||||
vlog_comments = relationship("VlogComment", back_populates="user", cascade="all, delete-orphan")
|
||||
media_likes = relationship("MediaLike", back_populates="user", cascade="all, delete-orphan")
|
||||
post_likes = relationship("PostLike", back_populates="user", cascade="all, delete-orphan")
|
||||
post_comments = relationship("PostComment", back_populates="author", cascade="all, delete-orphan")
|
||||
tickets = relationship("Ticket", foreign_keys="[Ticket.user_id]", back_populates="user")
|
||||
50
backend/models/vlog.py
Normal file
50
backend/models/vlog.py
Normal file
@@ -0,0 +1,50 @@
|
||||
from sqlalchemy import Column, Integer, String, DateTime, ForeignKey, Text
|
||||
from sqlalchemy.orm import relationship
|
||||
from datetime import datetime
|
||||
from config.database import Base
|
||||
|
||||
class Vlog(Base):
|
||||
__tablename__ = "vlogs"
|
||||
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
author_id = Column(Integer, ForeignKey("users.id"), nullable=False)
|
||||
title = Column(String, nullable=False)
|
||||
description = Column(Text)
|
||||
video_url = Column(String, nullable=False)
|
||||
thumbnail_url = Column(String)
|
||||
duration = Column(Integer) # in seconds
|
||||
views_count = Column(Integer, default=0)
|
||||
likes_count = Column(Integer, default=0)
|
||||
created_at = Column(DateTime, default=datetime.utcnow)
|
||||
updated_at = Column(DateTime, default=datetime.utcnow, onupdate=datetime.utcnow)
|
||||
|
||||
# Relationships
|
||||
author = relationship("User", back_populates="vlogs")
|
||||
likes = relationship("VlogLike", back_populates="vlog", cascade="all, delete-orphan")
|
||||
comments = relationship("VlogComment", back_populates="vlog", cascade="all, delete-orphan")
|
||||
|
||||
class VlogLike(Base):
|
||||
__tablename__ = "vlog_likes"
|
||||
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
vlog_id = Column(Integer, ForeignKey("vlogs.id"), nullable=False)
|
||||
user_id = Column(Integer, ForeignKey("users.id"), nullable=False)
|
||||
created_at = Column(DateTime, default=datetime.utcnow)
|
||||
|
||||
# Relationships
|
||||
vlog = relationship("Vlog", back_populates="likes")
|
||||
user = relationship("User", back_populates="vlog_likes")
|
||||
|
||||
class VlogComment(Base):
|
||||
__tablename__ = "vlog_comments"
|
||||
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
vlog_id = Column(Integer, ForeignKey("vlogs.id"), nullable=False)
|
||||
user_id = Column(Integer, ForeignKey("users.id"), nullable=False)
|
||||
content = Column(Text, nullable=False)
|
||||
created_at = Column(DateTime, default=datetime.utcnow)
|
||||
updated_at = Column(DateTime, default=datetime.utcnow, onupdate=datetime.utcnow)
|
||||
|
||||
# Relationships
|
||||
vlog = relationship("Vlog", back_populates="comments")
|
||||
user = relationship("User", back_populates="vlog_comments")
|
||||
Reference in New Issue
Block a user