Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/challengeSolutions.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Verify the ports of the container by running the following command : `docker ps`
#### Detailed solution

1. Login to the application from http://localhost:8888/login
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.
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.
3. After the vehicle details are verified successful, the vehicle will get added and then be populated in the *Dashboard* page.
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`.
5. Sensitive information like latitude and longitude are provided back in the response for the endpoint. Send the request to *Repeater* for later purpose.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ public class UserMessage {
public static final String PASSWORD_GOT_RESET = "Password reset successful.";
public static final String VEHICLE_MODEL_IS_NOT_AVAILABLE =
"Sorry we don't have Vehicle model for this company. Please select other..";
public static final String VEHICLE_SAVED_SUCCESSFULLY = "Vehicle save successfully..";
public static final String VEHICLE_SAVED_SUCCESSFULLY = "Vehicle saved successfully!";
public static final String VEHICLE_NOT_FOUND = "Failed to get Vehicles";
public static final String VEHICLE_DETAILS_SENT_TO_EMAIL =
"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. ";
"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]";
public static final String CHANGE_EMAIL_MESSAGE =
"The token has been sent to your email. If you have used example.com email, check your email using the MailHog web portal. ";
public static final String CHANGE_EMAIL_OLD_USEREMAIL_NOT_FOUND_MESSAGE =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,19 @@ public class VehicleController {

@Autowired VehicleOwnershipService vehicleOwnershipService;

/**
* @param request
* @return response of success and failure message creates vehicle and sends details to user
*/
@PostMapping("/vehicle/register_vehicle")
public ResponseEntity<CRAPIResponse> registerVehicle(HttpServletRequest request) {
CRAPIResponse registerVehicleResponse = vehicleService.registerVehicle(request);
if (registerVehicleResponse != null && registerVehicleResponse.getStatus() == 200) {
return ResponseEntity.status(HttpStatus.OK).body(registerVehicleResponse);
}
return ResponseEntity.status(HttpStatus.FORBIDDEN).body(registerVehicleResponse);
}

/**
* @param vehicleDetails
* @return response of success and failure message save vehicle Details for user in database
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public CRAPIResponse registerUser(SignUpForm signUpRequest) {
return new CRAPIResponse(
UserMessage.NUMBER_ALREADY_REGISTERED + signUpRequest.getNumber(), 403);
}
// check Number in database
// Check Email in database
if (userRepository.existsByEmail(signUpRequest.getEmail())) {
return new CRAPIResponse(
UserMessage.EMAIL_ALREADY_REGISTERED + signUpRequest.getEmail(), 403);
Expand All @@ -107,7 +107,7 @@ public CRAPIResponse registerUser(SignUpForm signUpRequest) {
if (vehicleDetails != null) {
smtpMailServer.sendMail(
user.getEmail(),
MailBody.signupMailBody(
MailBody.newVehicleMailBody(
vehicleDetails,
(userDetails != null && userDetails.getName() != null
? userDetails.getName()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,35 @@ public VehicleDetails createVehicle() {
500);
}

/**
* @param request
* @return CRAPIResponse after creating a new vehicle and sending details to current user
*/
@Transactional
@Override
public CRAPIResponse registerVehicle(HttpServletRequest request) {
User user = null;
UserDetails userDetails = null;
VehicleDetails vehicleDetails = null;

user = userService.getUserFromToken(request);
if (user == null) {
return new CRAPIResponse(UserMessage.TOKEN_VERIFICATION_MISSING, 401);
}
userDetails = userDetailsRepository.findByUser_id(user.getId());
vehicleDetails = createVehicle();
if (vehicleDetails != null) {
smtpMailServer.sendMail(
user.getEmail(),
MailBody.newVehicleMailBody(
vehicleDetails,
(userDetails != null && userDetails.getName() != null ? userDetails.getName() : "")),
"Your New Vehicle In crAPI");
return new CRAPIResponse(UserMessage.VEHICLE_DETAILS_SENT_TO_EMAIL, 200);
}
return new CRAPIResponse(UserMessage.INTERNAL_SERVER_ERROR, 500);
}

/**
* @param request
* @return list of vehicle of user
Expand Down Expand Up @@ -219,7 +248,7 @@ public CRAPIResponse sendVehicleDetails(HttpServletRequest request) {
}
smtpMailServer.sendMail(
user.getEmail(),
MailBody.signupMailBody(
MailBody.newVehicleMailBody(
vehicleDetails,
(userDetails != null && userDetails.getName() != null ? userDetails.getName() : "")),
"Welcome to crAPI");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ public interface VehicleService {

VehicleDetails createVehicle();

CRAPIResponse registerVehicle(HttpServletRequest request);

List<VehicleDetails> getVehicleDetails(HttpServletRequest request);

VehicleLocationResponse getVehicleLocation(UUID carId);
Expand Down
4 changes: 2 additions & 2 deletions services/identity/src/main/java/com/crapi/utils/MailBody.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,13 @@ public static String otpMailBody(Otp otp) {
* @param name
* @return Mail body for user Signup
*/
public static String signupMailBody(VehicleDetails vehicleDetails, String name) {
public static String newVehicleMailBody(VehicleDetails vehicleDetails, String name) {
String msgBody =
"<html><body>"
+ "<font face='calibri' style = 'font-size:15px; color:#000;'>Hi "
+ name
+ "<font>,"
+ "<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>"
+ "<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>"
+ "<p><font face='calibri' style = 'font-size:15px;color:#000;'>Your vehicle information is <b>VIN: </font><font face='calibri' font color='#0000ff'>"
+ vehicleDetails.getVin()
+ "</font></b> and <b>Pincode: <font face='calibri' font color='#0000ff'>"
Expand Down
13 changes: 13 additions & 0 deletions services/web/src/actions/vehicleActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,19 @@ interface GetVehiclesPayload extends ActionPayload {
email?: string;
}

export const registerVehicleAction = ({
callback,
accessToken,
}: ActionPayload) => {
return {
type: actionTypes.REGISTER_VEHICLE,
payload: {
accessToken,
callback,
},
};
};

export const verifyVehicleAction = ({
callback,
accessToken,
Expand Down
26 changes: 12 additions & 14 deletions services/web/src/components/dashboard/dashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -202,20 +202,18 @@ const Dashboard: React.FC<DashboardProps> = ({
<PageHeader
className="dashboard-header"
title="Vehicles Details"
extra={
!vehicles.length && [
<Button
type="primary"
shape="round"
icon={<PlusOutlined />}
size="large"
onClick={handleVerifyVehicleClick}
key="verify-vehicle"
>
Add a Vehicle
</Button>,
]
}
extra={[
<Button
type="primary"
shape="round"
icon={<PlusOutlined />}
size="large"
onClick={handleVerifyVehicleClick}
key="verify-vehicle"
>
Add Vehicle
</Button>,
]}
/>
<Content>
<Row gutter={[40, 40]}>
Expand Down
56 changes: 56 additions & 0 deletions services/web/src/components/verifyVehicle/verifyVehicle.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
.add-vehicle-container .ant-row {
align-items: stretch;
gap: calc(var(--spacing-md) * 2) !important;
}

.add-vehicle-card {
height: 100%;
width: 100%;
min-height: 320px;
display: flex;
flex-direction: column;
}

.add-vehicle-card .ant-card-body {
flex: 1;
display: flex;
flex-direction: column;
padding: 16px;
}

.vehicle-alert {
margin-top: 8px;
font-size: 12px;
}

.vehicle-alert .ant-alert-message {
font-weight: 600;
margin-bottom: 4px;
}

.vehicle-alert .ant-alert-description {
font-size: 12px;
line-height: 1.3;
}

.verify-vehicle-form .ant-form-item {
margin-bottom: 12px;
}

.verify-vehicle-form .ant-form-item:last-child {
margin-bottom: 0;
}

@media (max-width: 768px) {
.add-vehicle-card {
min-height: auto;
}

.add-vehicle-container .ant-col {
margin-bottom: 20px;
}

.add-vehicle-container .ant-row {
gap: var(--spacing-md);
}
}
Loading
Loading