-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
35d6a75
commit 0a4a5df
Showing
5 changed files
with
108 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
""" | ||
Controller for endpoints on user | ||
""" | ||
from flask_jwt_extended import get_jwt_identity | ||
|
||
from ridemyway.utils.response import Response | ||
from ridemyway.utils.db_queries import (select_user, | ||
insert_vehicle, select_vehicle) | ||
|
||
|
||
class VehicleController(): | ||
""" | ||
Registers a vehicle | ||
""" | ||
|
||
def register(self, **kwargs): | ||
""" | ||
register vehicle | ||
""" | ||
username = get_jwt_identity() | ||
self.user = select_user(username) | ||
if self.user['usertype'] == 'driver': | ||
vehicle = select_vehicle(kwargs['number_plate']) | ||
if vehicle: | ||
message = 'A vehicle with that numberplate is registered' | ||
return Response.failed(message=message), 409 | ||
kwargs['driver'] = self.user['username'] | ||
reg_vehicle = insert_vehicle(**kwargs) | ||
if reg_vehicle: | ||
message = 'Vehicle registered successfully' | ||
return Response.success(message=message), 201 | ||
message = 'Only drivers can register vehicles' | ||
return Response.failed(message=message), 403 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters