Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tiers de empreses #246

Merged
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/impl/Company/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
5 changes: 5 additions & 0 deletions src/impl/Company/router_v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,8 @@ def delete_user(companyId: int,
@router.get("/{companyId}/events", response_model=EventGet)
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)
30 changes: 30 additions & 0 deletions src/impl/Company/schema.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from typing import Optional
from pydantic import field_validator

from src.utils.Base.BaseSchema import BaseSchema

Expand All @@ -8,23 +9,44 @@ 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

Expand All @@ -34,7 +56,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
5 changes: 5 additions & 0 deletions src/impl/Company/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ 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: CompanyCreate, data: BaseToken):
if not data.check([UserType.LLEIDAHACKER]):
raise AuthenticationException("Not authorized")
Expand Down
8 changes: 5 additions & 3 deletions src/impl/Event/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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)
Expand Down
Loading