Skip to content

lcsmota/BikeApi

Repository files navigation

BikeApi

🌐 Status

Finished project βœ…

🧰 Prerequisites

  • .NET 6.0 or +

  • Connection string to SQLServer in BikeApi/appsettings.json named as Default

Database

Create a database in SQLServer that contains the table created from the following script:

CREATE DATABASE BikeApiDapper
GO

Use BikeApiDapper
GO

CREATE TABLE Categories(
	Id INT PRIMARY KEY IDENTITY(1, 1),
	Name VARCHAR(80) NOT NULL
);
GO

CREATE TABLE Brands(
	Id INT PRIMARY KEY IDENTITY(1, 1),
	Name VARCHAR(80) NOT NULL
);
GO

CREATE TABLE Products(
	Id INT PRIMARY KEY IDENTITY(1, 1),
	Name VARCHAR(80) NOT NULL,
	ModelYear SMALLINT NOT NULL,
	Price DECIMAL(10, 2) NOT NULL,
	BrandId INT NOT NULL,
	CategoryId INT NOT NULL,
	
	CONSTRAINT [FK_Products_Category] FOREIGN KEY (CategoryId) 
        REFERENCES Categories(Id),

	CONSTRAINT [FK_Products_Brand]FOREIGN KEY (BrandId) 
        REFERENCES Brands(Id)
);
GO

Relationships

+--------------+        +-------------+        +--------------+
|   Categories | 1    * |    Products | *    1 |     Brands   |
+--------------+        +-------------+        +--------------+
|     Id       |<-------|      Id     |------->|      Id      |
|     Name     |        |     Name    |        |     Name     |
|              |        |  ModelYear  |        |              |
|              |        |    Price    |        |              |
+--------------+        |  BrandId    |        +--------------+
                        | CategoryId  |
                        +-------------+

πŸ”§ Installation

$ git clone https://github.com/lcsmota/BikeApi.git

$ cd BikeApi/

$ dotnet restore

$ dotnet run

Server listenning at https://localhost:7250/swagger or https://localhost:7250/api/v1/Products, https://localhost:7250/api/v1/Brands and https://localhost:7250/api/v1/Categories

πŸ“« Routes for Products

Return all objects (Bikes)

  GET https://localhost:7250/api/v1/Products

βš™οΈ Status Code:

  (200) - OK
  (404) - Not Found

πŸ“¬ Postman

πŸ“ Swagger

Return only one object (Bike)

  GET https://localhost:7250/api/v1/Products/${id}
Parameter Type Description
id int Mandatory. The ID of the object you want to view

βš™οΈ Status Code:

  (200) - OK
  (404) - Not Found

πŸ“¬ Postman

πŸ“ Swagger

Insert a new object (Bike)

  POST https://localhost:7250/api/v1/Products

πŸ“¨ body:

{
  "name": "Trek 820",
  "modelYear": 2016,
  "price": 379.99,
  "brandId": 9,
  "categoryId": 6
}

🧾 response:

{
   "modelYear": 2016,
    "price": 379.99,
    "brandId": 9,
    "categoryId": 6,
    "id": 12,
    "name": "Trek 820"
}

βš™οΈ Status Code:

  (201) - Created

πŸ“¬ Postman

πŸ“ Swagger

Update an object (Bike)

  PUT https://localhost:7250/api/v1/Products/${id}
Parameter Type Description
id int Mandatory. The ID of the object you want to update

πŸ“¨ body:

{
  "name": "Trek 820",
  "price": 399.50
}

🧾 response:

βš™οΈ Status Code:

  (204) - No Content
  (404) - Not Found

πŸ“¬ Postman

πŸ“ Swagger

Delete an object (Bike)

  DELETE https://localhost:7250/api/v1/Products/${id}
Parameter Type Description
id int Mandatory. The ID of the object you want to delete

πŸ“¨ body:

🧾 response:

βš™οΈ Status Code:

  (204) - No Content
  (404) - Not Found

πŸ“¬ Postman

πŸ“ Swagger

πŸ“« Routes for Categories

Return all objects (Categories)

  GET https://localhost:7250/api/v1/Categories

βš™οΈ Status Code:

  (200) - OK
  (404) - Not Found

πŸ“¬ Postman

πŸ“ Swagger

Return only one object (Category)

  GET https://localhost:7250/api/v1/Categories/${id}
Parameter Type Description
id int Mandatory. The ID of the object you want to view

βš™οΈ Status Code:

  (200) - OK
  (404) - Not Found

πŸ“¬ Postman

πŸ“ Swagger

Return category with products (Bikes)

  GET https://localhost:7250/api/v1/Categories/${id}/multipleresults
Parameter Type Description
id int Mandatory. The ID of the object you want to view

βš™οΈ Status Code:

  (200) - OK

πŸ“¬ Postman

πŸ“ Swagger

Return all categories with prodcuts (Bikes)

  GET https://localhost:7250/api/v1/Categories/multiplemapping

βš™οΈ Status Code:

  (200) - OK

πŸ“¬ Postman

πŸ“ Swagger

Insert a new object (Category)

  POST https://localhost:7250/api/v1/Categories

πŸ“¨ body:

{
    "name": "Children Bicycles"
}

🧾 response:

{
    "products": [],
    "id": 9,
    "name": "Children Bicycles"
}

βš™οΈ Status Code:

  (201) - Created

πŸ“¬ Postman

πŸ“ Swagger

Update an object (Category)

  PUT https://localhost:7250/api/v1/Categories/${id}
Parameter Type Description
id int Mandatory. The ID of the object you want to update

πŸ“¨ body:

{
    "name": "Cyclocross Bicycles"
}

🧾 response:

βš™οΈ Status Code:

  (204) - No Content
  (404) - Not Found

πŸ“¬ Postman

πŸ“ Swagger

Delete an object (Category)

  DELETE https://localhost:7250/api/v1/Categories/${id}
Parameter Type Description
id int Mandatory. The ID of the object you want to delete

πŸ“¨ body:

🧾 response:

βš™οΈ Status Code:

  (204) - No Content
  (404) - Not Found

πŸ“¬ Postman

πŸ“ Swagger

πŸ“« Routes for Brands

Return all objects (Brands)

  GET https://localhost:7250/api/v1/Brands

βš™οΈ Status Code:

  (200) - OK
  (404) - Not Found

πŸ“¬ Postman

πŸ“ Swagger

Return only one object (Brand)

  GET https://localhost:7250/api/v1/Brands/${id}
Parameter Type Description
id int Mandatory. The ID of the object you want to view

βš™οΈ Status Code:

  (200) - OK
  (404) - Not Found

πŸ“¬ Postman

πŸ“ Swagger

Return brand with products (Bikes)

  GET https://localhost:7250/api/v1/Brands/${id}/multipleresults
Parameter Type Description
id int Mandatory. The ID of the object you want to view

βš™οΈ Status Code:

  (200) - OK

πŸ“¬ Postman

πŸ“ Swagger

Return all brands with prodcuts (Bikes)

  GET https://localhost:7250/api/v1/Brands/multiplemapping

βš™οΈ Status Code:

  (200) - OK

πŸ“¬ Postman

πŸ“ Swagger

Insert a new object (Brand)

  POST https://localhost:7250/api/v1/Brands

πŸ“¨ body:

{
    "name": "Trek"
}

🧾 response:

{
    "products": [],
    "id": 11,
    "name": "Trek"
}

βš™οΈ Status Code:

  (201) - Created

πŸ“¬ Postman

πŸ“ Swagger

Update an object (Brand)

  PUT https://localhost:7250/api/v1/Brands/${id}
Parameter Type Description
id int Mandatory. The ID of the object you want to update

πŸ“¨ body:

{
    "name": "Sun Bicycles"
}

🧾 response:

βš™οΈ Status Code:

  (204) - No Content
  (404) - Not Found

πŸ“¬ Postman

πŸ“ Swagger

Delete an object (Brand)

  DELETE https://localhost:7250/api/v1/Brands/${id}
Parameter Type Description
id int Mandatory. The ID of the object you want to delete

πŸ“¨ body:

🧾 response:

βš™οΈ Status Code:

  (204) - No Content
  (404) - Not Found

πŸ“¬ Postman

πŸ“ Swagger

πŸ”¨ Tools used

πŸ–₯️ Technologies and practices used

  • C# 10
  • .NET CORE 6
  • SQL SERVER
  • Dapper
  • Swagger
  • DTOs
  • Repository Pattern
  • Dependency injection
  • POO

πŸ“– Features

Registration, Listing, Update and Removal