Ejemplo n.º 1
0
    def post(self):
        data = request.get_json(force=True)

        if not data:
            return {'message': 'No input data provided'}, 400

        if (UserModel.find_by_username(data['email'])):

            return {'message': 'User {} already exists'.format(data['email'])}

        new_user = UserModel(username=data['email'],
                             password=UserModel.generate_hash(
                                 data['password']),
                             user_role=data['user_role'])

        try:
            new_user.save_to_db()

            if (data['user_role'] == 'passenger'):

                new_passenger = PassengerModel(passenger_name=data['username'],
                                               passenger_email=data['email'])

                try:
                    print('passenger_email try ')
                    new_passenger.save_to_db()
                    return {'success': 1}

                except Exception as e:
                    return {'message': 'Something went wrong', 'error': e}, 500

            if (data['user_role'] == 'owner'):

                new_owner = OwnerModel(
                    owner_name=data['username'],
                    owner_email=data['email'],
                    owner_nic="0000",
                    address="owner adrs",
                    area="area",
                    service_type="service_type",
                    company_name="company_name",
                )

                try:
                    new_owner.save_to_db()
                    return {'success': 1}

                except Exception as e:
                    return {'message': 'Something went wrong', 'error': e}, 500

            return {'success': 1}

        except Exception as e:
            return {'message': 'Something went wrong', 'error': e}, 500
Ejemplo n.º 2
0
    def get(self, trip_id):

        bid_details = []

        for ts in trip_status_schema.dump(
                TripStatusModel.find_by_tripId(trip_id)):
            print(ts)
            for owner in owner_schema.dump(OwnerModel().find_by_id(
                    ts['owner_id'])):
                print(ts['owner_id'], ts['assigned_driver'])

                for vehicle in vehicle_schema.dump(
                        VehicleModel().vehicle_detailsby_id(
                            ts['assigned_driver'])):
                    print(vehicle['vehicle_type'])

                    bid_details.append({
                        'ts_id': ts['ts_id'],
                        'company_name': owner['company_name'],
                        'area': owner['area'],
                        'contact': owner['contact_num'],
                        'budget': ts['trip_budget'],
                        'v_type': vehicle['vehicle_type'],
                        'v_brand': vehicle['vehicle_brand'],
                        'driver': ts['assigned_driver']
                    })
        print(bid_details)
        return bid_details
Ejemplo n.º 3
0
    def owner_suitsfor_trip(self, owId):

        area = OwnerModel().get_area(owId)

        trip_by_area = TripPlanModel().trip_detailsbyArea(area)

        trip_plan_json = trips_plan_schema.dump(trip_by_area)

        return_data = []

        for trip in trip_plan_json:
            trip_details = self.get_tripDetails(trip['trip_id'])

            for details in trip_details:
                if (VehicleModel().driver_has_vehicle_byLoad(
                        owId, details['no_of_passengers'])
                        or VehicleModel().driver_has_vehicle_byAC(
                            owId, details['ac_condition'])
                        and VehicleModel().driver_has_vehicle_byType(
                            owId, details['vehicle_type'])):

                    return_data.append({
                        'is_ok': True,
                        'trip': trip['trip_id']
                    })
                    break
                else:
                    return_data.append({
                        'is_ok': False,
                        'trip': trip['trip_id']
                    })
                    break

        return return_data
Ejemplo n.º 4
0
    def post(self, ):
        data = request.get_json(force=True)

        new_owner = OwnerModel(
            owner_name=data['owner_name'],
            owner_nic=data['owner_nic'],
            contact_num=data['contact_num'],
            address=data['address'],
            area=data['area'],
            service_type=data['service_type'],
            company_name=data['company_name'],
            owner_nic_pic=data['owner_nic_pic'],
            owner_cmp_pic=data['owner_cmp_pic'],
            owner_cmp_registration_doc=data['owner_cmp_registration_doc'])

        if not data:
            return {'message': 'No data provided'}, 400

        if OwnerModel.find_by_id(data['ow_id']):
            if OwnerModel.update_owner_details(data['ow_id'], new_owner):
                return {'message': 'details updated'}
            return {'message': 'Owner {} already exists'.format(data['ow_id'])}

        print(new_owner)

        try:
            new_owner.save_to_db()
            return {'message': 'owner {} created'.format(data['owner_name'])}
        except Exception as e:
            return {
                'message': 'Something went wrong',
                'error': e,
                'data': new_owner
            }, 500
Ejemplo n.º 5
0
    def post(self):

        data = request.get_json(force=True)

        username = data['username']

        current_user = UserModel.find_by_username(username)

        if not current_user:
            return {'message': 'User {} doesn\'t exist'.format(username)}

        user_role = UserModel.get_user_role(username)

        if UserModel.verify_hash(data['password'], current_user.password):

            genr_access_token = create_access_token(identity=username)
            genr_refresh_token = create_refresh_token(identity=username)

            UserModel.update_table(username, genr_access_token,
                                   genr_refresh_token)

            if user_role == 'passenger':
                userId = PassengerModel.get_passengerId(username)
                PassengerModel.update_token(userId, genr_access_token)
            if user_role == 'driver':
                userId = DriverModel.get_driverIdbyNIC(username)
                DriverModel.update_token(userId, genr_access_token)
            if user_role == 'owner':
                userId = OwnerModel.get_ownerId(username)
                OwnerModel.update_token(userId, genr_access_token)

            return {
                'success': 1,
                'access_token': genr_access_token,
                'refresh_token': genr_refresh_token,
                'user_id': userId
            }
        else:
            return {'message': 'wrong password'}
Ejemplo n.º 6
0
    def get(self, ow_id):

        trips_detail = []

        print('SINGLE TRIP',
              trip_plan_schema.dump(TripPlanModel.findtrip_by_id(2)))

        if OwnerModel().is_owner(ow_id):
            result = self.owner_suitsfor_trip(ow_id)
            print('Results', result)

            for item in result:
                if item['is_ok']:
                    #trips_detail.append(trips_plan_schema.dump(TripPlanModel().find_by_trip_id(item['trip'])))
                    trips_detail.append(
                        trip_plan_schema.dump(
                            TripPlanModel.findtrip_by_id(item['trip'])))
            print(trips_detail)
            return trips_detail
        else:
            return {'message': 'No trips for you !'}
Ejemplo n.º 7
0
 def get(slef, owId):
     return owner_schema.dump(OwnerModel().owner_detials(owId))
Ejemplo n.º 8
0
 def get(self, ow_id):
     d1 = OwnerModel().get_area(ow_id)
     return {'area': d1}
Ejemplo n.º 9
0
 def get(self):
     res = owner_schema.dump(OwnerModel().return_all())
     return {'owners': res}