Gravacao.de.tela.de.07-04-2023.11.53.24.webm
Finished project β
-
.NET 6.0 or +
-
Connection string to SQLServer in StoreCRUD/appsettings.json named as Default
Create a database in SQLServer that contains the table created from the following script:
CREATE TABLE [Categories] (
[Id] int NOT NULL IDENTITY,
[Title] nvarchar(80) NOT NULL,
CONSTRAINT [PK_Categories] PRIMARY KEY ([Id])
);
GO
CREATE TABLE [Users] (
[Id] int NOT NULL IDENTITY,
[UserName] nvarchar(80) NOT NULL,
[Password] nvarchar(max) NOT NULL,
[Role] nvarchar(max) NOT NULL,
CONSTRAINT [PK_Users] PRIMARY KEY ([Id])
);
GO
CREATE TABLE [Products] (
[Id] int NOT NULL IDENTITY,
[Title] nvarchar(80) NOT NULL,
[Description] nvarchar(255) NOT NULL,
[Price] decimal(18,2) NOT NULL,
[CategoryId] int NOT NULL,
CONSTRAINT [PK_Products] PRIMARY KEY ([Id]),
CONSTRAINT [FK_Products_Categories_CategoryId] FOREIGN KEY ([CategoryId]) REFERENCES [Categories] ([Id]) ON DELETE CASCADE
);
GO
+--------------+ +-------------+ +--------------+
| Categories | 1 * | Products | | Users |
+--------------+ +-------------+ +--------------+
| Id |<-------| Id | | Id |
| Title | | Title | | UserName |
| | | Description | | Password |
| | | Price | | Role |
+--------------+ | CategoryId | +--------------+
+-------------+
$ git clone https://github.com/lcsmota/StoreCRUD.git
$ cd StoreCRUD/
$ dotnet restore
$ dotnet run
Server listenning at https://localhost:7195/swagger or https://localhost:7195/api/v1/Users, https://localhost:7195/api/v1/Products and https://localhost:7195/api/v1/Categories
GET https://localhost:7195/api/v1/Users
βοΈ Status Code:
(200) - OK
(401) - Unauthorized
GET https://localhost:7195/api/v1/Users/${id}
Parameter | Type | Description |
---|---|---|
id |
int |
Mandatory. The ID of the object you want to view |
βοΈ Status Code:
(200) - OK
(401) - Unauthorized
(404) - Not Found
POST https://localhost:7195/api/v1/Users
π¨ body:
{
"userName": "maria",
"password": "maria123456"
}
π§Ύ response:
{
"id": 1002,
"userName": "maria",
"password": "",
"role": "employee"
}
βοΈ Status Code:
(200) - OK
(400) - Bad Request
POST https://localhost:7195/api/v1/Users/login
π¨ body:
{
"userName": "maria",
"password": "M@r1a*&$123"
}
π§Ύ response:
{
"user": {
"id": 1002,
"userName": "maria",
"password": "",
"role": "employee"
},
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYW1laWQiOiIxMDAyIiwidW5pcXVlX25hbWUiOiJtYXJpYSIsInJvbGUiOiJlbXBsb3llZSIsIm5iZiI6MTY4MDgyOTk2MCwiZXhwIjoxNjgwODMxMTYwLCJpYXQiOjE2ODA4Mjk5NjB9.F4U_Xq5IX3nK8L0jnfy7FFYz0Alir_YM_RPRxK4RckE"
}
βοΈ Status Code:
(200) - OK
(404) - Not Found
PUT https://localhost:7195/api/v1/Users/${id}
Parameter | Type | Description |
---|---|---|
id |
int |
Mandatory. The ID of the object you want to update |
π¨ body:
{
"id": 1002,
"userName": "maria",
"password": "M@r1a*&$123",
"role": "employee"
}
π§Ύ response:
βοΈ Status Code:
(204) - No Content
(400) - Bad Request
(401) - Unauthorized
GET https://localhost:7195/api/v1/Products
βοΈ Status Code:
(200) - OK
GET https://localhost:7195/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
GET https://localhost:7195/api/v1/Products/productsWithCateg
βοΈ Status Code:
(200) - OK
GET https://localhost:7195/api/v1/Products/${id}/productsWithCateg
Parameter | Type | Description |
---|---|---|
id |
int |
Mandatory. The ID of the object you want to view |
βοΈ Status Code:
(200) - OK
(404) - Not Found
GET https://localhost:7195/api/v1/Products/categories/${id}
Parameter | Type | Description |
---|---|---|
id |
int |
Mandatory. The ID of the object you want to view |
βοΈ Status Code:
(200) - OK
POST https://localhost:7195/api/v1/Products
π¨ body:
{
"title": "C# Basics",
"description": "Learn C# Fundamentals by Coding",
"price": 150,
"categoryId": 1
}
π§Ύ response:
{
"id": 3002,
"title": "C# Basics",
"description": "Learn C# Fundamentals by Coding",
"price": 150,
"categoryId": 1
}
βοΈ Status Code:
(201) - Created
(400) - Bad Request
PUT https://localhost:7195/api/v1/Products/${id}
Parameter | Type | Description |
---|---|---|
id |
int |
Mandatory. The ID of the object you want to update |
π¨ body:
{
"id": 3002,
"title": "C# 10 Basics",
"description": "Learn C# Fundamentals by Coding",
"price": 360,
"categoryId": 1,
"category": {
"id": 1,
"title": "Course"
}
}
π§Ύ response:
βοΈ Status Code:
(204) - No Content
(400) - Bad Request
(401) - Unauthorized
DELETE https://localhost:7195/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
(401) - Unauthorized
(404) - Not Found
(400) - Bad Request
GET https://localhost:7195/api/v1/Categories
βοΈ Status Code:
(200) - OK
GET https://localhost:7195/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
POST https://localhost:7195/api/v1/Categories
π¨ body:
{
"title": "Bootcamp"
}
π§Ύ response:
{
"id": 2005,
"title": "Bootcamp"
}
βοΈ Status Code:
(200) - Ok
(400) - Bad Request
(401) - Unauthorized
PUT https://localhost:7195/api/v1/Categories/${id}
Parameter | Type | Description |
---|---|---|
id |
int |
Mandatory. The ID of the object you want to update |
π¨ body:
{
"id": "2005",
"title": "Bootcamps"
}
π§Ύ response:
βοΈ Status Code:
(204) - No Content
(400) - Bad Request
(401) - Unauthorized
DELETE https://localhost:7195/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
(401) - Unauthorized
(400) - Bad Request
- C# 10
- .NET CORE 6
- SQL SERVER
- Entity Framework 7
- Code First
- Token JWT
- Swagger
- DTOs
- Dependency injection
- POO
Registration, Listing, Update and Removal