Skip to content

Commit 2db01c3

Browse files
New feature of adding multiple vehicles added (#333)
* New feature of adding multiple vehicles added * reverted to old apis and added register func * fix dom rendering * lint fix --------- Co-authored-by: Roshan Piyush <piyush.roshan@gmail.com>
1 parent d321c85 commit 2db01c3

File tree

16 files changed

+302
-70
lines changed

16 files changed

+302
-70
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.

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,10 @@ 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 =
6363
"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 =

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,19 @@ public class VehicleController {
4040

4141
@Autowired VehicleOwnershipService vehicleOwnershipService;
4242

43+
/**
44+
* @param request
45+
* @return response of success and failure message creates vehicle and sends details to user
46+
*/
47+
@PostMapping("/vehicle/register_vehicle")
48+
public ResponseEntity<CRAPIResponse> registerVehicle(HttpServletRequest request) {
49+
CRAPIResponse registerVehicleResponse = vehicleService.registerVehicle(request);
50+
if (registerVehicleResponse != null && registerVehicleResponse.getStatus() == 200) {
51+
return ResponseEntity.status(HttpStatus.OK).body(registerVehicleResponse);
52+
}
53+
return ResponseEntity.status(HttpStatus.FORBIDDEN).body(registerVehicleResponse);
54+
}
55+
4356
/**
4457
* @param vehicleDetails
4558
* @return response of success and failure message save vehicle Details for user in database

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: 30 additions & 1 deletion
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 sending details to current user
113+
*/
114+
@Transactional
115+
@Override
116+
public CRAPIResponse registerVehicle(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
@@ -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: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ public interface VehicleService {
2828

2929
VehicleDetails createVehicle();
3030

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

3335
VehicleLocationResponse getVehicleLocation(UUID carId);

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'>"

services/web/src/actions/vehicleActions.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,19 @@ interface GetVehiclesPayload extends ActionPayload {
2525
email?: string;
2626
}
2727

28+
export const registerVehicleAction = ({
29+
callback,
30+
accessToken,
31+
}: ActionPayload) => {
32+
return {
33+
type: actionTypes.REGISTER_VEHICLE,
34+
payload: {
35+
accessToken,
36+
callback,
37+
},
38+
};
39+
};
40+
2841
export const verifyVehicleAction = ({
2942
callback,
3043
accessToken,

services/web/src/components/dashboard/dashboard.tsx

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -202,20 +202,18 @@ const Dashboard: React.FC<DashboardProps> = ({
202202
<PageHeader
203203
className="dashboard-header"
204204
title="Vehicles Details"
205-
extra={
206-
!vehicles.length && [
207-
<Button
208-
type="primary"
209-
shape="round"
210-
icon={<PlusOutlined />}
211-
size="large"
212-
onClick={handleVerifyVehicleClick}
213-
key="verify-vehicle"
214-
>
215-
Add a Vehicle
216-
</Button>,
217-
]
218-
}
205+
extra={[
206+
<Button
207+
type="primary"
208+
shape="round"
209+
icon={<PlusOutlined />}
210+
size="large"
211+
onClick={handleVerifyVehicleClick}
212+
key="verify-vehicle"
213+
>
214+
Add Vehicle
215+
</Button>,
216+
]}
219217
/>
220218
<Content>
221219
<Row gutter={[40, 40]}>
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
.add-vehicle-container .ant-row {
2+
align-items: stretch;
3+
gap: calc(var(--spacing-md) * 2) !important;
4+
}
5+
6+
.add-vehicle-card {
7+
height: 100%;
8+
width: 100%;
9+
min-height: 320px;
10+
display: flex;
11+
flex-direction: column;
12+
}
13+
14+
.add-vehicle-card .ant-card-body {
15+
flex: 1;
16+
display: flex;
17+
flex-direction: column;
18+
padding: 16px;
19+
}
20+
21+
.vehicle-alert {
22+
margin-top: 8px;
23+
font-size: 12px;
24+
}
25+
26+
.vehicle-alert .ant-alert-message {
27+
font-weight: 600;
28+
margin-bottom: 4px;
29+
}
30+
31+
.vehicle-alert .ant-alert-description {
32+
font-size: 12px;
33+
line-height: 1.3;
34+
}
35+
36+
.verify-vehicle-form .ant-form-item {
37+
margin-bottom: 12px;
38+
}
39+
40+
.verify-vehicle-form .ant-form-item:last-child {
41+
margin-bottom: 0;
42+
}
43+
44+
@media (max-width: 768px) {
45+
.add-vehicle-card {
46+
min-height: auto;
47+
}
48+
49+
.add-vehicle-container .ant-col {
50+
margin-bottom: 20px;
51+
}
52+
53+
.add-vehicle-container .ant-row {
54+
gap: var(--spacing-md);
55+
}
56+
}

0 commit comments

Comments
 (0)