Skip to content

4ubov/transport-catalog-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

34 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Transport-Catalog-API

About :

This API is designed to implement functionality for performing tasks related to the transport company.

This API has functions:

  Vehicle:
    Returns all Vehicles 
    Returns One Vehicle by id 
    Adds new Vehicle
    Updates Vehicle in db
    Returns a filtered list of Vehicles by filters

  Category:
    Returns all Categories
    Returns One Category by id 

  Type:
    Returns all Types
    Returns One Type by id

How to start:

  1. Clone repository, and open it in IDE
  2. Create database by this file (PostgreSql syntax): 
        https://github.com/4ubov/transport-catalog-api/blob/main/src/main/resources/transport_catalog_db.sql
  3. Fill application.properties fields by your own dataSource
  4. Run project in IDE
  5. Go to the browser and go to the address: http://localhost:yourPort/ 
        Example link: http://localhost:8080/
        On this address will contain the builded version of the frontend client.
        path: resources/templates/index.html

REST API

Vehicle-Controller

Request description: Return all Vehicles from db.

⚪ GET /api/vehicle/

Request

Request body: No parameters

Response

Status code: 200
Description: Successfully found!
Media type: application/json
Json return: List<VehicleDTO>
Example value:
  [
    {
      "vehicleId": 53,
      "brand": "Mercedes",
      "model": "E250",
      "category": "A",
      "stateNumber": "F553RH58",
      "type": "Хэтчбек",
      "yearOfRealise": 2007,
      "hasTrailer": false
    },
    {
      "vehicleId": 54,
      "brand": "Mercedes",
      "model": "GLS3",
      "category": "A",
      "stateNumber": "R282AA58",
      "type": "Седан",
      "yearOfRealise": 2017,
      "hasTrailer": false
    }
  ]

Request description: Return one Vehicle from db by ID.

⚪ POST /api/vehicle/get-one

Request

Request body: application/json
Example value:
  {
    "vehicleId" : "56"
  }

Response

Status code: 200
Description: Vehicle successfully found!
Media type: application/json
Json return: VehicleDTO
Example value:
  {
    "vehicleId": 56,
    "brand": "BMW",
    "model": "E3",
    "category": "A",
    "stateNumber": "A111AA58",
    "type": "Хэтчбек",
    "yearOfRealise": 2011,
    "hasTrailer": false
}
Status code: 404
Description: Bad ID format! ("vehicleId" : "56DFE") only Long value
Media type: application/json
Example value:
  {
    "statusCode": 404,
    "message": "Entered vehicleId is incorrect type, it need be a number",
    "timestamp": 1679587416465
  }
Status code: 404
Description: Entity not found! If entered vehicleId dont exist in db.
Media type: application/json
Example value:
  {
    "statusCode": 404,
    "message": "Vehicle Entity with entered id not found!",
    "timestamp": 1679587416465
  }

Request description: Add new Vehicle.

⚪ POST /api/vehicle/add

Request

Request body: application/json
Json contain: VehicleDTO
Example value:
  {
    "brand": "Audi",
    "model": "R8",
    "category": "A",
    "stateNumber": "F287FR777",
    "type": "Седан",
    "yearOfRealise": 2012,
    "hasTrailer": false
}

Response

Status code: 200
Description: Vehicle successfully added!           
Media type: application/json
Example value:
  {
    "CREATED"
  }
Status code: 400
Description: Exceptions that will throws in case bad Validation @Valid!
Media type: application/json
Example value:
  {
    "statusCode": 400,
    "message": "brand - Поле brand не должно быть пустым!; 
        Поле model не должно быть пустым! Example: M3;
        VehicleType Entity with entered name not found!; 
        VehicleCategory Entity with entered name not found!" ,
    "timestamp": 1689438720293
  }
Status code: 400
Description: State Number is unique field, your request contain same number!
Media type: application/json
Example value:
  {
    "statusCode": 400,
    "message": "stateNumber - Транспорт с таким гос. номером уже есть в БД!; ",
    "timestamp": 1689438543459
  }

Request description: Add new Vehicle.

⚪ PUT /api/vehicle/add

Request

Request body: application/json
Example value:
Json contain: VehicleDTO
  {
    "vehicleId": "5",
    "brand": "Audi",
    "model": "RX7",
    "category": "A",
    "stateNumber": "F237FR777",
    "type": "Кроссовер",
    "yearOfRealise": 2014,
    "hasTrailer": false
}

Response

Status code: 200
Description: Vehicle successfully updated!          
Media type: application/json
Example value:
  {
    "CREATED"
  }
Status code: 400
Description: Exceptions that will throws in case bad Validation @Valid!
Media type: application/json
Example value:
  {
    "statusCode": 400,
    "message": "brand - Поле brand не должно быть пустым!; 
        Поле model не должно быть пустым! Example: M3;
        VehicleType Entity with entered name not found!; 
        VehicleCategory Entity with entered name not found!" ,
    "timestamp": 1689438720293
  }
Status code: 400
Description: State Number is unique field, your request contain same number!
Media type: application/json
Example value:
  {
    "statusCode": 400,
    "message": "stateNumber - Транспорт с таким гос. номером уже есть в БД!; ",
    "timestamp": 1689438543459
  }

Request description: Filter Vehicles by imputed filters.

⚪ POST /api/vehicle/filter

Request

Request body: application/json
Json contain: Map<String, String>
Example value:
  {
    "brand": "Audi",
    "type": "Седан"
  }

Response

Status code: 200
Description: Vehicles successfully filtered!           
Media type: application/json
Json return: List<VehicleDTO>
Example value:
  [
    {
      "vehicleId": 67,
      "brand": "Audi",
      "model": "R8",
      "category": "A",
      "stateNumber": "F287FR777",
      "type": "Седан",
      "yearOfRealise": 2012,
      "hasTrailer": false
  },
  {
    "vehicleId": 58,
    "brand": "Audi",
    "model": "Q7",
    "category": "A",
    "stateNumber": "G283GR777",
    "type": "Седан",
    "yearOfRealise": 2022,
    "hasTrailer": false
  }
]
Status code: 400
Description: Exceptions that will throws if sended category or type dont exist in db!
                Because VehicleCategory and VehicleType data in db added manually.
Media type: application/json
Example value:
  {
    "statusCode": 400,
    "message": 
        VehicleType Entity with entered name not found!; 
        VehicleCategory Entity with entered name not found!" ,
    "timestamp": 1689438720293
  }

Type-Controller

Request description: Return all VehicleType from db.

⚪ GET /api/type/

Request

Request body: No parameters

Response

Status code: 200
Description: Successfully found!
Media type: application/json
Json return: List<VehicleTypeDTO>
Example value:
  [
    {
      "typeId": 1,
      "typeName": "Седан"
    },
    {
      "typeId": 2,
      "typeName": "Хэтчбек"
    },
    {
      "typeId": 3,
      "typeName": "Минивэн"
    }
  ]

Request description: Return one VehicleType from db by ID.

⚪ POST /api/type/get-one

Request

Request body: application/json
Request contain: Long id
Example value:

    2

Response

Status code: 200
Description: Vehicle Type successfully found!
Media type: application/json
Json return: VehicleTypeDTO
Example value:
  {
    "typeId": 2,
    "typeName": "Хэтчбек"
  }
Status code: 400
Description: VehicleType not Found!
Media type: application/json
Example value:
  {
    "statusCode": 400,
    "message": "VehicleType Entity with entered ID not found!",
    "timestamp": 1679587416465
  }

Category-Controller

Request description: Return all VehicleCategory from db.

⚪ GET /api/category/

Request

Request body: No parameters

Response

Status code: 200
Description: Successfully found!
Media type: application/json
Json return: List<VehicleCategoryDTO>
Example value:
  [
    {
      "categoryId": 1,
      "categoryName": "A"
    },
    {
      "categoryId": 2,
      "categoryName": "B"
    },
    {
      "categoryId": 3,
      "categoryName": "C"
    }
  ]

Request description: Return one VehicleCategory from db by ID.

⚪ POST /api/category/get-one

Request

Request body: application/json
Request contain: Long id
Example value:

    2

Response

Status code: 200
Description: Vehicle Type successfully found!
Media type: application/json
Json return: VehicleTypeDTO
Example value:
  {
    "categoryId": 2,
    "categoryName": "B"
  }
Status code: 400
Description: VehicleType not Found!
Media type: application/json
Example value:
  {
    "statusCode": 400,
    "message": "VehicleCategory Entity with entered ID not found!",
    "timestamp": 1679587413465
  }

Schemas:

VehicleDTO

⚪ vehicleId
    type: integer64
⚪ brand
    type: string
⚪ model
    type: string
⚪ category
    type: string
⚪ stateNumber
    type: string
⚪ type
    type: integer32
⚪ hasTrailer
    type: boolean

VehicleTypeDTO

⚪ typeId
    type: integer64
⚪ typeName
    type: string

VehicleCategoryDTO

⚪ categoryId
    type: integer64
⚪ categoryName
    type: string

transport_catalog_db DataBase : Link to db file

image image

UI screenshots

Starter page: "http://localhost:8080/"

image

Edit page

image

Add new Vehicle page

image

Drop-down menu view

image


Client (Frontend) on React JS, that implements this REST-API - ReactJs-Client

Releases

No releases published

Packages

No packages published