user selection compoleted tested
This commit is contained in:
58
ServicesApi/Builds/Identity/events/people/flat_tenant.py
Normal file
58
ServicesApi/Builds/Identity/events/people/flat_tenant.py
Normal file
@@ -0,0 +1,58 @@
|
||||
from typing import Any
|
||||
|
||||
from Initializer.event_clusters import Event
|
||||
from Validations.response import (
|
||||
PaginateOnly,
|
||||
Pagination,
|
||||
PaginationResult,
|
||||
PostgresResponseSingle,
|
||||
PostgresResponse,
|
||||
EndpointResponse
|
||||
)
|
||||
from Validations.defaults.validations import CommonHeaders
|
||||
from Schemas import People
|
||||
from Extensions.Middlewares.token_provider import TokenProvider
|
||||
|
||||
|
||||
# List all people endpoint Flat Tenant
|
||||
FlatTenantPeopleListEvent = Event(
|
||||
name="flat_tenant_people_list",
|
||||
key="7cb248d3-d75a-4d28-8be5-f147089ce654",
|
||||
request_validator=None, # TODO: Add request validator
|
||||
response_validator=None, # TODO: Add response validator
|
||||
description="Flat Tenant People List all flat tenant users endpoint",
|
||||
)
|
||||
|
||||
class FlatTenantPeopleListPydantic:
|
||||
...
|
||||
|
||||
|
||||
|
||||
def flat_tenant_people_list_callable(list_options: PaginateOnly, header: CommonHeaders):
|
||||
list_options = PaginateOnly(**list_options.model_dump())
|
||||
token_object = TokenProvider.get_dict_from_redis(token=header.token)
|
||||
if not token_object.is_occupant:
|
||||
raise Exception("Forbidden for employees")
|
||||
|
||||
pagination_query = {}
|
||||
if list_options.query:
|
||||
pagination_query = FlatTenantPeopleListPydantic(**list_options.query)
|
||||
|
||||
with People.new_session() as db_session:
|
||||
People.set_session(db_session)
|
||||
if pagination_query:
|
||||
people_list = People.query.filter(
|
||||
*People.convert(pagination_query),
|
||||
People.build_parts_id == token_object.selected_occupant.build_id
|
||||
)
|
||||
else:
|
||||
people_list = People.query.filter(
|
||||
People.build_parts_id == token_object.selected_occupant.build_id
|
||||
)
|
||||
pagination = Pagination(data=people_list)
|
||||
pagination.change(**list_options.model_dump())
|
||||
pagination_result = PaginationResult(data=people_list, pagination=pagination, response_model=FlatTenantPeopleListPydantic)
|
||||
return EndpointResponse(message="MSG0003-LIST", pagination_result=pagination_result).response
|
||||
|
||||
|
||||
FlatTenantPeopleListEvent.event_callable = flat_tenant_people_list_callable
|
||||
Reference in New Issue
Block a user