auth service up running

This commit is contained in:
berkay 2025-01-10 14:15:35 +03:00
parent 4eb95e4d9c
commit 03accfed1b
23 changed files with 457 additions and 317 deletions

View File

@ -30,19 +30,16 @@ class ActionsSchema(ABC):
Raises: Raises:
HTTPException: If endpoint is not found in database HTTPException: If endpoint is not found in database
""" """
from databases import EndpointRestriction # Temporarily return a dummy response to skip endpoint restriction checks
return {
endpoint_restriction = EndpointRestriction.filter_one( "endpoint_name": self.endpoint,
EndpointRestriction.endpoint_name.ilike(f"%{self.endpoint}%"), "endpoint_function": "dummy_function",
system=True "endpoint_method": "GET",
).data "endpoint_desc": "Temporary endpoint",
"endpoint_code": "dummy_code",
if not endpoint_restriction: "id": 1,
raise HTTPException( "uu_id": "dummy_uuid"
status_code=status.HTTP_404_NOT_FOUND, }
detail=f"Endpoint {self.endpoint} not found in the database"
)
return endpoint_restriction
class ActionsSchemaFactory: class ActionsSchemaFactory:

View File

@ -6,16 +6,11 @@ from api_validations.validations_request import (
UpdateAccountRecord, UpdateAccountRecord,
ListOptions, ListOptions,
) )
from ApiServices.api_handlers import AlchemyJsonResponse from ApiServices.api_handlers import AlchemyJsonResponse
from api_events.events.abstract_class import MethodToEvent, ActionsSchema from api_events.events.abstract_class import MethodToEvent, ActionsSchema
from api_objects.auth.token_objects import EmployeeTokenObject, OccupantTokenObject from api_objects.auth.token_objects import EmployeeTokenObject, OccupantTokenObject
from api_validations.validations_response.account import AccountListResponse from api_validations.validations_response import AccountRecordResponse
from api_validations.validations_response.account_responses import AccountRecordsListResponse from databases import AccountRecords, BuildIbans
from databases import (
AccountRecords,
BuildIbans,
)
from databases.sql_models.building.build import BuildLivingSpace from databases.sql_models.building.build import BuildLivingSpace
from databases.sql_models.building.decision_book import BuildDecisionBookPayments from databases.sql_models.building.decision_book import BuildDecisionBookPayments
from databases.sql_models.others.enums import ApiEnumDropdown from databases.sql_models.others.enums import ApiEnumDropdown
@ -32,8 +27,8 @@ class AccountRecordsListEventMethods(MethodToEvent):
"208e6273-17ef-44f0-814a-8098f816b63a": "account_records_list_flt_res", "208e6273-17ef-44f0-814a-8098f816b63a": "account_records_list_flt_res",
} }
__event_validation__ = { __event_validation__ = {
"7192c2aa-5352-4e36-98b3-dafb7d036a3d": AccountRecordsListResponse, "7192c2aa-5352-4e36-98b3-dafb7d036a3d": AccountRecordResponse,
"208e6273-17ef-44f0-814a-8098f816b63a": AccountRecordsListResponse, "208e6273-17ef-44f0-814a-8098f816b63a": AccountRecordResponse,
} }
@classmethod @classmethod
@ -59,7 +54,7 @@ class AccountRecordsListEventMethods(MethodToEvent):
result=records, result=records,
cls_object=AccountRecords, cls_object=AccountRecords,
filter_attributes=list_options, filter_attributes=list_options,
response_model=AccountRecordsListResponse response_model=AccountRecordResponse
) )
@classmethod @classmethod

View File

@ -1,17 +1,22 @@
from typing import Union from typing import Union, Dict, Any, List
from fastapi.exceptions import HTTPException from fastapi import status
from fastapi.responses import JSONResponse from fastapi.responses import JSONResponse
from api_validations.validations_response.address import ( from api_validations.validations_response import (
ListAddressResponse, ListAddressResponse,
AddressPostCodeResponse, AddressPostCodeResponse,
) )
from databases import ( from databases import (
AddressPostcode, AddressDistrict,
Addresses, AddressCity,
RelationshipEmployee2PostCode, AddressCountry,
AddressStreet, AddressStreet,
AddressNeighborhood,
AddressPostcode,
# AddressCountryCode,
RelationshipEmployee2PostCode,
Addresses,
) )
from api_validations.validations_request import ( from api_validations.validations_request import (

View File

@ -33,7 +33,7 @@ from api_validations.validations_request import (
EmployeeSelection, EmployeeSelection,
) )
from api_validations.validations_response.auth_responses import ( from api_validations.validations_response import (
AuthenticationLoginResponse, AuthenticationLoginResponse,
AuthenticationRefreshResponse, AuthenticationRefreshResponse,
AuthenticationUserInfoResponse AuthenticationUserInfoResponse

View File

@ -2,7 +2,6 @@ import typing
from typing import Union from typing import Union
from fastapi import status, HTTPException from fastapi import status, HTTPException
from fastapi.responses import JSONResponse
from databases import ( from databases import (
Build, Build,
@ -19,8 +18,7 @@ from api_validations.validations_request import (
PatchRecord, PatchRecord,
ListOptions, ListOptions,
) )
from api_validations.validations_response import ListBuildingResponse from api_validations.validations_response import BuildResponse
from ApiServices.api_handlers import AlchemyJsonResponse from ApiServices.api_handlers import AlchemyJsonResponse
from api_events.events.abstract_class import MethodToEvent, ActionsSchema from api_events.events.abstract_class import MethodToEvent, ActionsSchema
from api_objects.auth.token_objects import EmployeeTokenObject, OccupantTokenObject from api_objects.auth.token_objects import EmployeeTokenObject, OccupantTokenObject
@ -36,7 +34,7 @@ class BuildListEventMethods(MethodToEvent):
"68b3b5ed-b74c-4a27-820f-3959214e94e9": "build_list", "68b3b5ed-b74c-4a27-820f-3959214e94e9": "build_list",
} }
__event_validation__ = { __event_validation__ = {
"68b3b5ed-b74c-4a27-820f-3959214e94e9": ListBuildingResponse, "68b3b5ed-b74c-4a27-820f-3959214e94e9": BuildResponse,
} }
@classmethod @classmethod
@ -59,6 +57,9 @@ class BuildListEventMethods(MethodToEvent):
completed=True, completed=True,
message="Building records listed successfully", message="Building records listed successfully",
result=records, result=records,
cls_object=Build,
filter_attributes=list_options,
response_model=BuildResponse
) )

View File

@ -11,7 +11,7 @@ from api_validations.validations_request import (
ListOptions, ListOptions,
) )
from api_validations.validations_response.building_responses import BuildAreaListResponse from api_validations.validations_response import BuildResponse, BuildAreaResponse
from ApiServices.api_handlers import AlchemyJsonResponse from ApiServices.api_handlers import AlchemyJsonResponse
from api_events.events.abstract_class import MethodToEvent, ActionsSchema from api_events.events.abstract_class import MethodToEvent, ActionsSchema
@ -25,7 +25,7 @@ class BuildAreaListEventMethods(MethodToEvent):
"0bb51845-65a2-4340-8872-a3b5aad95468": "build_area_list", "0bb51845-65a2-4340-8872-a3b5aad95468": "build_area_list",
} }
__event_validation__ = { __event_validation__ = {
"0bb51845-65a2-4340-8872-a3b5aad95468": BuildAreaListResponse, "0bb51845-65a2-4340-8872-a3b5aad95468": BuildAreaResponse,
} }
@classmethod @classmethod
@ -56,7 +56,7 @@ class BuildAreaListEventMethods(MethodToEvent):
result=records, result=records,
cls_object=BuildArea, cls_object=BuildArea,
filter_attributes=list_options, filter_attributes=list_options,
response_model=BuildAreaListResponse response_model=BuildResponse
) )

View File

@ -1,23 +1,18 @@
from typing import Union from typing import Union
from fastapi.responses import JSONResponse from ApiServices.api_handlers import AlchemyJsonResponse
from fastapi import status from api_validations.validations_response import BuildPartsListResponse
from api_validations.validations_response.parts import BuildPartsListResponse
from databases import (
Build,
BuildParts,
)
from api_events.events.abstract_class import MethodToEvent, ActionsSchema from api_events.events.abstract_class import MethodToEvent, ActionsSchema
from api_objects.auth.token_objects import EmployeeTokenObject, OccupantTokenObject from api_objects.auth.token_objects import EmployeeTokenObject, OccupantTokenObject
from ApiServices.api_handlers import AlchemyJsonResponse
from api_validations.validations_request import ( from api_validations.validations_request import (
InsertBuildParts, InsertBuildParts,
UpdateBuildParts, UpdateBuildParts,
ListOptions, ListOptions,
) )
from databases import (
Build,
BuildParts,
)
class BuildingBuildPartsListEventMethods(MethodToEvent): class BuildingBuildPartsListEventMethods(MethodToEvent):
@ -48,6 +43,9 @@ class BuildingBuildPartsListEventMethods(MethodToEvent):
completed=True, completed=True,
message="Building parts listed successfully", message="Building parts listed successfully",
result=records, result=records,
cls_object=BuildParts,
filter_attributes=list_options,
response_model=BuildPartsListResponse,
) )

View File

@ -11,7 +11,7 @@ from api_validations.validations_request import (
ListOptions, ListOptions,
) )
from api_validations.validations_response.building_responses import BuildSitesListResponse from api_validations.validations_response import BuildSitesResponse
from ApiServices.api_handlers import AlchemyJsonResponse from ApiServices.api_handlers import AlchemyJsonResponse
from api_events.events.abstract_class import MethodToEvent, ActionsSchema from api_events.events.abstract_class import MethodToEvent, ActionsSchema
@ -25,7 +25,7 @@ class BuildSitesListEventMethods(MethodToEvent):
"6798414c-6c7d-47f0-9d8b-6935a0f51c2e": "build_sites_list", "6798414c-6c7d-47f0-9d8b-6935a0f51c2e": "build_sites_list",
} }
__event_validation__ = { __event_validation__ = {
"6798414c-6c7d-47f0-9d8b-6935a0f51c2e": BuildSitesListResponse, "6798414c-6c7d-47f0-9d8b-6935a0f51c2e": BuildSitesResponse,
} }
@classmethod @classmethod
@ -64,7 +64,7 @@ class BuildSitesListEventMethods(MethodToEvent):
result=records, result=records,
cls_object=BuildSites, cls_object=BuildSites,
filter_attributes=list_options, filter_attributes=list_options,
response_model=BuildSitesListResponse response_model=BuildSitesResponse
) )

View File

@ -6,7 +6,7 @@ from ApiServices.api_handlers import AlchemyJsonResponse
from api_validations.validations_request import ( from api_validations.validations_request import (
ListOptions, ListOptions,
) )
from api_validations.validations_response.building_responses import BuildTypesListResponse from api_validations.validations_response import BuildTypesResponse
from databases.sql_models.building.build import BuildTypes from databases.sql_models.building.build import BuildTypes
@ -17,7 +17,7 @@ class BuildTypesListEventMethods(MethodToEvent):
"5344d03c-fc47-43ec-8c44-6c2acd7e5d9f": "build_types_list", "5344d03c-fc47-43ec-8c44-6c2acd7e5d9f": "build_types_list",
} }
__event_validation__ = { __event_validation__ = {
"5344d03c-fc47-43ec-8c44-6c2acd7e5d9f": BuildTypesListResponse "5344d03c-fc47-43ec-8c44-6c2acd7e5d9f": BuildTypesResponse
} }
@classmethod @classmethod
@ -43,13 +43,10 @@ class BuildTypesListEventMethods(MethodToEvent):
return AlchemyJsonResponse( return AlchemyJsonResponse(
completed=False, completed=False,
message="You are not authorized to access this endpoint", message="You are not authorized to access this endpoint",
result=None result=None,
) cls_object=BuildTypes,
else: filter_attributes=list_options,
return AlchemyJsonResponse( response_model=BuildTypesResponse
completed=False,
message="You are not authorized to access this endpoint",
result=None
) )

View File

@ -19,7 +19,7 @@ from api_validations.validations_request import (
UpdateBuildLivingSpace, UpdateBuildLivingSpace,
ListOptions, ListOptions,
) )
from api_validations.validations_response.living_space import LivingSpaceListResponse from api_validations.validations_response import LivingSpaceListResponse
from databases.sql_models.event.event import Services from databases.sql_models.event.event import Services
@ -108,7 +108,10 @@ class BuildingLivingSpacesListEventMethods(MethodToEvent):
return AlchemyJsonResponse( return AlchemyJsonResponse(
completed=True, completed=True,
message="Living spaces listed successfully", message="Living spaces listed successfully",
result=records result=records,
cls_object=BuildLivingSpace,
filter_attributes=list_options,
response_model=LivingSpaceListResponse,
) )

View File

@ -12,7 +12,7 @@ from api_validations.validations_request import (
PatchRecord, PatchRecord,
) )
from api_validations.validations_response.company_responses import CompanyListResponse from api_validations.validations_response import CompanyListResponse
from api_events.events.abstract_class import MethodToEvent, ActionsSchema from api_events.events.abstract_class import MethodToEvent, ActionsSchema
from api_objects.auth.token_objects import EmployeeTokenObject, OccupantTokenObject from api_objects.auth.token_objects import EmployeeTokenObject, OccupantTokenObject
@ -52,7 +52,7 @@ class CompanyListEventMethods(MethodToEvent):
result=records, result=records,
cls_object=Companies, cls_object=Companies,
filter_attributes=list_options, filter_attributes=list_options,
response_model=CompanyListResponse response_model=CompanyListResponse,
) )

View File

@ -1,6 +1,6 @@
from typing import Union from typing import Union
from api_validations.validations_response.parts import BuildPartsListResponse from api_validations.validations_response import BuildPartsListResponse
from databases import ( from databases import (
BuildParts, BuildParts,
) )

View File

@ -3,7 +3,7 @@ from typing import Union
from fastapi import status from fastapi import status
from fastapi.responses import JSONResponse from fastapi.responses import JSONResponse
from api_validations.validations_response.people import PeopleListResponse from api_validations.validations_response import PeopleListResponse
from databases import ( from databases import (
People, People,
Users, Users,

View File

@ -1,5 +1,119 @@
from .building import ListBuildingResponse from .building_responses import (
BuildResponse,
BuildLivingSpaceResponse,
BuildLivingSpaceCollection,
BuildAreaResponse,
BuildAreaCollection,
BuildTypesResponse,
BuildTypesCollection,
BuildPartsResponse,
BuildPartsCollection,
BuildSitesResponse,
BuildSitesCollection,
Part2EmployeeResponse,
Part2EmployeeCollection,
BuildPersonProvidingResponse,
BuildPersonProvidingCollection,
RelationshipEmployee2BuildResponse,
RelationshipEmployee2BuildCollection,
BuildCompaniesProvidingResponse,
BuildCompaniesProvidingCollection,
BuildManagementResponse,
BuildManagementCollection
)
from .account_responses import (
AccountRecordResponse,
AccountRecordCollection,
AccountRecordExchangeResponse,
AccountRecordExchangeCollection
)
from .address_responses import ListAddressResponse, AddressPostCodeResponse
from .auth_responses import (
AuthenticationLoginResponse,
AuthenticationRefreshResponse,
AuthenticationUserInfoResponse
)
from .base_responses import BaseResponse, CrudCollection
from .budget_responses import (
DecisionBookBudgetBooksResponse,
DecisionBookBudgetBooksCollection,
DecisionBookBudgetCodesResponse,
DecisionBookBudgetCodesCollection,
DecisionBookBudgetMasterResponse,
DecisionBookBudgetMasterCollection,
DecisionBookBudgetsResponse,
DecisionBookBudgetsCollection
)
from .company_responses import (
CompanyListResponse,
CompanyDepartmentListResponse,
CompanyDutyListResponse,
CompanyEmployeeListResponse
)
from .decision_book_responses import (
BuildDecisionBookResponse,
BuildDecisionBookCollection,
BuildDecisionBookInvitationsResponse,
BuildDecisionBookInvitationsCollection,
BuildDecisionBookPersonResponse,
BuildDecisionBookPersonCollection,
BuildDecisionBookPersonOccupantsResponse,
BuildDecisionBookPersonOccupantsCollection,
BuildDecisionBookItemsResponse,
BuildDecisionBookItemsCollection,
BuildDecisionBookItemsUnapprovedResponse,
BuildDecisionBookItemsUnapprovedCollection,
BuildDecisionBookPaymentsResponse,
BuildDecisionBookPaymentsCollection,
BuildDecisionBookLegalResponse,
BuildDecisionBookLegalCollection
)
from .living_space_responses import LivingSpaceListResponse
from .parts_responses import BuildPartsListResponse
from .people_responses import PeopleListResponse
__all__ = [ __all__ = [
"ListBuildingResponse", "BuildResponse",
"AccountRecordResponse",
"AccountRecordCollection",
"AccountRecordExchangeResponse",
"AccountRecordExchangeCollection",
"ListAddressResponse",
"AddressPostCodeResponse",
"AuthenticationLoginResponse",
"AuthenticationRefreshResponse",
"AuthenticationUserInfoResponse",
"BaseResponse",
"CrudCollection",
"DecisionBookBudgetBooksResponse",
"DecisionBookBudgetBooksCollection",
"DecisionBookBudgetCodesResponse",
"DecisionBookBudgetCodesCollection",
"DecisionBookBudgetMasterResponse",
"DecisionBookBudgetMasterCollection",
"DecisionBookBudgetsResponse",
"DecisionBookBudgetsCollection",
"CompanyListResponse",
"CompanyDepartmentListResponse",
"CompanyDutyListResponse",
"CompanyEmployeeListResponse",
"BuildDecisionBookResponse",
"BuildDecisionBookCollection",
"BuildDecisionBookInvitationsResponse",
"BuildDecisionBookInvitationsCollection",
"BuildDecisionBookPersonResponse",
"BuildDecisionBookPersonCollection",
"BuildDecisionBookPersonOccupantsResponse",
"BuildDecisionBookPersonOccupantsCollection",
"BuildDecisionBookItemsResponse",
"BuildDecisionBookItemsCollection",
"BuildDecisionBookItemsUnapprovedResponse",
"BuildDecisionBookItemsUnapprovedCollection",
"BuildDecisionBookPaymentsResponse",
"BuildDecisionBookPaymentsCollection",
"BuildDecisionBookLegalResponse",
"BuildDecisionBookLegalCollection",
"LivingSpaceListResponse",
"BuildPartsListResponse",
"PeopleListResponse"
] ]

View File

@ -164,7 +164,48 @@ class AccountDetailCollection(CrudCollection[AccountDetailResponse]):
class AccountRecordResponse(BaseResponse): class AccountRecordResponse(BaseResponse):
"""Response model for account records""" """Response model for account financial records.
This model represents a financial transaction record in the system,
including bank transaction details, amounts, and related metadata.
Attributes:
iban (str): International Bank Account Number
bank_date (datetime): Date when the transaction occurred at the bank
currency_value (Decimal): Original transaction amount
bank_balance (Decimal): Account balance after the transaction
currency (str): Currency code (e.g., "TRY", "USD")
additional_balance (Decimal): Any additional balance adjustments
channel_branch (str): Bank branch or channel where transaction occurred
process_name (str): Name/type of the transaction
process_type (str): Classification of the transaction
process_comment (str): Additional transaction details or notes
bank_reference_code (str): Bank's reference code for the transaction
add_comment_note (Optional[str]): Additional internal notes
is_receipt_mail_send (Optional[bool]): Whether receipt was emailed
found_from (Optional[str]): Source of the transaction record
similarity (Optional[float]): Matching confidence for duplicate detection
remainder_balance (Optional[Decimal]): Remaining balance if partial
bank_date_y (Optional[int]): Year of bank transaction
bank_date_m (Optional[int]): Month of bank transaction
bank_date_w (Optional[int]): Week of bank transaction
bank_date_d (Optional[int]): Day of bank transaction
approving_accounting_record (Optional[bool]): Accounting approval status
accounting_receipt_date (Optional[datetime]): When receipt was processed
accounting_receipt_number (Optional[int]): Receipt reference number
approved_record (Optional[bool]): Whether record is approved
import_file_name (Optional[str]): Source file if imported
receive_debit_uu_id (Optional[str]): Related debit record ID
budget_type_uu_id (Optional[str]): Associated budget type ID
company_uu_id (Optional[str]): Associated company ID
send_company_uu_id (Optional[str]): Sending company ID
customer_id (Optional[str]): Associated customer ID
customer_uu_id (Optional[str]): Associated customer UUID
send_person_uu_id (Optional[str]): Sending person ID
approving_accounting_person_uu_id (Optional[str]): Approver ID
build_parts_uu_id (Optional[str]): Related building part ID
build_decision_book_uu_id (Optional[str]): Related decision book ID
"""
iban: str iban: str
bank_date: datetime bank_date: datetime
currency_value: Decimal currency_value: Decimal
@ -203,12 +244,28 @@ class AccountRecordResponse(BaseResponse):
class AccountRecordCollection(CrudCollection[AccountRecordResponse]): class AccountRecordCollection(CrudCollection[AccountRecordResponse]):
"""Collection of account records""" """Collection of account financial records.
This model represents a paginated list of account records with
sorting and pagination information.
"""
pass pass
class AccountRecordExchangeResponse(BaseResponse): class AccountRecordExchangeResponse(BaseResponse):
"""Response model for account record exchanges""" """Response model for currency exchange records.
This model represents a currency exchange transaction, tracking
exchange rates and converted amounts for financial records.
Attributes:
account_record_id (int): ID of the related account record
account_record_uu_id (str): UUID of the related account record
exchange_rate (Decimal): Applied exchange rate
exchange_currency (str): Target currency code
exchange_value (Decimal): Converted amount
exchange_date (datetime): When the exchange was calculated
"""
account_record_id: int account_record_id: int
account_record_uu_id: str account_record_uu_id: str
exchange_rate: Decimal exchange_rate: Decimal
@ -218,7 +275,11 @@ class AccountRecordExchangeResponse(BaseResponse):
class AccountRecordExchangeCollection(CrudCollection[AccountRecordExchangeResponse]): class AccountRecordExchangeCollection(CrudCollection[AccountRecordExchangeResponse]):
"""Collection of account record exchanges""" """Collection of currency exchange records.
This model represents a paginated list of currency exchange records
with sorting and pagination information.
"""
pass pass

View File

@ -6,7 +6,27 @@ from uuid import UUID
T = TypeVar('T') T = TypeVar('T')
class BaseResponse(BaseModel): class BaseResponse(BaseModel):
"""Base response model that all other response models inherit from""" """Base response model that all response models inherit from.
This model provides common fields that are present in all database records,
including tracking information (created/updated timestamps), user actions
(created by, updated by, confirmed by), and record status (active, deleted).
Attributes:
uu_id (str): Unique identifier for the record, typically a UUID
created_at (datetime): Timestamp when the record was created
updated_at (Optional[datetime]): Timestamp when the record was last updated
created_by (Optional[str]): Username or identifier of the user who created the record
updated_by (Optional[str]): Username or identifier of the user who last updated the record
confirmed_by (Optional[str]): Username or identifier of the user who confirmed the record
is_confirmed (Optional[bool]): Whether the record has been confirmed/approved
active (Optional[bool]): Whether the record is currently active
deleted (Optional[bool]): Whether the record has been marked as deleted
expiry_starts (Optional[datetime]): When the record becomes valid/active
expiry_ends (Optional[datetime]): When the record expires/becomes inactive
is_notification_send (Optional[bool]): Whether notifications have been sent for this record
is_email_send (Optional[bool]): Whether emails have been sent for this record
"""
uu_id: str uu_id: str
created_at: datetime created_at: datetime
updated_at: Optional[datetime] updated_at: Optional[datetime]
@ -22,11 +42,48 @@ class BaseResponse(BaseModel):
is_email_send: Optional[bool] = False is_email_send: Optional[bool] = False
class Config: class Config:
"""Pydantic configuration for the base response model.
Attributes:
from_attributes (bool): Enables ORM mode for SQLAlchemy integration
"""
from_attributes = True from_attributes = True
class CrudCollection(BaseModel, Generic[T]): class CrudCollection(BaseModel, Generic[T]):
"""Base collection model for paginated responses""" """Base collection model for paginated responses.
This model is used to return collections of items with pagination information.
It is generic over the type of items in the collection, allowing it to be
used with any response model.
Type Parameters:
T: The type of items in the collection
Attributes:
page (int): Current page number, 1-based indexing
size (int): Number of items per page
total (int): Total number of items across all pages
order_field (str): Field used for sorting the collection
order_type (str): Sort direction ('asc' or 'desc')
items (List[T]): List of items in the current page
Example:
```python
class UserResponse(BaseResponse):
name: str
email: str
users = CrudCollection[UserResponse](
page=1,
size=10,
total=100,
order_field="name",
order_type="asc",
items=[...]
)
```
"""
page: int = 1 page: int = 1
size: int = 10 size: int = 10
total: int = 0 total: int = 0
@ -35,4 +92,9 @@ class CrudCollection(BaseModel, Generic[T]):
items: List[T] = [] items: List[T] = []
class Config: class Config:
"""Pydantic configuration for the collection model.
Attributes:
from_attributes (bool): Enables ORM mode for SQLAlchemy integration
"""
from_attributes = True from_attributes = True

View File

@ -1,24 +1,30 @@
from datetime import datetime
from typing import Optional, List, Union
from sqlalchemy.orm import mapped_column, Mapped from sqlalchemy.orm import mapped_column, Mapped
from sqlalchemy import ( from sqlalchemy import (
String, String,
Integer, Integer,
Boolean,
ForeignKey, ForeignKey,
Index, Index,
SmallInteger,
Boolean,
TIMESTAMP, TIMESTAMP,
func,
Text,
BigInteger,
Numeric, Numeric,
UUID, SmallInteger,
) )
from databases.sql_models.core_mixin import CrudCollection from databases.sql_models.core_mixin import CrudCollection
from databases.language_models import ( from databases.language_models.account.account import (
AccountBooksLanguageModel, AccountBooksLanguageModel,
AccountDetailLanguageModel,
AccountMasterLanguageModel,
AccountRecordExchangesLanguageModel,
AccountCodesLanguageModel, AccountCodesLanguageModel,
AccountRecordsLanguageModel, AccountRecordsLanguageModel,
AccountRecordExchangesLanguageModel,
AccountDetailLanguageModel,
AccountCodeParserLanguageModel, AccountCodeParserLanguageModel,
AccountMasterLanguageModel,
) )
@ -29,7 +35,7 @@ class AccountBooks(CrudCollection):
__language_model__ = AccountBooksLanguageModel __language_model__ = AccountBooksLanguageModel
country: Mapped[str] = mapped_column(String, nullable=False) country: Mapped[str] = mapped_column(String, nullable=False)
branch_type: Mapped[str] = mapped_column(SmallInteger, server_default="0") branch_type: Mapped[int] = mapped_column(SmallInteger, server_default="0")
company_id: Mapped[int] = mapped_column(ForeignKey("companies.id"), nullable=False) company_id: Mapped[int] = mapped_column(ForeignKey("companies.id"), nullable=False)
company_uu_id: Mapped[str] = mapped_column(String, nullable=False) company_uu_id: Mapped[str] = mapped_column(String, nullable=False)
@ -79,7 +85,7 @@ class AccountCodes(CrudCollection):
account_code_seperator: Mapped[str] = mapped_column(String(1), server_default=".") account_code_seperator: Mapped[str] = mapped_column(String(1), server_default=".")
system_id: Mapped[int] = mapped_column(SmallInteger, server_default="0") system_id: Mapped[int] = mapped_column(SmallInteger, server_default="0")
locked: Mapped[bool] = mapped_column(SmallInteger, server_default="0") locked: Mapped[int] = mapped_column(SmallInteger, server_default="0")
company_id: Mapped[int] = mapped_column(ForeignKey("companies.id")) company_id: Mapped[int] = mapped_column(ForeignKey("companies.id"))
company_uu_id: Mapped[str] = mapped_column( company_uu_id: Mapped[str] = mapped_column(
@ -120,7 +126,7 @@ class AccountCodeParser(CrudCollection):
__tablename__ = "account_code_parser" __tablename__ = "account_code_parser"
__exclude__fields__ = [] __exclude__fields__ = []
__language_model__ = AccountCodeParserLanguageModel __language_model__ = AccountCodesLanguageModel
account_code_1: Mapped[str] = mapped_column(String, nullable=False, comment="Order") account_code_1: Mapped[str] = mapped_column(String, nullable=False, comment="Order")
account_code_2: Mapped[str] = mapped_column(String, nullable=False, comment="Order") account_code_2: Mapped[str] = mapped_column(String, nullable=False, comment="Order")
@ -297,7 +303,7 @@ class AccountDetail(CrudCollection):
canceled: Mapped[int] = mapped_column(SmallInteger, server_default="0") canceled: Mapped[int] = mapped_column(SmallInteger, server_default="0")
cross_ref: Mapped[int] = mapped_column(Integer, server_default="0") cross_ref: Mapped[int] = mapped_column(Integer, server_default="0")
data_center_id: Mapped[str] = mapped_column(String, server_default="") data_center_id: Mapped[str] = mapped_column(String, server_default="")
data_center_rec_num: Mapped[str] = mapped_column(Integer, server_default="0") data_center_rec_num: Mapped[int] = mapped_column(Integer, server_default="0")
status_id: Mapped[int] = mapped_column(SmallInteger, server_default="0") status_id: Mapped[int] = mapped_column(SmallInteger, server_default="0")
plug_type_id: Mapped[int] = mapped_column( plug_type_id: Mapped[int] = mapped_column(
@ -728,7 +734,6 @@ class AccountRecords(CrudCollection):
# ), # ),
# {"comment": "Account Record Decision Payment Closed Information"}, # {"comment": "Account Record Decision Payment Closed Information"},
# ) # )
#
class AccountRecordExchanges(CrudCollection): class AccountRecordExchanges(CrudCollection):

View File

@ -1,35 +1,45 @@
import typing
from operator import or_
from datetime import datetime, timedelta from datetime import datetime, timedelta
from platform import system from typing import List, Optional, Union
from typing import List
from fastapi import HTTPException, status from fastapi import HTTPException, status
from sqlalchemy.orm import mapped_column, relationship, Mapped from sqlalchemy.orm import mapped_column, relationship, Mapped
from sqlalchemy import ( from sqlalchemy import (
String, String,
Integer, Integer,
Boolean,
ForeignKey, ForeignKey,
Index, Index,
SmallInteger,
Boolean,
TIMESTAMP, TIMESTAMP,
func,
Text, Text,
Numeric, Numeric,
or_,
) )
from api_library.date_time_actions.date_functions import system_arrow from api_library.date_time_actions.date_functions import system_arrow
from databases.sql_models.core_mixin import CrudCollection from databases.sql_models.core_mixin import CrudCollection
from databases.extensions.selector_classes import SelectActionWithEmployee from databases.extensions.selector_classes import SelectActionWithEmployee
from api_validations.validations_request import ( from api_validations.validations_request import (
InsertBuildParts,
InsertBuild, InsertBuild,
InsertBuildParts,
InsertBuildLivingSpace,
UpdateBuild, UpdateBuild,
) )
from api_objects.auth.token_objects import EmployeeTokenObject, OccupantTokenObject from api_objects.auth.token_objects import EmployeeTokenObject, OccupantTokenObject
from databases.language_models.building.build import (
BuildTypesLanguageModel,
Part2EmployeeLanguageModel,
BuildPartsLanguageModel,
BuildSitesLanguageModel,
RelationshipEmployee2BuildLanguageModel,
BuildLanguageModel,
BuildPartsLanguageModel,
BuildLivingSpaceLanguageModel,
BuildManagementLanguageModel,
BuildAreaLanguageModel,
BuildCompaniesProvidingLanguageModel,
BuildPersonProvidingLanguageModel,
)
class BuildTypes(CrudCollection): class BuildTypes(CrudCollection):
""" """
@ -39,6 +49,7 @@ class BuildTypes(CrudCollection):
__tablename__ = "build_types" __tablename__ = "build_types"
__exclude__fields__ = [] __exclude__fields__ = []
__language_model__ = BuildTypesLanguageModel
__include__fields__ = [] __include__fields__ = []
function_code: Mapped[str] = mapped_column( function_code: Mapped[str] = mapped_column(
@ -68,6 +79,7 @@ class Part2Employee(CrudCollection):
__tablename__ = "part2employee" __tablename__ = "part2employee"
__exclude__fields__ = [] __exclude__fields__ = []
__language_model__ = Part2EmployeeLanguageModel
__include__fields__ = [] __include__fields__ = []
build_id: Mapped[int] = mapped_column(Integer, comment="Building ID") build_id: Mapped[int] = mapped_column(Integer, comment="Building ID")
@ -93,6 +105,7 @@ class RelationshipEmployee2Build(CrudCollection):
__tablename__ = "relationship_employee2build" __tablename__ = "relationship_employee2build"
__exclude__fields__ = [] __exclude__fields__ = []
__language_model__ = RelationshipEmployee2BuildLanguageModel
company_id: Mapped[int] = mapped_column( company_id: Mapped[int] = mapped_column(
ForeignKey("companies.id"), nullable=False ForeignKey("companies.id"), nullable=False
@ -129,6 +142,7 @@ class Build(CrudCollection, SelectActionWithEmployee):
__tablename__ = "build" __tablename__ = "build"
__exclude__fields__ = [] __exclude__fields__ = []
__language_model__ = BuildLanguageModel
__include__fields__ = [] __include__fields__ = []
__access_by__ = [] __access_by__ = []
__many__table__ = RelationshipEmployee2Build __many__table__ = RelationshipEmployee2Build
@ -145,10 +159,10 @@ class Build(CrudCollection, SelectActionWithEmployee):
) )
max_floor: Mapped[int] = mapped_column( max_floor: Mapped[int] = mapped_column(
SmallInteger, server_default="1", nullable=False, comment="Max Floor" Integer, server_default="1", nullable=False, comment="Max Floor"
) )
underground_floor: Mapped[int] = mapped_column( underground_floor: Mapped[int] = mapped_column(
SmallInteger, server_default="0", nullable=False, comment="Underground Floor" Integer, server_default="0", nullable=False, comment="Underground Floor"
) )
build_date: Mapped[TIMESTAMP] = mapped_column( build_date: Mapped[TIMESTAMP] = mapped_column(
TIMESTAMP(timezone=True), server_default="1900-01-01" TIMESTAMP(timezone=True), server_default="1900-01-01"
@ -159,18 +173,18 @@ class Build(CrudCollection, SelectActionWithEmployee):
comment="Building annual ordinary meeting period", comment="Building annual ordinary meeting period",
) )
tax_no: Mapped[str] = mapped_column(String(24), server_default="") tax_no: Mapped[str] = mapped_column(String(24), server_default="")
lift_count: Mapped[int] = mapped_column(SmallInteger, server_default="0") lift_count: Mapped[int] = mapped_column(Integer, server_default="0")
heating_system: Mapped[bool] = mapped_column(Boolean, server_default="True") heating_system: Mapped[bool] = mapped_column(Boolean, server_default="True")
cooling_system: Mapped[bool] = mapped_column(Boolean, server_default="False") cooling_system: Mapped[bool] = mapped_column(Boolean, server_default="False")
hot_water_system: Mapped[bool] = mapped_column(Boolean, server_default="False") hot_water_system: Mapped[bool] = mapped_column(Boolean, server_default="False")
block_service_man_count: Mapped[int] = mapped_column( block_service_man_count: Mapped[int] = mapped_column(
SmallInteger, server_default="0" Integer, server_default="0"
) )
security_service_man_count: Mapped[int] = mapped_column( security_service_man_count: Mapped[int] = mapped_column(
SmallInteger, server_default="0" Integer, server_default="0"
) )
garage_count: Mapped[int] = mapped_column( garage_count: Mapped[int] = mapped_column(
SmallInteger, server_default="0", comment="Garage Count" Integer, server_default="0", comment="Garage Count"
) )
management_room_id: Mapped[int] = mapped_column( management_room_id: Mapped[int] = mapped_column(
Integer, nullable=True, comment="Management Room ID" Integer, nullable=True, comment="Management Room ID"
@ -290,7 +304,7 @@ class Build(CrudCollection, SelectActionWithEmployee):
def top_flat(self): def top_flat(self):
max_flat_no = 0 max_flat_no = 0
for part in self.parts: for part in self.parts:
if part.part_no > self.max_flat_no: if part.part_no > self.max_floor:
max_flat_no = part.part_no max_flat_no = part.part_no
return max_flat_no return max_flat_no
@ -298,7 +312,7 @@ class Build(CrudCollection, SelectActionWithEmployee):
def bottom_flat(self): def bottom_flat(self):
min_flat_no = 0 min_flat_no = 0
for part in self.parts: for part in self.parts:
if part.part_no < self.max_flat_no: if part.part_no < self.max_floor:
min_flat_no = part.part_no min_flat_no = part.part_no
return min_flat_no return min_flat_no
@ -352,6 +366,7 @@ class BuildParts(CrudCollection):
__tablename__ = "build_parts" __tablename__ = "build_parts"
__exclude__fields__ = [] __exclude__fields__ = []
__language_model__ = BuildPartsLanguageModel
__include__fields__ = [] __include__fields__ = []
__enum_list__ = [("part_direction", "Directions", "NN")] __enum_list__ = [("part_direction", "Directions", "NN")]
@ -361,10 +376,10 @@ class BuildParts(CrudCollection):
) )
# part_name: Mapped[str] = mapped_column(String(24), server_default="", nullable=False, comment="Part Name") # part_name: Mapped[str] = mapped_column(String(24), server_default="", nullable=False, comment="Part Name")
part_no: Mapped[int] = mapped_column( part_no: Mapped[int] = mapped_column(
SmallInteger, server_default="0", nullable=False, comment="Part Number" Integer, server_default="0", nullable=False, comment="Part Number"
) )
part_level: Mapped[int] = mapped_column( part_level: Mapped[int] = mapped_column(
SmallInteger, server_default="0", comment="Building Part Level" Integer, server_default="0", comment="Building Part Level"
) )
part_code: Mapped[str] = mapped_column( part_code: Mapped[str] = mapped_column(
String, server_default="", nullable=False, comment="Part Code" String, server_default="", nullable=False, comment="Part Code"
@ -496,6 +511,7 @@ class BuildLivingSpace(CrudCollection):
__tablename__ = "build_living_space" __tablename__ = "build_living_space"
__exclude__fields__ = [] __exclude__fields__ = []
__language_model__ = BuildLivingSpaceLanguageModel
__include__fields__ = [] __include__fields__ = []
fix_value: Mapped[float] = mapped_column( fix_value: Mapped[float] = mapped_column(
@ -513,7 +529,7 @@ class BuildLivingSpace(CrudCollection):
String, server_default="", comment="Agreement No" String, server_default="", comment="Agreement No"
) )
marketing_process: Mapped[bool] = mapped_column(Boolean, server_default="False") marketing_process: Mapped[bool] = mapped_column(Boolean, server_default="False")
marketing_layer: Mapped[int] = mapped_column(SmallInteger, server_default="0") marketing_layer: Mapped[int] = mapped_column(Integer, server_default="0")
build_parts_id: Mapped[int] = mapped_column( build_parts_id: Mapped[int] = mapped_column(
ForeignKey("build_parts.id"), ForeignKey("build_parts.id"),
@ -550,7 +566,7 @@ class BuildLivingSpace(CrudCollection):
def create_action( def create_action(
cls, cls,
data: dict, data: dict,
token_dict: typing.Union[EmployeeTokenObject, OccupantTokenObject], token_dict: Union[EmployeeTokenObject, OccupantTokenObject],
): ):
from databases import Services, OccupantTypes from databases import Services, OccupantTypes
from api_events.events.events.events_bind_modules import ( from api_events.events.events.events_bind_modules import (
@ -601,6 +617,7 @@ class BuildManagement(CrudCollection):
__tablename__ = "build_management" __tablename__ = "build_management"
__exclude__fields__ = [] __exclude__fields__ = []
__language_model__ = BuildManagementLanguageModel
discounted_percentage: Mapped[float] = mapped_column( discounted_percentage: Mapped[float] = mapped_column(
Numeric(6, 2), server_default="0.00" Numeric(6, 2), server_default="0.00"
@ -655,6 +672,7 @@ class BuildArea(CrudCollection):
__tablename__ = "build_area" __tablename__ = "build_area"
__exclude__fields__ = [] __exclude__fields__ = []
__language_model__ = BuildAreaLanguageModel
area_name: Mapped[str] = mapped_column(String, server_default="") area_name: Mapped[str] = mapped_column(String, server_default="")
area_code: Mapped[str] = mapped_column(String, server_default="") area_code: Mapped[str] = mapped_column(String, server_default="")
@ -690,6 +708,7 @@ class BuildSites(CrudCollection):
__tablename__ = "build_sites" __tablename__ = "build_sites"
__exclude__fields__ = [] __exclude__fields__ = []
__language_model__ = BuildSitesLanguageModel
__include__fields__ = [] __include__fields__ = []
site_name: Mapped[str] = mapped_column(String(24), nullable=False) site_name: Mapped[str] = mapped_column(String(24), nullable=False)
@ -716,6 +735,7 @@ class BuildCompaniesProviding(CrudCollection):
__tablename__ = "build_companies_providing" __tablename__ = "build_companies_providing"
__exclude__fields__ = [] __exclude__fields__ = []
__language_model__ = BuildCompaniesProvidingLanguageModel
__include__fields__ = [] __include__fields__ = []
build_id = mapped_column( build_id = mapped_column(
@ -755,6 +775,7 @@ class BuildPersonProviding(CrudCollection):
__tablename__ = "build_person_providing" __tablename__ = "build_person_providing"
__exclude__fields__ = [] __exclude__fields__ = []
__language_model__ = BuildPersonProvidingLanguageModel
__include__fields__ = [] __include__fields__ = []
build_id = mapped_column( build_id = mapped_column(
@ -787,75 +808,3 @@ class BuildPersonProviding(CrudCollection):
), ),
{"comment": "People providing services for building"}, {"comment": "People providing services for building"},
) )
# owner_people: Mapped["People"] = relationship(
# "People",
# back_populates="owner_buildings",
# foreign_keys=[current_owner_person_id],
# )
# tenant_people: Mapped["People"] = relationship(
# "People",
# back_populates="tenant_buildings",
# foreign_keys=[current_tenant_person_id],
# )
# decision_book_management: Mapped[List["BuildDecisionBookManagement"]] = (
# relationship(
# "BuildDecisionBookManagement",
# back_populates="buildings",
# foreign_keys="BuildDecisionBookManagement.build_parts_id",
# )
# )
# budget_records: Mapped[List["CompanyBudgetRecords"]] = relationship(
# "CompanyBudgetRecords",
# back_populates="parts",
# foreign_keys="CompanyBudgetRecords.build_parts_id",
# )
# living_spaces: Mapped[List["BuildLivingSpace"]] = relationship(
# "BuildLivingSpace",
# back_populates="parts",
# foreign_keys="BuildLivingSpace.build_parts_id",
# )
# decision_book_payment_master: Mapped[List["BuildDecisionBookPaymentsMaster"]] = (
# relationship(
# "BuildDecisionBookPaymentsMaster",
# back_populates="parts",
# foreign_keys="BuildDecisionBookPaymentsMaster.build_parts_id",
# )
# )
# decision_book_project_payments_master: Mapped[
# "BuildDecisionBookProjectPaymentsMaster"
# ] = relationship(
# "BuildDecisionBookProjectPaymentsMaster",
# back_populates="parts",
# foreign_keys="BuildDecisionBookProjectPaymentsMaster.build_parts_id",
# )
# search_iban_description: Mapped["BuildIbanDescription"] = relationship(
# "BuildIbanDescription",
# back_populates="parts",
# foreign_keys="BuildIbanDescription.build_parts_id",
# )
# parts: Mapped[List["BuildParts"]] = relationship(
# "BuildParts", back_populates="living_spaces", foreign_keys=[build_parts_id]
# )
# owner_people: Mapped["People"] = relationship(
# "People", back_populates="owner_living_spaces", foreign_keys=[owner_person_id]
# )
# life_people: Mapped["People"] = relationship(
# "People", back_populates="life_living_spaces", foreign_keys=[life_person_id]
# )
# company_id: Mapped[int] = mapped_column(ForeignKey("companies.id"))
# response_company_id: Mapped[int] = mapped_column(ForeignKey("companies.id"))
# person_id: Mapped[int] = mapped_column(ForeignKey("people.id"))
# companies: Mapped["Companies"] = relationship(
# "Companies", back_populates="buildings", foreign_keys=[company_id]
# )
# @classmethod
# def select_action(cls, duty_id, token=None):
# from database_sql_models import Companies
#
# related_companies = Companies.select_action(duty_id=duty_id)
# companies_ids = [company.id for company in related_companies.all()]
# return cls.filter_all(cls.company_id.in_(companies_ids)).query

View File

@ -977,7 +977,7 @@ class BuildDecisionBookLegal(CrudCollection):
contact_agreement_date: Mapped[TIMESTAMP] = mapped_column( contact_agreement_date: Mapped[TIMESTAMP] = mapped_column(
TIMESTAMP(timezone=True), server_default="1900-01-01 00:00:00", nullable=True TIMESTAMP(timezone=True), server_default="1900-01-01 00:00:00", nullable=True
) )
meeting_date: Mapped[str] = mapped_column( meeting_date: Mapped[TIMESTAMP] = mapped_column(
TIMESTAMP(timezone=True), server_default="1900-01-01 00:00:00" TIMESTAMP(timezone=True), server_default="1900-01-01 00:00:00"
) )
lawsuits_type: Mapped[str] = mapped_column(String(1), server_default="C") lawsuits_type: Mapped[str] = mapped_column(String(1), server_default="C")

View File

@ -2,8 +2,8 @@ from fastapi.exceptions import HTTPException
from databases.sql_models.core_mixin import CrudCollection from databases.sql_models.core_mixin import CrudCollection
from sqlalchemy import String, Integer, Boolean, ForeignKey, Index, Identity from sqlalchemy import String, Integer, Boolean, ForeignKey, Index, Identity, TIMESTAMP, func
from sqlalchemy.orm import mapped_column, Mapped from sqlalchemy.orm import mapped_column, relationship, Mapped
from api_configs import RelationAccess from api_configs import RelationAccess
from databases.extensions import SelectAction from databases.extensions import SelectAction
@ -13,6 +13,11 @@ from api_validations.validations_request import (
MatchCompany2Company, MatchCompany2Company,
) )
from api_objects.auth.token_objects import EmployeeTokenObject from api_objects.auth.token_objects import EmployeeTokenObject
from databases.language_models.company.company import (
RelationshipDutyCompanyLanguageModel,
CompaniesLanguageModel,
# CompanyDutiesLanguageModel,
)
class RelationshipDutyCompany(CrudCollection): class RelationshipDutyCompany(CrudCollection):
@ -31,6 +36,7 @@ class RelationshipDutyCompany(CrudCollection):
__tablename__ = "relationship_duty_company" __tablename__ = "relationship_duty_company"
__exclude__fields__ = [] __exclude__fields__ = []
__access_by__ = RelationAccess.SuperAccessList __access_by__ = RelationAccess.SuperAccessList
__language_model__ = RelationshipDutyCompanyLanguageModel
owner_id: Mapped[int] = mapped_column( owner_id: Mapped[int] = mapped_column(
ForeignKey("companies.id"), nullable=False ForeignKey("companies.id"), nullable=False
@ -184,6 +190,7 @@ class Companies(CrudCollection, SelectAction):
__exclude__fields__ = ["is_blacklist", "is_commercial"] __exclude__fields__ = ["is_blacklist", "is_commercial"]
__access_by__ = [] __access_by__ = []
__many__table__ = RelationshipDutyCompany __many__table__ = RelationshipDutyCompany
__language_model__ = CompaniesLanguageModel
# __explain__ = AbstractCompany() # __explain__ = AbstractCompany()
formal_name: Mapped[str] = mapped_column( formal_name: Mapped[str] = mapped_column(

View File

@ -1,4 +1,15 @@
from databases.sql_models.core_mixin import CrudCollection from databases.sql_models.core_mixin import CrudCollection
from databases.language_models.event.event import (
EventsLanguageModel,
ModulesLanguageModel,
ServicesLanguageModel,
Service2EventsLanguageModel,
Event2OccupantExtraLanguageModel,
Event2EmployeeExtraLanguageModel,
Event2EmployeeLanguageModel,
Event2OccupantLanguageModel,
ModulePriceLanguageModel,
)
from sqlalchemy import ( from sqlalchemy import (
String, String,
@ -20,6 +31,7 @@ class Events(CrudCollection):
__tablename__ = "events" __tablename__ = "events"
__exclude__fields__ = [] __exclude__fields__ = []
__language_model__ = EventsLanguageModel
event_type: Mapped[str] = mapped_column( event_type: Mapped[str] = mapped_column(
String, nullable=False, comment="Event Type" String, nullable=False, comment="Event Type"
@ -58,6 +70,7 @@ class Modules(CrudCollection):
__tablename__ = "modules" __tablename__ = "modules"
__exclude__fields__ = [] __exclude__fields__ = []
__language_model__ = ModulesLanguageModel
module_name: Mapped[str] = mapped_column( module_name: Mapped[str] = mapped_column(
String, nullable=False, comment="Module Name" String, nullable=False, comment="Module Name"
@ -92,6 +105,7 @@ class Services(CrudCollection):
__tablename__ = "services" __tablename__ = "services"
__exclude__fields__ = [] __exclude__fields__ = []
__language_model__ = ServicesLanguageModel
module_id: Mapped[int] = mapped_column(ForeignKey("modules.id"), nullable=False) module_id: Mapped[int] = mapped_column(ForeignKey("modules.id"), nullable=False)
module_uu_id: Mapped[str] = mapped_column( module_uu_id: Mapped[str] = mapped_column(
@ -137,6 +151,7 @@ class Service2Events(CrudCollection):
__tablename__ = "services2events" __tablename__ = "services2events"
__exclude__fields__ = [] __exclude__fields__ = []
__language_model__ = Service2EventsLanguageModel
service_id: Mapped[int] = mapped_column(ForeignKey("services.id"), nullable=False) service_id: Mapped[int] = mapped_column(ForeignKey("services.id"), nullable=False)
service_uu_id = mapped_column(String, nullable=False, comment="Service UUID") service_uu_id = mapped_column(String, nullable=False, comment="Service UUID")
@ -150,6 +165,7 @@ class Event2OccupantExtra(CrudCollection):
__tablename__ = "event2occupant_extra" __tablename__ = "event2occupant_extra"
__exclude__fields__ = [] __exclude__fields__ = []
__language_model__ = Event2OccupantExtraLanguageModel
build_living_space_id: Mapped[int] = mapped_column( build_living_space_id: Mapped[int] = mapped_column(
ForeignKey("build_living_space.id"), nullable=False ForeignKey("build_living_space.id"), nullable=False
@ -180,6 +196,7 @@ class Event2EmployeeExtra(CrudCollection):
__tablename__ = "event2employee_extra" __tablename__ = "event2employee_extra"
__exclude__fields__ = [] __exclude__fields__ = []
__language_model__ = Event2EmployeeExtraLanguageModel
employee_id: Mapped[int] = mapped_column(ForeignKey("employees.id"), nullable=False) employee_id: Mapped[int] = mapped_column(ForeignKey("employees.id"), nullable=False)
employee_uu_id: Mapped[str] = mapped_column( employee_uu_id: Mapped[str] = mapped_column(
@ -209,6 +226,7 @@ class Event2Employee(CrudCollection):
__tablename__ = "event2employee" __tablename__ = "event2employee"
__exclude__fields__ = [] __exclude__fields__ = []
__language_model__ = Event2EmployeeLanguageModel
employee_id: Mapped[int] = mapped_column(ForeignKey("employees.id"), nullable=False) employee_id: Mapped[int] = mapped_column(ForeignKey("employees.id"), nullable=False)
employee_uu_id: Mapped[str] = mapped_column( employee_uu_id: Mapped[str] = mapped_column(
@ -257,6 +275,7 @@ class Event2Occupant(CrudCollection):
__tablename__ = "event2occupant" __tablename__ = "event2occupant"
__exclude__fields__ = [] __exclude__fields__ = []
__language_model__ = Event2OccupantLanguageModel
build_living_space_id: Mapped[str] = mapped_column( build_living_space_id: Mapped[str] = mapped_column(
ForeignKey("build_living_space.id"), nullable=False ForeignKey("build_living_space.id"), nullable=False
@ -309,6 +328,7 @@ class ModulePrice(CrudCollection):
__tablename__ = "module_price" __tablename__ = "module_price"
__exclude__fields__ = [] __exclude__fields__ = []
__language_model__ = ModulePriceLanguageModel
campaign_code: Mapped[str] = mapped_column( campaign_code: Mapped[str] = mapped_column(
String, nullable=False, comment="Campaign Code" String, nullable=False, comment="Campaign Code"
@ -336,73 +356,3 @@ class ModulePrice(CrudCollection):
) # sana düz 75.00 TL yapar ) # sana düz 75.00 TL yapar
__table_args__ = ({"comment": "ModulePrice Information"},) __table_args__ = ({"comment": "ModulePrice Information"},)
# class Modules2Occupant(CrudCollection):
# """
# ModulesOccupantPrices class based on declarative_base and BaseMixin via session
# discounted_price - calculated_price = Pazarlamaya gider yazılır 3 TL
# """
#
# __tablename__ = "modules2_occupant"
#
#
# discounted_percentage: Mapped[float] = mapped_column(Numeric(6, 2), server_default="0.00") # %22
# discounted_price = mapped_column(
# Numeric(20, 2), server_default="0.00"
# ) # Normal: 78.00 TL
# calculated_price = mapped_column(
# Numeric(20, 2), server_default="0.00"
# ) # sana düz 75.00 TL yapar
#
# service_id = mapped_column(ForeignKey("services.id"), nullable=False)
# build_living_space_id = mapped_column(
# ForeignKey("build_living_space.id"), nullable=False, index=True
# )
#
# __table_args__ = ({"comment": "ModulesOccupantPrices Information"},)
#
#
# class Modules2Employee(CrudCollection):
# """
# Modules2EmployeeServices class based on declarative_base and BaseMixin via session
# """
#
# __tablename__ = "modules2_employee"
#
# discounted_percentage: Mapped[float] = mapped_column(Numeric(6, 2), server_default="0.00") # %22
# discounted_price = mapped_column(
# Numeric(20, 2), server_default="0.00"
# ) # Normal: 78.00 TL
# calculated_price = mapped_column(
# Numeric(20, 2), server_default="0.00"
# ) # sana düz 75.00 TL yapar
#
# service_id = mapped_column(ForeignKey("services.id"), nullable=False)
# employee_id = mapped_column(ForeignKey("employees.id"), nullable=False)
#
# __table_args__ = ({"comment": "Modules2EmployeeServices Information"},)
# class Actions(CrudCollection):
# """
# Actions class based on declarative_base and BaseMixin via session
# """
#
# __tablename__ = "actions"
# __exclude__fields__ = []
#
# action_table = mapped_column(String, nullable=False, comment="Action Table")
# action_type = mapped_column(String, nullable=False, comment="Action Type")
# action_description = mapped_column(String, server_default="")
# action_code = mapped_column(String, nullable=False, comment="Action Code")
# endpoint_id = mapped_column(ForeignKey("endpoint_restriction.id"), nullable=True)
# endpoint_uu_id = mapped_column(String, nullable=True, comment="Endpoint UUID")
#
# @property
# def action_name(self):
# return f"{self.action_table} {self.action_type}"
#
# @property
# def total_cost(self):
# return self.cost * self.unit_price
#
# __table_args__ = ({"comment": "Actions Information"},)

View File

@ -1,35 +1,54 @@
from api_library.date_time_actions.date_functions import system_arrow
from api_configs import Auth, ApiStatic, RelationAccess
from datetime import timedelta from datetime import timedelta
from typing import Optional, List
from fastapi import HTTPException from fastapi import HTTPException
from databases.sql_models.core_mixin import CrudCollection
from databases.extensions import SelectAction, SelectActionWithEmployee
from databases.extensions.auth import UserLoginModule
from sqlalchemy import ( from sqlalchemy import (
String, String,
Boolean,
TIMESTAMP,
ForeignKey,
func,
Numeric,
Index,
BigInteger,
Integer, Integer,
Boolean,
ForeignKey,
Index,
TIMESTAMP,
func,
Text, Text,
BigInteger,
Numeric,
or_, or_,
) )
from sqlalchemy.orm import mapped_column, relationship, Mapped from sqlalchemy.orm import mapped_column, relationship, Mapped
from api_library.date_time_actions.date_functions import system_arrow
from api_configs import Auth, ApiStatic, RelationAccess
from databases.sql_models.core_mixin import CrudCollection
from databases.extensions import SelectAction, SelectActionWithEmployee
from databases.extensions.auth import UserLoginModule
from api_validations.validations_request import InsertUsers, InsertPerson from api_validations.validations_request import InsertUsers, InsertPerson
from databases.language_models.identity.identity import (
UsersTokensLanguageModel,
UsersLanguageModel,
PeopleLanguageModel,
RelationshipDutyPeopleLanguageModel,
RelationshipEmployee2PostCodeLanguageModel,
AddressPostcodeLanguageModel,
AddressesLanguageModel,
AddressGeographicLocationsLanguageModel,
AddressCountryLanguageModel,
AddressStateLanguageModel,
AddressCityLanguageModel,
AddressDistrictLanguageModel,
AddressLocalityLanguageModel,
AddressNeighborhoodLanguageModel,
AddressStreetLanguageModel,
OccupantTypesLanguageModel,
ContractsLanguageModel,
)
class UsersTokens(CrudCollection): class UsersTokens(CrudCollection):
__tablename__ = "users_tokens" __tablename__ = "users_tokens"
__exclude__fields__ = [] __exclude__fields__ = []
__language_model__ = UsersTokensLanguageModel
user_id: Mapped[int] = mapped_column(ForeignKey("users.id"), nullable=False) user_id: Mapped[int] = mapped_column(ForeignKey("users.id"), nullable=False)
@ -56,6 +75,7 @@ class Users(CrudCollection, UserLoginModule, SelectAction):
"expiry_begins", "expiry_begins",
"related_company", "related_company",
] ]
__language_model__ = UsersLanguageModel
user_tag: Mapped[str] = mapped_column( user_tag: Mapped[str] = mapped_column(
String(64), server_default="", comment="Unique tag for the user", index=True String(64), server_default="", comment="Unique tag for the user", index=True
@ -85,10 +105,10 @@ class Users(CrudCollection, UserLoginModule, SelectAction):
Boolean, server_default="0", comment="Flag to remember user login" Boolean, server_default="0", comment="Flag to remember user login"
) )
password_expires_day: Mapped[str] = mapped_column( password_expires_day: Mapped[int] = mapped_column(
"expires_day", "expires_day",
String, Integer,
server_default=str(Auth.PASSWORD_EXPIRE_DAY), server_default=str(Auth.PASSWORD_EXPIRE_DAY.days),
comment="Password expires in days", comment="Password expires in days",
) )
password_expiry_begins: Mapped[TIMESTAMP] = mapped_column( password_expiry_begins: Mapped[TIMESTAMP] = mapped_column(
@ -233,6 +253,7 @@ class RelationshipDutyPeople(CrudCollection):
__tablename__ = "relationship_duty_people" __tablename__ = "relationship_duty_people"
__exclude__fields__ = [] __exclude__fields__ = []
__access_by__ = RelationAccess.SuperAccessList __access_by__ = RelationAccess.SuperAccessList
__language_model__ = RelationshipDutyPeopleLanguageModel
company_id: Mapped[int] = mapped_column( company_id: Mapped[int] = mapped_column(
ForeignKey("companies.id"), nullable=False ForeignKey("companies.id"), nullable=False
@ -285,6 +306,7 @@ class People(CrudCollection, SelectAction):
"birth_date", "birth_date",
"tax_no", "tax_no",
] ]
__language_model__ = PeopleLanguageModel
firstname: Mapped[str] = mapped_column( firstname: Mapped[str] = mapped_column(
String, nullable=False, comment="First name of the person" String, nullable=False, comment="First name of the person"
@ -395,6 +417,7 @@ class RelationshipEmployee2PostCode(CrudCollection):
__tablename__ = "relationship_employee2postcode" __tablename__ = "relationship_employee2postcode"
__exclude__fields__ = [] __exclude__fields__ = []
__include__fields__ = [] __include__fields__ = []
__language_model__ = RelationshipEmployee2PostCodeLanguageModel
company_id: Mapped[int] = mapped_column( company_id: Mapped[int] = mapped_column(
ForeignKey("companies.id"), nullable=True ForeignKey("companies.id"), nullable=True
@ -421,6 +444,7 @@ class AddressPostcode(CrudCollection, SelectActionWithEmployee):
__exclude__fields__ = [] __exclude__fields__ = []
__access_by__ = [] __access_by__ = []
__many__table__ = RelationshipEmployee2PostCode __many__table__ = RelationshipEmployee2PostCode
__language_model__ = AddressPostcodeLanguageModel
street_id: Mapped[int] = mapped_column(ForeignKey("address_street.id")) street_id: Mapped[int] = mapped_column(ForeignKey("address_street.id"))
street_uu_id: Mapped[str] = mapped_column( street_uu_id: Mapped[str] = mapped_column(
@ -440,6 +464,7 @@ class Addresses(CrudCollection):
__tablename__ = "addresses" __tablename__ = "addresses"
__exclude__fields__ = [] __exclude__fields__ = []
__language_model__ = AddressesLanguageModel
build_number: Mapped[str] = mapped_column( build_number: Mapped[str] = mapped_column(
String(24), nullable=False, comment="Build Number" String(24), nullable=False, comment="Build Number"
@ -537,6 +562,7 @@ class AddressGeographicLocations(CrudCollection):
__tablename__ = "address_geographic_locations" __tablename__ = "address_geographic_locations"
__exclude__fields__ = [] __exclude__fields__ = []
__language_model__ = AddressGeographicLocationsLanguageModel
geo_table: Mapped[str] = mapped_column( geo_table: Mapped[str] = mapped_column(
String, nullable=False, comment="Address Table Name" String, nullable=False, comment="Address Table Name"
@ -588,6 +614,7 @@ class AddressCountry(CrudCollection):
__tablename__ = "address_country" __tablename__ = "address_country"
__exclude__fields__ = [] __exclude__fields__ = []
__language_model__ = AddressCountryLanguageModel
country_code: Mapped[str] = mapped_column( country_code: Mapped[str] = mapped_column(
String(16), nullable=False, comment="Country Code" String(16), nullable=False, comment="Country Code"
@ -619,6 +646,7 @@ class AddressState(CrudCollection):
__tablename__ = "address_state" __tablename__ = "address_state"
__exclude__fields__ = [] __exclude__fields__ = []
__language_model__ = AddressStateLanguageModel
state_code: Mapped[str] = mapped_column( state_code: Mapped[str] = mapped_column(
String(16), nullable=False, comment="State Code" String(16), nullable=False, comment="State Code"
@ -662,6 +690,7 @@ class AddressCity(CrudCollection):
__tablename__ = "address_city" __tablename__ = "address_city"
__exclude__fields__ = [] __exclude__fields__ = []
__language_model__ = AddressCityLanguageModel
city_code: Mapped[str] = mapped_column( city_code: Mapped[str] = mapped_column(
String(24), nullable=False, comment="City Code" String(24), nullable=False, comment="City Code"
@ -703,6 +732,7 @@ class AddressDistrict(CrudCollection):
__tablename__ = "address_district" __tablename__ = "address_district"
__exclude__fields__ = [] __exclude__fields__ = []
__language_model__ = AddressDistrictLanguageModel
district_code: Mapped[str] = mapped_column( district_code: Mapped[str] = mapped_column(
String(16), nullable=False, comment="District Code" String(16), nullable=False, comment="District Code"
@ -745,6 +775,7 @@ class AddressLocality(CrudCollection):
__tablename__ = "address_locality" __tablename__ = "address_locality"
__exclude__fields__ = [] __exclude__fields__ = []
__language_model__ = AddressLocalityLanguageModel
locality_code: Mapped[str] = mapped_column( locality_code: Mapped[str] = mapped_column(
String(16), nullable=False, comment="Locality Code" String(16), nullable=False, comment="Locality Code"
@ -789,6 +820,7 @@ class AddressNeighborhood(CrudCollection):
__tablename__ = "address_neighborhood" __tablename__ = "address_neighborhood"
__exclude__fields__ = [] __exclude__fields__ = []
__language_model__ = AddressNeighborhoodLanguageModel
neighborhood_code: Mapped[str] = mapped_column( neighborhood_code: Mapped[str] = mapped_column(
String(16), nullable=False, comment="Neighborhood Code" String(16), nullable=False, comment="Neighborhood Code"
@ -839,6 +871,7 @@ class AddressStreet(CrudCollection):
__tablename__ = "address_street" __tablename__ = "address_street"
__exclude__fields__ = [] __exclude__fields__ = []
__language_model__ = AddressStreetLanguageModel
street_code: Mapped[str] = mapped_column( street_code: Mapped[str] = mapped_column(
String(16), nullable=False, comment="Street Code" String(16), nullable=False, comment="Street Code"
@ -940,6 +973,7 @@ class OccupantTypes(CrudCollection):
__tablename__ = "occupant_types" __tablename__ = "occupant_types"
__exclude__fields__ = [] __exclude__fields__ = []
__language_model__ = OccupantTypesLanguageModel
occupant_type: Mapped[str] = mapped_column( occupant_type: Mapped[str] = mapped_column(
String, nullable=False, comment="Occupant Type" String, nullable=False, comment="Occupant Type"
@ -971,6 +1005,7 @@ class Contracts(CrudCollection):
__tablename__ = "contracts" __tablename__ = "contracts"
__exclude__fields__ = [] __exclude__fields__ = []
__language_model__ = ContractsLanguageModel
contract_type: Mapped[str] = mapped_column( contract_type: Mapped[str] = mapped_column(
String(5), String(5),
@ -1021,49 +1056,3 @@ class Contracts(CrudCollection):
Index("_contract_ndx_01", contract_code, unique=True), Index("_contract_ndx_01", contract_code, unique=True),
{"comment": "Contract Information"}, {"comment": "Contract Information"},
) )
# def selected_employee_and_duty_details(self, selected_duty_uu_id):
# from database_sql_models import (
# Companies,
# Employees,
# Duties,
# Departments,
# )
#
# found_person = People.find_one(id=self.person_id)
# found_employee = Employees.find_one(
# people_id=found_person.id, is_confirmed=True
# )
# found_duty = Duties.find_one(uu_id=selected_duty_uu_id)
# found_department = Departments.find_one(id=found_duty.department_id)
# found_company = Companies.find_one(id=found_department.company_id)
# return {
# "duty_list": {
# "duty_id": found_duty.id,
# "duty_uu_id": found_duty.uu_id.__str__(),
# "duty_code": found_duty.duty_code,
# "duty_name": found_duty.duty_name,
# "duty_description": found_duty.duty_description,
# },
# "employee_list": {
# "employee_id": found_employee.id,
# "employee_uu_id": found_employee.uu_id.__str__(),
# "people_id": found_employee.people_id,
# "duty_id": found_employee.duty_id,
# "employee_description": found_employee.employee_description,
# },
# "department_list": {
# "department_id": found_department.id,
# "department_uu_id": found_department.uu_id.__str__(),
# "company_id": found_department.company_id,
# "department_name": found_department.department_name,
# "department_description": found_department.department_description,
# },
# "companies_list": {
# "company_id": found_company.id,
# "company_uu_id": found_company.uu_id.__str__(),
# "formal_name": found_company.formal_name,
# "company_tag": found_company.company_tag,
# },
# }

7
run_auth_service.sh Executable file
View File

@ -0,0 +1,7 @@
#!/bin/bash
echo "Stopping existing containers..."
docker compose -f api-docker-compose.yml down
echo "Building and starting auth service..."
docker compose -f api-docker-compose.yml up --build wag_management_auth_service