From dd442ddf26d3cbfe7674159303426ec2429efa15 Mon Sep 17 00:00:00 2001 From: gazev Date: Sun, 17 Nov 2024 15:25:32 +0000 Subject: [PATCH] fix: member projects association --- app/__init__.py | 2 +- app/commands/commands.py | 2 +- app/config.py | 2 +- app/models/models.py | 8 ++++---- app/services/member_project_service.py | 6 +++--- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/app/__init__.py b/app/__init__.py index ba302a3..2980b6f 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -33,7 +33,7 @@ def create_app(config_class=Config): register_error_handlers(flask_app) register_commands(flask_app) - if (frontend_uri := flask_app.config.get("FRONTEND_ORIGIN", "")) != "": + if (frontend_uri := flask_app.config.get("FRONTEND_URI", "")) != "": CORS(flask_app, origins=[frontend_uri], supports_credentials=True) setup_logger(flask_app) diff --git a/app/commands/commands.py b/app/commands/commands.py index 5c0d209..19d1a50 100644 --- a/app/commands/commands.py +++ b/app/commands/commands.py @@ -29,7 +29,7 @@ def populate_admin_user(): admin = Member( username=admin_username, password=admin_password, - ist_id="ist"+admin_username, + ist_id="ist1"+admin_username, member_number=0, name=admin_username, join_date="1970-01-01", diff --git a/app/config.py b/app/config.py index 87b2d19..b2fc354 100644 --- a/app/config.py +++ b/app/config.py @@ -42,7 +42,7 @@ class Config: LOGS_PATH = os.path.join(basedir, _get_env_or_default("LOGS_PATH", "")) - FRONTEND_ORIGIN = _get_env_or_default("FRONTEND_ORIGIN", "http://localhost:3000") + FRONTEND_URI = _get_env_or_default("FRONTEND_URI", "http://localhost:3000") ADMIN_USERNAME = _get_env_or_default("ADMIN_USERNAME", "") ADMIN_PASSWORD = _get_env_or_default("ADMIN_PASSWORD", "") diff --git a/app/models/models.py b/app/models/models.py index 0ea76e3..8245f75 100644 --- a/app/models/models.py +++ b/app/models/models.py @@ -103,7 +103,7 @@ def check_invariants(self): if not isinstance(self.ist_id, str) or not self.ist_id or \ len(self.ist_id) < 4 or len(self.ist_id) > 20 or \ not self.ist_id.startswith("ist1"): - raise ValueError("Field 'ist_id' must be a valid IST student number.") + raise ValueError(f"Field 'ist_id' must be a valid IST student number.") # name if not isinstance(self.name, str) or not self.name or \ @@ -121,7 +121,7 @@ def check_invariants(self): raise ValueError("Field 'course' must be a non-empty string with max 8 characters.") # member_number - if not isinstance(self.member_number, int) or self.member_number <= 0: + if not isinstance(self.member_number, int) or self.member_number < 0: raise ValueError("Field 'member_number' must be a positive integer.") # join_date @@ -269,8 +269,8 @@ def check_invariants(self): def to_dict(self): return { - "member_id": self.member_id, - "project_id": self.project_id, + "username": self.member_username, + "project_name": self.project_name, "entry_date": self.entry_date, "contributions": self.contributions, "exit_date": self.exit_date diff --git a/app/services/member_project_service.py b/app/services/member_project_service.py index 528cb1b..e19a1a1 100644 --- a/app/services/member_project_service.py +++ b/app/services/member_project_service.py @@ -46,8 +46,8 @@ def delete_project_member( return member.id -def get_member_projects(member: Member) -> List[Project]: - return [assoc.project for assoc in member.projects if assoc.project] +def get_member_projects(member: Member) -> List[MemberProjects]: + return [assoc for assoc in member.projects if assoc.project] def get_project_members(project: Project) -> List[Member]: - return [assoc.member for assoc in project.members if assoc.member] \ No newline at end of file + return [assoc for assoc in project.members if assoc.member] \ No newline at end of file