Skip to content

Commit 6abbae7

Browse files
committed
New feature of adding multiple vehicles added
1 parent 91d8ac5 commit 6abbae7

File tree

22 files changed

+345
-136
lines changed

22 files changed

+345
-136
lines changed

docs/challengeSolutions.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Verify the ports of the container by running the following command : `docker ps`
1414
#### Detailed solution
1515

1616
1. Login to the application from http://localhost:8888/login
17-
2. From the *Dashboard*, choose *Add a Vehicle* and add the vehicle by providing the VIN and pincode received in Mailhog mailbox after Signup or by reinitiating from *Dashboard* page.
17+
2. From the *Dashboard*, choose *Add Vehicle* and add the vehicle by providing the VIN and pincode received in Mailhog mailbox after Signup or by reinitiating from *Dashboard* page.
1818
3. After the vehicle details are verified successful, the vehicle will get added and then be populated in the *Dashboard* page.
1919
4. Observe the request sent when we click *Refresh Location*. It can be seen that the endpoint is in the format `/identity/api/v2/vehicle/<vehicleid>/location`.
2020
5. Sensitive information like latitude and longitude are provided back in the response for the endpoint. Send the request to *Repeater* for later purpose.

openapi-spec/crapi-openapi-spec.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1009,9 +1009,9 @@
10091009
},
10101010
"parameters" : [ ]
10111011
},
1012-
"/identity/api/v2/vehicle/add_vehicle" : {
1012+
"/identity/api/v2/vehicle/verify_vehicle" : {
10131013
"post" : {
1014-
"operationId" : "add_vehicle",
1014+
"operationId" : "verify_vehicle",
10151015
"summary" : "Add the user vehicle",
10161016
"tags" : [ "Identity / Vehicle" ],
10171017
"security" : [ {

postman_collections/crAPI.postman_collection.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -775,7 +775,7 @@
775775
"uid": "13872198-c0ef62ef-8ca0-4eaf-a3d8-44c1aa41a407"
776776
},
777777
{
778-
"name": "Add Vehicle from Mail",
778+
"name": "Verify Vehicle from Mail",
779779
"event": [
780780
{
781781
"listen": "test",
@@ -850,7 +850,7 @@
850850
"raw": "{\"vin\": \"{{VIN}}\", \"pincode\": \"{{PIN}}\"}"
851851
},
852852
"url": {
853-
"raw": "{{url}}/identity/api/v2/vehicle/add_vehicle",
853+
"raw": "{{url}}/identity/api/v2/vehicle/verify_vehicle",
854854
"host": [
855855
"{{url}}"
856856
],
@@ -859,7 +859,7 @@
859859
"api",
860860
"v2",
861861
"vehicle",
862-
"add_vehicle"
862+
"verify_vehicle"
863863
]
864864
}
865865
},

services/chatbot/src/resources/crapi-openapi-spec.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1009,9 +1009,9 @@
10091009
},
10101010
"parameters" : [ ]
10111011
},
1012-
"/identity/api/v2/vehicle/add_vehicle" : {
1012+
"/identity/api/v2/vehicle/verify_vehicle" : {
10131013
"post" : {
1014-
"operationId" : "add_vehicle",
1014+
"operationId" : "verify_vehicle",
10151015
"summary" : "Add the user vehicle",
10161016
"tags" : [ "Identity / Vehicle" ],
10171017
"security" : [ {

services/identity/src/main/java/com/crapi/constant/UserMessage.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,12 @@ public class UserMessage {
5555
public static final String PASSWORD_GOT_RESET = "Password reset successful.";
5656
public static final String VEHICLE_MODEL_IS_NOT_AVAILABLE =
5757
"Sorry we don't have Vehicle model for this company. Please select other..";
58-
public static final String VEHICLE_SAVED_SUCCESSFULLY = "Vehicle save successfully..";
58+
public static final String VEHICLE_SAVED_SUCCESSFULLY = "Vehicle saved successfully!";
5959
public static final String VEHICLE_NOT_FOUND = "Failed to get Vehicles";
6060
public static final String VEHICLE_DETAILS_SENT_TO_EMAIL =
61-
"Your newly purchased Vehicle Details have been sent to you email address. If you have used example.com email, check your email using the MailHog web portal. ";
61+
"Your newly purchased vehicle details have been sent to you email address. Verify them to add your vehicle. [If you have used example.com email, check your email using the MailHog web portal]";
6262
public static final String CHANGE_EMAIL_MESSAGE =
63-
"The token has been sent to your email. If you have used example.com email, check your email using the MailHog web portal. ";
63+
"The token has been sent to your email. If you have used example.com email, check your email using the MailHog web portal.";
6464
public static final String CHANGE_EMAIL_OLD_USEREMAIL_NOT_FOUND_MESSAGE =
6565
"Sorry, we didn't find any user for ";
6666
public static final String INVALID_EMAIL_TOKEN = "Sorry, Token did't match";

services/identity/src/main/java/com/crapi/controller/VehicleController.java

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,27 @@ public class VehicleController {
4444
* @param vehicleDetails
4545
* @return response of success and failure message save vehicle Details for user in database
4646
*/
47-
@PostMapping("/vehicle/add_vehicle")
47+
@PostMapping("/vehicle/create_vehicle")
48+
public ResponseEntity<CRAPIResponse> createVehicle(HttpServletRequest request) {
49+
CRAPIResponse createVehicleResponse = vehicleService.createVehicle(request);
50+
if (createVehicleResponse != null && createVehicleResponse.getStatus() == 200) {
51+
return ResponseEntity.status(HttpStatus.OK).body(createVehicleResponse);
52+
}
53+
return ResponseEntity.status(HttpStatus.FORBIDDEN).body(createVehicleResponse);
54+
}
55+
56+
/**
57+
* @param vehicleDetails
58+
* @return response of success and failure message save vehicle Details for user in database
59+
*/
60+
@PostMapping("/vehicle/verify_vehicle")
4861
public ResponseEntity<CRAPIResponse> addVehicle(
4962
@Valid @RequestBody VehicleForm vehicleDetails, HttpServletRequest request) {
50-
CRAPIResponse checkVehicleResponse = vehicleService.checkVehicle(vehicleDetails, request);
51-
if (checkVehicleResponse != null && checkVehicleResponse.getStatus() == 200) {
52-
return ResponseEntity.status(HttpStatus.OK).body(checkVehicleResponse);
63+
CRAPIResponse verifyVehicleResponse = vehicleService.verifyVehicle(vehicleDetails, request);
64+
if (verifyVehicleResponse != null && verifyVehicleResponse.getStatus() == 200) {
65+
return ResponseEntity.status(HttpStatus.OK).body(verifyVehicleResponse);
5366
}
54-
return ResponseEntity.status(HttpStatus.FORBIDDEN).body(checkVehicleResponse);
67+
return ResponseEntity.status(HttpStatus.FORBIDDEN).body(verifyVehicleResponse);
5568
}
5669

5770
/**

services/identity/src/main/java/com/crapi/service/Impl/UserRegistrationServiceImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public CRAPIResponse registerUser(SignUpForm signUpRequest) {
8080
return new CRAPIResponse(
8181
UserMessage.NUMBER_ALREADY_REGISTERED + signUpRequest.getNumber(), 403);
8282
}
83-
// check Number in database
83+
// Check Email in database
8484
if (userRepository.existsByEmail(signUpRequest.getEmail())) {
8585
return new CRAPIResponse(
8686
UserMessage.EMAIL_ALREADY_REGISTERED + signUpRequest.getEmail(), 403);
@@ -107,7 +107,7 @@ public CRAPIResponse registerUser(SignUpForm signUpRequest) {
107107
if (vehicleDetails != null) {
108108
smtpMailServer.sendMail(
109109
user.getEmail(),
110-
MailBody.signupMailBody(
110+
MailBody.newVehicleMailBody(
111111
vehicleDetails,
112112
(userDetails != null && userDetails.getName() != null
113113
? userDetails.getName()

services/identity/src/main/java/com/crapi/service/Impl/VehicleServiceImpl.java

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,35 @@ public VehicleDetails createVehicle() {
107107
500);
108108
}
109109

110+
/**
111+
* @param request
112+
* @return CRAPIResponse after creating a new vehicle and assigning it to the current user
113+
*/
114+
@Transactional
115+
@Override
116+
public CRAPIResponse createVehicle(HttpServletRequest request) {
117+
User user = null;
118+
UserDetails userDetails = null;
119+
VehicleDetails vehicleDetails = null;
120+
121+
user = userService.getUserFromToken(request);
122+
if (user == null) {
123+
return new CRAPIResponse(UserMessage.TOKEN_VERIFICATION_MISSING, 401);
124+
}
125+
userDetails = userDetailsRepository.findByUser_id(user.getId());
126+
vehicleDetails = createVehicle();
127+
if (vehicleDetails != null) {
128+
smtpMailServer.sendMail(
129+
user.getEmail(),
130+
MailBody.newVehicleMailBody(
131+
vehicleDetails,
132+
(userDetails != null && userDetails.getName() != null ? userDetails.getName() : "")),
133+
"Your New Vehicle In crAPI");
134+
return new CRAPIResponse(UserMessage.VEHICLE_DETAILS_SENT_TO_EMAIL, 200);
135+
}
136+
return new CRAPIResponse(UserMessage.INTERNAL_SERVER_ERROR, 500);
137+
}
138+
110139
/**
111140
* @param request
112141
* @return list of vehicle of user
@@ -176,7 +205,7 @@ public VehicleLocationResponse getVehicleLocation(UUID carId) {
176205
*/
177206
@Transactional
178207
@Override
179-
public CRAPIResponse checkVehicle(VehicleForm vehicleForm, HttpServletRequest request) {
208+
public CRAPIResponse verifyVehicle(VehicleForm vehicleForm, HttpServletRequest request) {
180209
VehicleDetails checkVehicle = null;
181210
User user = null;
182211
checkVehicle = vehicleDetailsRepository.findByVin(vehicleForm.getVin());
@@ -219,7 +248,7 @@ public CRAPIResponse sendVehicleDetails(HttpServletRequest request) {
219248
}
220249
smtpMailServer.sendMail(
221250
user.getEmail(),
222-
MailBody.signupMailBody(
251+
MailBody.newVehicleMailBody(
223252
vehicleDetails,
224253
(userDetails != null && userDetails.getName() != null ? userDetails.getName() : "")),
225254
"Welcome to crAPI");

services/identity/src/main/java/com/crapi/service/VehicleService.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,13 @@ public interface VehicleService {
2828

2929
VehicleDetails createVehicle();
3030

31+
CRAPIResponse createVehicle(HttpServletRequest request);
32+
3133
List<VehicleDetails> getVehicleDetails(HttpServletRequest request);
3234

3335
VehicleLocationResponse getVehicleLocation(UUID carId);
3436

35-
CRAPIResponse checkVehicle(VehicleForm vehicleDetails, HttpServletRequest request);
37+
CRAPIResponse verifyVehicle(VehicleForm vehicleDetails, HttpServletRequest request);
3638

3739
CRAPIResponse sendVehicleDetails(HttpServletRequest request);
3840
}

services/identity/src/main/java/com/crapi/utils/MailBody.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,13 @@ public static String otpMailBody(Otp otp) {
5050
* @param name
5151
* @return Mail body for user Signup
5252
*/
53-
public static String signupMailBody(VehicleDetails vehicleDetails, String name) {
53+
public static String newVehicleMailBody(VehicleDetails vehicleDetails, String name) {
5454
String msgBody =
5555
"<html><body>"
5656
+ "<font face='calibri' style = 'font-size:15px; color:#000;'>Hi "
5757
+ name
5858
+ "<font>,"
59-
+ "<br><font face='calibri'><p style = 'font-size:15px; color:#000;'>We are glad to have you on-board. Your newly purchased vehiche details are provided below. Please add it on your crAPI dashboard.</p>"
59+
+ "<br><font face='calibri'><p style = 'font-size:15px; color:#000;'>We are glad to have you on-board with a new vehicle. Your newly purchased vehicle details are provided below. Please add it on your crAPI dashboard.</p>"
6060
+ "<p><font face='calibri' style = 'font-size:15px;color:#000;'>Your vehicle information is <b>VIN: </font><font face='calibri' font color='#0000ff'>"
6161
+ vehicleDetails.getVin()
6262
+ "</font></b> and <b>Pincode: <font face='calibri' font color='#0000ff'>"

0 commit comments

Comments
 (0)