Exemple #1
0
def serialize_review(review: Review) -> dict:
    return dict(
        account=serialize_account(review.account),
        datetime_of_create=review.datetime_of_create,
        evaluation=review.evaluation,
        comment=review.comment,
    )
Exemple #2
0
    def authenticate(self, token: str) -> dict:
        token_data = self.access_tokenizer.decode(token)
        if not token_data:
            raise CoreError(ErrorCodes.NOT_AUTHORIZED)

        account_email = token_data['email']

        account = self.accounts_repo.get_by_email(account_email)

        return serialize_account(account)
Exemple #3
0
    def authorize(self, email: str, password: str) -> str:
        password_hash = self.password_tokenizer.encode(password)
        account = self.accounts_repo.authorize(email, password_hash)

        if not account:
            raise CoreError(ErrorCodes.BAD_CREDENTIALS)

        token = self.access_tokenizer.encode(serialize_account(account))

        return token
Exemple #4
0
def serialize_trip(trip: Trip) -> dict:
    return dict(
        trip_id=trip.trip_id,
        start_datetime=trip.start_datetime,
        estimated_end_date=trip.estimated_end_date,
        car=serialize_car(trip.car),
        customer=serialize_account(trip.customer),
        price_amount=trip.price_amount,
        paid=trip.paid,
        started=trip.started,
        ended=trip.ended,
        cancelled=trip.cancelled,
        real_end_date=trip.real_end_date,
    )
Exemple #5
0
    def register(self, account_data: dict) -> dict:
        schema = AccountSchema()
        validation_errors = schema.validate(account_data)
        if validation_errors:
            raise CoreError(ErrorCodes.ACCOUNT_IS_NOT_A_VALID,
                            validation_errors)

        password_hash = self.password_tokenizer.encode(
            account_data['password'])
        account = self.accounts_repo.create(
            email=account_data['email'],
            password_hash=password_hash,
            first_name=account_data['personal_data']['first_name'],
            last_name=account_data['personal_data']['last_name'],
        )

        return serialize_account(account)