mitlist/be/app/schemas/group.py
Mohamad 0cd1b9c84d feat: Implement soft delete functionality and remove cascading deletes
This commit introduces a significant update to the database schema and models by implementing soft delete functionality across multiple tables, including users, groups, lists, items, expenses, and more. Key changes include:

- Addition of `deleted_at` and `is_deleted` columns to facilitate soft deletes.
- Removal of cascading delete behavior from foreign key constraints to prevent accidental data loss.
- Updates to the models to incorporate the new soft delete mixin, ensuring consistent handling of deletions across the application.
- Introduction of a new endpoint for group deletion, requiring owner confirmation to enhance data integrity.

These changes aim to improve data safety and compliance with data protection regulations while maintaining the integrity of related records.
2025-06-25 20:16:28 +02:00

45 lines
1.2 KiB
Python

from pydantic import BaseModel, ConfigDict, computed_field
from datetime import datetime, date
from typing import Optional, List
from .user import UserPublic
from .chore import ChoreHistoryPublic
class GroupCreate(BaseModel):
name: str
class GroupDelete(BaseModel):
confirmation_name: str
class GroupScheduleGenerateRequest(BaseModel):
start_date: date
end_date: date
member_ids: Optional[List[int]] = None
class GroupPublic(BaseModel):
id: int
name: str
created_by_id: int
created_at: datetime
member_associations: Optional[List["UserGroupPublic"]] = None
chore_history: Optional[List[ChoreHistoryPublic]] = []
@computed_field
@property
def members(self) -> Optional[List[UserPublic]]:
if not self.member_associations:
return None
return [assoc.user for assoc in self.member_associations if assoc.user]
model_config = ConfigDict(from_attributes=True)
class UserGroupPublic(BaseModel):
id: int
user_id: int
group_id: int
role: str
joined_at: datetime
user: Optional[UserPublic] = None
model_config = ConfigDict(from_attributes=True)
GroupPublic.model_rebuild()