Пример #1
0
 def put(self, registration):
     """
     Endpoint for updating a ride offer
     ---
     tags:
       - Car
     security:
       - Bearer: []  
     parameters:
       - name: registration
         in: path
         required: true
         description: The licence plate of the car.
         type: string
       - name: model
         in: formData
         required: true
         description: The model of the car.
         type: string
       - name: capacity
         in: formData
         required: true
         description: The capacity of the car.
         type: integer
     responses:
       500:
         description: Internal server error
       200:
         description: Car updated successful
         schema:
           $ref: '#/definitions/UpdateCar'
     """
     args = self.reqparse.parse_args()
     check_for_empty_fields(args)
     return Car.edit(registration, args['model'], args['capacity'])
Пример #2
0
 def post(self, ride_id):
     """
     Endpoint for creating a ride request
     ---
     tags:
       - Ride request
     security:
       - Bearer: []  
     parameters:
       - name: ride_id
         in: path
         required: true
         type: integer
         description: Unique identifier of the ride offer.
       - name: requestor_id
         in: formData
         required: true
         type: integer
         description: Unique identifier of the requestor.
     responses:
       500:
         description: Internal server error
       201:
         description: Ride successfully requested
     """
     args = self.reqparse.parse_args()
     check_for_empty_fields(args)
     ride_request = RideRequest(ride_id, args['requestor_id'],
                                args['request_status'])
     return ride_request.add()
Пример #3
0
 def put(self, user_id):
     """
     Endpoint for user profile update
     ---
     tags:
       - User
     security:
       - Bearer: []
     parameters:
       - name: user_id
         in: path
         required: true
         type: integer
       - name: firstname
         in: formData
         required: true
         description: The user's firstname.
         type: string
       - name: lastname
         in: formData
         required: true
         description: The user's lastname.
         type: string
       - name: password
         in: formData
         required: true
         description: The user's password.
         type: string
         format: password
       - name: car_registration
         in: formData
         description: The user's car licence plate.
         type: string
       - name: phone_number
         in: formData
         description: The user's phone number.
         type: string
     responses:
       500:
         description: Internal server error
       200:
         description: Update successful
       404:
         description: The user does not exist
     """
     args = self.reqparse.parse_args()
     check_for_empty_fields(args)
     if len(args['password']) >= 8:
         return User.edit(user_id, args['firstname'], args['lastname'],
                          args['password'], args['phone_number'],
                          args['car_registration'])
     return {
         'status': 'failed',
         'message': 'Password is too short. At least 8 characters required'
     }, 202
Пример #4
0
 def post(self):
     """
     Endpoint for creating a ride offer
     ---
     tags:
       - Ride
     security:
       - Bearer: []
     parameters:
       - name: date
         in: formData
         required: true
         description: Date the ride will be taken.
         type: string
         format: date
       - name: time
         in: formData
         required: true
         description: Time the ride will start.
         type: string
       - name: pickup
         in: formData
         required: true
         description: Place the ride will be taken from.
         type: string
       - name: dropoff
         in: formData
         required: true
         description: Destination of the ride.
         type: string
       - name: driver_id
         in: formData
         required: true
         description: Unique identifier of the driver.
         type: integer
       - name: price
         in: formData
         required: true
         description: The price of the ride.
         type: integer
         format: float
     responses:
       500:
         description: Internal server error
       201:
         description: Ride creation successful
     """
     args = self.reqparse.parse_args()
     check_for_empty_fields(args)
     validate_date(args['date'])
     ride = Ride(args['date'], args['time'], args['pickup'],
                 args['dropoff'], args['driver_id'], args['price'])
     return ride.add()
Пример #5
0
 def put(self, ride_id, request_id):
     # PUT method for editing a ride request
     """
     Endpoint for accepting/declining a ride request
     ---
     tags:
       - Ride request
     security:
       - Bearer: []  
     parameters:
       - name: ride_id
         in: path
         required: true
         type: integer
         description: Unique identifier of the ride offer.
       - name: request_id
         in: path
         required: true
         type: integer
         description: Unique identifier of the ride request.
       - name: request_status
         in: formData
         required: true
         type: string
         description: Current status of the request.
         enum:
           - "Accepted"
           - "Declined"
     responses:
       500:
         description: Internal server error
       201:
         description: Ride request successfully updated
         # schema:
         #   $ref: '#/definitions/UpdateRideRequest'
     """
     args = self.reqparse.parse_args()
     check_for_empty_fields(args)
     return RideRequest.edit(ride_id, request_id, args['request_status'])
Пример #6
0
 def post(self):
     """
     Endpoint for user log in
     ---
     tags:
       - User
     security:
       - Bearer: []  
     parameters:
       - name: email
         in: formData
         required: true
         description: The user's email.
         type: string
       - name: password
         in: formData
         required: true
         description: The user's password.
         type: string
         format: password
     responses:
       500:
         description: Internal server error
       200:
         description: Login successful
       202:
         description: Wrong password, please try again.
       404:
         description: The user with email string does not exist
     """
     args = self.reqparse.parse_args()
     check_for_empty_fields(args)
     if match_email(args['email']):
         return User.login(args['email'], args['password'])
     return {
         'status': 'failed',
         'message': 'Invalid email address, try again'
     }, 202
Пример #7
0
 def post(self):
     """
     Endpoint for creating a car
     ---
     tags:
       - Car
     security:
       - Bearer: []  
     parameters:
       - name: registration
         in: formData
         required: true
         description: The licence plate of the car.
         type: string
       - name: model
         in: formData
         required: true
         description: The model of the car.
         type: string
       - name: capacity
         in: formData
         required: true
         description: The capacity of the car.
         type: integer
     responses:
       500:
         description: Internal server error
       201:
         description: Car created successfully
         # schema:
         #   $ref: '#/definitions/Car'
     """
     args = self.reqparse.parse_args()
     check_for_empty_fields(args)
     car = Car(args['registration'], args['model'], args['capacity'])
     return car.add()
Пример #8
0
    def post(self):
        """
        Endpoint for user sign up
        ---
        tags:
          - User
        parameters:
          - name: firstname
            in: formData
            required: true
            description: The user's firstname.
            type: string
          - name: lastname
            in: formData
            required: true
            description: The user's lastname.
            type: string
          - name: email
            in: formData
            required: true
            description: The user's email.
            type: string
          - name: password
            in: formData
            required: true
            description: The user's password.
            type: string
            format: password
          - name: confirm_password
            in: formData
            required: true
            description: Confirmation of the password entered.
            type: string
            format: password
        responses:
          500:
            description: Internal server error
          201:
            description: Account creation successful
          202:
            description: Password is too short. At least 8 characters required
        """

        args = self.reqparse.parse_args()
        check_for_empty_fields(args)
        if match_email(args['email']):
            if args['password'] == args['confirm_password']:
                if len(args['password']) >= 8:
                    user = User(args['firstname'], args['lastname'],
                                args['email'], args['password'],
                                args['phone_number'], args['car_registration'])
                    return user.add()
                return {
                    'status':
                    'failed',
                    'message':
                    'Password is too short. At least 8 characters required'
                }, 202
            return {
                'status': 'failed',
                'message':
                'Password and confirm password do not match, try again'
            }, 202
        return {
            'status': 'failed',
            'message': 'Invalid email address, try again'
        }, 202
Пример #9
0
 def put(self, ride_id):
     """
     Endpoint for updating a ride offer
     ---
     tags:
       - Ride
     security:
       - Bearer: []  
     parameters:
       - name: ride_id
         in: path
         required: true
         description: Unique identifier of the ride.
         type: integer
       - name: date
         in: formData
         required: true
         description: Date the ride will be taken.
         type: string
       - name: time
         in: formData
         required: true
         description: Time the ride will start.
         type: string
       - name: pickup
         in: formData
         required: true
         description: Place the ride will be taken from.
         type: string
       - name: dropoff
         in: formData
         required: true
         description: Destination of the ride.
         type: string
       - name: driver_id
         in: formData
         required: true
         description: Unique identifier of the driver.
         type: integer
       - name: price
         in: formData
         required: true
         description: The price of the ride.
         type: integer
         format: float
       - name: status
         in: formData
         description: The status of the ride.
         type: string
         enum:
           - "In Offer"
           - "Started"
           - "Done"
     responses:
       500:
         description: Internal server error
       201:
         description: Ride creation successful
     """
     args = self.reqparse.parse_args()
     check_for_empty_fields(args)
     return Ride.edit(args['date'], args['time'], args['pickup'],
                      args['dropoff'], args['driver_id'], args['price'],
                      args['status'], ride_id)