Archived
1
0
This repository has been archived on 2023-12-01. You can view files and clone it, but cannot push or open issues or pull requests.
MindBoxApi/README.md
2023-11-14 12:00:03 +03:00

51 lines
1.7 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

## База данных
### Таблица со списком категорий
```sql
CREATE TABLE categories(
category_id INT NOT NULL PRIMARY KEY,
category_name VARCHAR(10)
);
```
### Таблица со списком продуктов
```sql
CREATE TABLE products(
product_id INT NOT NULL PRIMARY KEY,
product_name VARCHAR(10)
);
```
### Таблица товара с категориями
```sql
CREATE TABLE grocery_store(
product_id INT,
category_id INT,
FOREIGN KEY (product_id) REFERENCES products (product_id),
FOREIGN KEY (category_id) REFERENCES categories (category_id)
);
```
## Выбор всех пар "Имя продукта - Имя категории" (основное задание)
Запрос
```sql
SELECT product_name AS product, category_name AS category FROM products
LEFT JOIN grocery_store ON grocery_store.product_id = products.product_id
LEFT JOIN categories ON grocery_store.category_id = categories.category_id
ORDER BY product;
```
```ps
Invoke-RestMethod https://mindbox.cebotari.ru/item -Method GET
```
## Дополнительно реализованы
### Добавление новой категории
```ps
Invoke-RestMethod https://mindbox.cebotari.ru/category -Method POST -Body (@{Id=5; Name="Black"} | ConvertTo-Json) -ContentType "application/json"
```
### Добавление нового продукта
```ps
Invoke-RestMethod http://mindbox.cebotari.ru/product -Method POST -Body (@{Id=5; Name="Olives"} | ConvertTo-Json) -ContentType "application/json"
```
### Добавление новой нового товара
```ps
Invoke-RestMethod -Uri "http://mindbox.cebotari.ru/item?productId=5&categoryId=5" -Method POST
```