From 3cc24ba0811ec5164eea543f1de70edace6963d3 Mon Sep 17 00:00:00 2001 From: naimsg16 Date: Wed, 21 Aug 2024 18:25:31 +0200 Subject: [PATCH 1/6] Tiers de empreses --- src/impl/Company/model.py | 3 ++- src/impl/Company/router_v1.py | 5 +++++ src/impl/Company/schema.py | 29 +++++++++++++++++++++++++++++ src/impl/Company/service.py | 6 ++++++ 4 files changed, 42 insertions(+), 1 deletion(-) diff --git a/src/impl/Company/model.py b/src/impl/Company/model.py index 82d06dac..73b81eca 100644 --- a/src/impl/Company/model.py +++ b/src/impl/Company/model.py @@ -14,8 +14,9 @@ class Company(BaseModel): telephone: str = Column(String) website: str = Column(String) image: str = Column(String) + tier: int = Column(Integer) # is_image_url: bool = Column(Boolean, default=False) linkdin: str = Column(String) leader_id: int = Column(Integer, ForeignKey('my_user.id')) users = relationship('User', secondary='company_user') - events = relationship('Event', secondary='company_event_participation') + events = relationship('Event', secondary='company_event_participation') \ No newline at end of file diff --git a/src/impl/Company/router_v1.py b/src/impl/Company/router_v1.py index 0e1dbba1..741d7ccd 100644 --- a/src/impl/Company/router_v1.py +++ b/src/impl/Company/router_v1.py @@ -5,6 +5,7 @@ from src.impl.Company.schema import CompanyCreate as CompanyCreateSchema from src.impl.Company.schema import CompanyGet as CompanyGetSchema from src.impl.Company.schema import CompanyGetAll as CompanyGetAllSchema +from src.impl.Company.schema import CompanyGetByTier as CompanyGetByTierSchema from src.impl.Company.schema import CompanyUpdate as CompanyUpdateSchema from src.impl.Company.service import CompanyService from src.impl.CompanyUser.schema import CompanyUserGet as CompanyUserGetSchema @@ -79,3 +80,7 @@ def delete_user(companyId: int, @router.get("/{companyId}/events", response_model=EventGetSchema) def get_events(companyId: int, token: BaseToken = Depends(JWTBearer())): return company_service.get_company_events(companyId) + +@router.get("/{tier}", response_model=CompanyGetByTierSchema) +def get_by_tier(tier: int): + return company_service.get_by_tier(tier) \ No newline at end of file diff --git a/src/impl/Company/schema.py b/src/impl/Company/schema.py index e0cfdbaa..b5e04033 100644 --- a/src/impl/Company/schema.py +++ b/src/impl/Company/schema.py @@ -1,4 +1,6 @@ from typing import Optional +from pydantic import field_validator + from src.utils.Base.BaseSchema import BaseSchema @@ -8,22 +10,41 @@ class CompanyCreate(BaseSchema): description: str website: str image: Optional[str] = None + tier: int #is_image_url: Optional[bool] = None address: str linkdin: str telephone: str + @field_validator('tier') + @classmethod + def tier_validator(cls, v): + if v < 0: + raise ValueError('tier must be a positive integer') + return v + class CompanyGet(BaseSchema): name: str description: str website: str image: str + tier: int #is_image_url: bool address: str linkdin: str telephone: str +class CompanyGetByTier(BaseSchema): + name: str + description: str + website: str + tier: int + image: Optional[str] = None + #is_image_url: Optional[bool] = None + address: str + linkdin: str + telephone: str class CompanyGetAll(CompanyGet): id: int @@ -34,7 +55,15 @@ class CompanyUpdate(BaseSchema): description: Optional[str] = None website: Optional[str] = None image: Optional[str] = None + tier: Optional[int] = None #is_image_url: Optional[bool] = None address: Optional[str] = None linkdin: Optional[str] = None telephone: Optional[str] = None + + @field_validator('tier') + @classmethod + def tier_validator(cls, v): + if v < 0: + raise ValueError('tier must be a positive integer') + return v \ No newline at end of file diff --git a/src/impl/Company/service.py b/src/impl/Company/service.py index adffcfcc..c7ff904c 100644 --- a/src/impl/Company/service.py +++ b/src/impl/Company/service.py @@ -28,6 +28,12 @@ def get_by_id(self, companyId: int): def get_company(self, companyId: int): return self.get_by_id(companyId) + + def get_by_tier(self, tier: int): + companies = db.session.query(ModelCompany).filter( + ModelCompany.tier == tier + ) + return companies def add_company(self, payload: CompanyCreateSchema, data: BaseToken): if not data.check([UserType.LLEIDAHACKER]): From 04e3650e41032387ae1b60cde48528edde9ef5df Mon Sep 17 00:00:00 2001 From: github-actions Date: Mon, 23 Sep 2024 20:17:20 +0000 Subject: [PATCH 2/6] Automated autoyapf fixes --- src/impl/Company/router_v1.py | 3 ++- src/impl/Company/schema.py | 5 +++-- src/impl/Company/service.py | 5 ++--- src/impl/Event/service.py | 8 +++++--- 4 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/impl/Company/router_v1.py b/src/impl/Company/router_v1.py index d8c17eef..808b7550 100644 --- a/src/impl/Company/router_v1.py +++ b/src/impl/Company/router_v1.py @@ -79,6 +79,7 @@ def delete_user(companyId: int, def get_events(companyId: int, token: BaseToken = Depends(JWTBearer())): return company_service.get_company_events(companyId) + @router.get("/{tier}", response_model=CompanyGetByTierSchema) def get_by_tier(tier: int): - return company_service.get_by_tier(tier) \ No newline at end of file + return company_service.get_by_tier(tier) diff --git a/src/impl/Company/schema.py b/src/impl/Company/schema.py index b5e04033..32eb23e3 100644 --- a/src/impl/Company/schema.py +++ b/src/impl/Company/schema.py @@ -1,7 +1,6 @@ from typing import Optional from pydantic import field_validator - from src.utils.Base.BaseSchema import BaseSchema @@ -35,6 +34,7 @@ class CompanyGet(BaseSchema): linkdin: str telephone: str + class CompanyGetByTier(BaseSchema): name: str description: str @@ -46,6 +46,7 @@ class CompanyGetByTier(BaseSchema): linkdin: str telephone: str + class CompanyGetAll(CompanyGet): id: int @@ -66,4 +67,4 @@ class CompanyUpdate(BaseSchema): def tier_validator(cls, v): if v < 0: raise ValueError('tier must be a positive integer') - return v \ No newline at end of file + return v diff --git a/src/impl/Company/service.py b/src/impl/Company/service.py index d50b9594..dfd77d0e 100644 --- a/src/impl/Company/service.py +++ b/src/impl/Company/service.py @@ -28,11 +28,10 @@ def get_by_id(self, companyId: int): def get_company(self, companyId: int): return self.get_by_id(companyId) - + def get_by_tier(self, tier: int): companies = db.session.query(ModelCompany).filter( - ModelCompany.tier == tier - ) + ModelCompany.tier == tier) return companies def add_company(self, payload: CompanyCreate, data: BaseToken): diff --git a/src/impl/Event/service.py b/src/impl/Event/service.py index 1b46aa59..ef9ed4f0 100644 --- a/src/impl/Event/service.py +++ b/src/impl/Event/service.py @@ -227,10 +227,10 @@ def add_hacker(self, event_id: int, hacker_id: int, db.session.commit() db.session.refresh(event) return event - + @BaseService.needs_service(UserService) def update_register(self, event_id: int, hacker_id: int, - payload: HackerEventRegistration, data: BaseToken): + payload: HackerEventRegistration, data: BaseToken): if not data.check([UserType.LLEIDAHACKER]) and not data.check( [UserType.HACKER], hacker_id): raise AuthenticationException("Not authorized") @@ -244,7 +244,9 @@ def update_register(self, event_id: int, hacker_id: int, hacker = self.user_service.get_by_id(hacker_id) if hacker not in event.registered_hackers: raise InvalidDataException('Hacker is not registered') - reg = db.session.query(HackerEventRegistration).filter(HackerRegistration.user_id == hacker_id, HackerRegistration.event_id == event_id).first() + reg = db.session.query(HackerEventRegistration).filter( + HackerRegistration.user_id == hacker_id, + HackerRegistration.event_id == event_id).first() if reg is None: raise InvalidDataException('Hacker is not registered') set_existing_data(reg, payload) From c3b1ecd6dcef924e765f8307b781a548140a6ec3 Mon Sep 17 00:00:00 2001 From: github-actions Date: Mon, 23 Sep 2024 20:34:57 +0000 Subject: [PATCH 3/6] Automated autoyapf fixes --- src/impl/Event/router_v1.py | 1 + src/impl/Event/service.py | 6 ++++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/impl/Event/router_v1.py b/src/impl/Event/router_v1.py index 409c3c2e..80f3f61f 100644 --- a/src/impl/Event/router_v1.py +++ b/src/impl/Event/router_v1.py @@ -342,6 +342,7 @@ def get_status(event_id: int): def get_food_restrictions(event_id: int): return event_service.get_food_restrictions(event_id) + @router.get("/{event_id}/credits") def get_credits(event_id: int, token: BaseToken = Depends(JWTBearer())): return event_service.get_credits(event_id, token) diff --git a/src/impl/Event/service.py b/src/impl/Event/service.py index efcf4488..825aa755 100644 --- a/src/impl/Event/service.py +++ b/src/impl/Event/service.py @@ -397,14 +397,16 @@ def get_food_restrictions(self, eventId: int): restrictions.append(user.food_restrictions) # remove duplicates return list(set(restrictions)) - + @BaseService.needs_service(HackerService) def get_credits(self, eventId: int, data: BaseToken): if not data.check([UserType.LLEIDAHACKER]): raise AuthenticationException("Not authorized") users = {_.id: _.email for _ in self.hacker_service.get_all()} event = self.get_by_id(eventId) - regs = db.session.query(HackerRegistration).filter(HackerRegistration.event_id == eventId, HackerRegistration.wants_credit==True).all() + regs = db.session.query(HackerRegistration).filter( + HackerRegistration.event_id == eventId, + HackerRegistration.wants_credit == True).all() return [users[_.user_id] for _ in regs] @BaseService.needs_service('HackerGroupService') From 0fe7cf0eeb24f0f77f57e043fbe67d934570339d Mon Sep 17 00:00:00 2001 From: elver5041 Date: Mon, 23 Sep 2024 22:38:10 +0200 Subject: [PATCH 4/6] alembic --- .../2024-09-23_22-37__20bff18796a3.py | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 alembic/versions/2024-09-23_22-37__20bff18796a3.py diff --git a/alembic/versions/2024-09-23_22-37__20bff18796a3.py b/alembic/versions/2024-09-23_22-37__20bff18796a3.py new file mode 100644 index 00000000..0aae08ad --- /dev/null +++ b/alembic/versions/2024-09-23_22-37__20bff18796a3.py @@ -0,0 +1,28 @@ +"""empty message + +Revision ID: 20bff18796a3 +Revises: 83b72cd40dab +Create Date: 2024-09-23 22:37:39.866908 + +""" +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision = '20bff18796a3' +down_revision = '83b72cd40dab' +branch_labels = None +depends_on = None + + +def upgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.add_column('company', sa.Column('tier', sa.Integer(), nullable=True)) + # ### end Alembic commands ### + + +def downgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.drop_column('company', 'tier') + # ### end Alembic commands ### From 6513d0ec0105298d2c5ed3d624c414689a70f61e Mon Sep 17 00:00:00 2001 From: github-actions Date: Mon, 23 Sep 2024 20:38:51 +0000 Subject: [PATCH 5/6] Automated autoyapf fixes --- alembic/versions/2024-09-23_22-37__20bff18796a3.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/alembic/versions/2024-09-23_22-37__20bff18796a3.py b/alembic/versions/2024-09-23_22-37__20bff18796a3.py index 0aae08ad..fb99284a 100644 --- a/alembic/versions/2024-09-23_22-37__20bff18796a3.py +++ b/alembic/versions/2024-09-23_22-37__20bff18796a3.py @@ -8,7 +8,6 @@ from alembic import op import sqlalchemy as sa - # revision identifiers, used by Alembic. revision = '20bff18796a3' down_revision = '83b72cd40dab' @@ -17,12 +16,12 @@ def upgrade(): - # ### commands auto generated by Alembic - please adjust! ### - op.add_column('company', sa.Column('tier', sa.Integer(), nullable=True)) + # ### commands auto generated by Alembic - please adjust! ### + op.add_column('company', sa.Column('tier', sa.Integer(), nullable=True)) # ### end Alembic commands ### def downgrade(): - # ### commands auto generated by Alembic - please adjust! ### - op.drop_column('company', 'tier') + # ### commands auto generated by Alembic - please adjust! ### + op.drop_column('company', 'tier') # ### end Alembic commands ### From fb751c79f793c008da5f4178609ea73c8fa09034 Mon Sep 17 00:00:00 2001 From: elver5041 Date: Mon, 23 Sep 2024 22:54:07 +0200 Subject: [PATCH 6/6] shema fix --- src/impl/Company/router_v1.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/impl/Company/router_v1.py b/src/impl/Company/router_v1.py index 808b7550..24b24e93 100644 --- a/src/impl/Company/router_v1.py +++ b/src/impl/Company/router_v1.py @@ -2,7 +2,7 @@ from fastapi import APIRouter, Depends -from src.impl.Company.schema import CompanyCreate +from src.impl.Company.schema import CompanyCreate, CompanyGetByTier from src.impl.Company.schema import CompanyGet from src.impl.Company.schema import CompanyGetAll from src.impl.Company.schema import CompanyUpdate @@ -80,6 +80,6 @@ def get_events(companyId: int, token: BaseToken = Depends(JWTBearer())): return company_service.get_company_events(companyId) -@router.get("/{tier}", response_model=CompanyGetByTierSchema) +@router.get("/{tier}", response_model=CompanyGetByTier) def get_by_tier(tier: int): return company_service.get_by_tier(tier)