AM-RentalManagement provides the functionality for the capability Management of the Rentals via API endpoints dedicated to individual use cases.
-
Create a copy of the
src/.env.example
file and rename it tosrc/.env
. Afterward, update the variable settings within this new file. -
In your terminal, change to the
src/
directory and execute the following command:go run .
- Execute
go test -v ./...
This document provides detailed information on the gRPC APIs for the Rental and Customer services within the rentalmanagement
package.
To install grpcurl
using Go, make sure you have Go installed on your machine. Then, run the following command:
go install github.com/fullstorydev/grpcurl/cmd/[email protected]
RentCarRequest {
startDate: google.protobuf.Timestamp;
endDate: google.protobuf.Timestamp;
vin: string;
customerId: string;
}
grpcurl -d="{\"startDate\":\"2022-02-19T00:00:00Z\",\"endDate\":\"2022-02-20T00:00:00Z\",\"vin\":\"JH4DB1561NS000569\",\"customerId\":\"CUST12345\"}" -plaintext localhost:50051 rentalmanagement.RentalService/RentCar
{
"rental": {
"rentalId": "887fdad9-ec1d-4f9a-8592-bb3308aba8b9",
"customerId": "CUST12345",
"vin": "JH4DB1561NS000569",
"startDate": {"seconds": 1645237120},
"endDate": {"seconds": 1645937120}
},
"error": null
}
{
"rental": null,
"error": {
"message": "Internal",
"details": "car with VIN JH4DB1561NS000569 is not available for the specified time range"
}
}
CancelRentalRequest {
rentalId: string;
}
grpcurl -d {\"rentalId\":\"887fdad9-ec1d-4f9a-8592-bb3308aba8b9\"} -plaintext localhost:50051 rentalmanagement.RentalService/CancelRental
{
"error": null
}
{
"error": {
"message": "Internal",
"details": "Failed to check existence of rental with ID 887fdad9-ec1d-4f9a-8592-bb3308aba8b9: Database failed to find rental with ID 887fdad9-ec1d-4f9a-8592-bb3308aba8b9"
}
}
ListAvailableCarsRequest {
startDate: google.protobuf.Timestamp;
endDate: google.protobuf.Timestamp;
}
grpcurl -d="{\"startDate\":\"2022-02-19T00:00:00Z\",\"endDate\":\"2022-02-20T00:00:00Z\"}" -plaintext localhost:50051 rentalmanagement.RentalService/ListAvailableCars
{
"cars": [
{"vin": "JH4DB1561NS000569", "brand": "Tesla", "model": "Model S"},
{"vin": "JH4DB1561NS000569", "brand": "BMW", "model": "M3"}
],
"error": null
}
{
"cars": [],
"error": {
"message": "Internal",
"details": "StartDate must be before EndDate"
}
}
ListCustomerRentalsRequest {
customerId: string;
}
grpcurl -d {\"customerId\":\"CUST12345\"} -plaintext localhost:50051 rentalmanagement.RentalService/ListCustomerRentals
{
"rentals": [
{
"rentalId": "5cc65441-39ec-48bc-8c63-bb2f6ced9ba4",
"customerId": "CUST12345",
"vin": "JH4DB1561NS000566",
"startDate": {"seconds": 1645237120},
"endDate": {"seconds": 1645937120}
},
{
"rentalId": "3ef41de2-2a19-46df-aceb-fb181d8cd552",
"customerId": "CUST12345",
"vin": "JH4DB1561NS000568",
"startDate": {"seconds": 1646237120},
"endDate": {"seconds": 1646937120}
}
],
"error": null
}
{
"rentals": [],
"error": {
"message": "InvalidArgument",
"details": "CustomerId is not valid"
}
}
RegisterCustomerRequest {
name: string;
}
grpcurl -d {\"name\":\"John Doe\"} -plaintext localhost:50051 rentalmanagement.CustomerService/RegisterCustomer
{
"customer": {
"customerId": "CUST12345",
"name": "John Doe"
}
}
DeregisterCustomerRequest {
customerId: string;
}
grpcurl -d {\"customerId\":\"CUST12345\"} -plaintext localhost:50051 rentalmanagement.CustomerService/DeregisterCustomer
{
"error": null
}