Giter Club home page Giter Club logo

carrentalapp's Introduction

3.MicroserviceEngineering

AM-RentalManagement provides the functionality for the capability Management of the Rentals via API endpoints dedicated to individual use cases.

Design AM-RentalManagement

API Diagram

Run AM-RentalManagement

  1. Create a copy of the src/.env.example file and rename it to src/.env. Afterward, update the variable settings within this new file.

  2. In your terminal, change to the src/ directory and execute the following command:

    go run .
    

Run Tests

  1. Execute go test -v ./...

Rental and Customer Service API

๐Ÿ“Œ Overview

This document provides detailed information on the gRPC APIs for the Rental and Customer services within the rentalmanagement package.


Installing grpcurl

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]

๐Ÿš— Rental Service

RentCar

Request Format

RentCarRequest {
    startDate: google.protobuf.Timestamp;
    endDate: google.protobuf.Timestamp;
    vin: string;
    customerId: string;
}

๐Ÿ“Ÿ Command Line Request

grpcurl -d="{\"startDate\":\"2022-02-19T00:00:00Z\",\"endDate\":\"2022-02-20T00:00:00Z\",\"vin\":\"JH4DB1561NS000569\",\"customerId\":\"CUST12345\"}" -plaintext localhost:50051 rentalmanagement.RentalService/RentCar

๐Ÿ“ค Response Body

{
    "rental": {
        "rentalId": "887fdad9-ec1d-4f9a-8592-bb3308aba8b9",
        "customerId": "CUST12345",
        "vin": "JH4DB1561NS000569",
        "startDate": {"seconds": 1645237120},
        "endDate": {"seconds": 1645937120}
    },
    "error": null
}
๐Ÿ“ค Error Response Body
{
    "rental": null,
    "error": {
        "message": "Internal",
        "details": "car with VIN JH4DB1561NS000569 is not available for the specified time range"
    }
}

CancelRental

Request Format

CancelRentalRequest {
    rentalId: string;
}

๐Ÿ“Ÿ Command Line Request

grpcurl -d {\"rentalId\":\"887fdad9-ec1d-4f9a-8592-bb3308aba8b9\"} -plaintext localhost:50051 rentalmanagement.RentalService/CancelRental

๐Ÿ“ค Response Body

{
    "error": null
}
๐Ÿ“ค Error Response Body
{
    "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"
    }
}

ListAvailableCars

Request Format

ListAvailableCarsRequest {
    startDate: google.protobuf.Timestamp;
    endDate: google.protobuf.Timestamp;
}

๐Ÿ“Ÿ Command Line Request

grpcurl -d="{\"startDate\":\"2022-02-19T00:00:00Z\",\"endDate\":\"2022-02-20T00:00:00Z\"}" -plaintext localhost:50051 rentalmanagement.RentalService/ListAvailableCars

๐Ÿ“ค Response Body

{
    "cars": [
        {"vin": "JH4DB1561NS000569", "brand": "Tesla", "model": "Model S"},
        {"vin": "JH4DB1561NS000569", "brand": "BMW", "model": "M3"}
    ],
    "error": null
}
๐Ÿ“ค Error Response Body
{
    "cars": [],
    "error": {
        "message": "Internal",
        "details": "StartDate must be before EndDate"
    }
}

ListCustomerRentals

Request Format

ListCustomerRentalsRequest {
    customerId: string;
}

๐Ÿ“Ÿ Command Line Request

grpcurl -d {\"customerId\":\"CUST12345\"} -plaintext localhost:50051 rentalmanagement.RentalService/ListCustomerRentals

๐Ÿ“ค Response Body

{
    "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
}

๐Ÿ“ค Error Response Body

{
    "rentals": [],
    "error": {
        "message": "InvalidArgument",
        "details": "CustomerId is not valid"
    }
}

๐Ÿ‘ฅ Customer Service

RegisterCustomer

Request Format

RegisterCustomerRequest {
    name: string;
}

๐Ÿ“Ÿ Command Line Request

grpcurl -d {\"name\":\"John Doe\"} -plaintext localhost:50051 rentalmanagement.CustomerService/RegisterCustomer

๐Ÿ“ค Response Body

{
    "customer": {
        "customerId": "CUST12345",
        "name": "John Doe"
    }
}

DeregisterCustomer

Request Format

DeregisterCustomerRequest {
    customerId: string;
}

๐Ÿ“Ÿ Command Line Request

grpcurl -d {\"customerId\":\"CUST12345\"} -plaintext localhost:50051 rentalmanagement.CustomerService/DeregisterCustomer

๐Ÿ“ค Response Body

{
    "error": null
}

carrentalapp's People

Contributors

abdelrahmanelayashy avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.