Open Hodzinets opened 2 years ago
{ "customerId": "ALFKI", "employeeId": 1, "freight": true, "orderDetails": [ { "discount": 0, "productId": 1, "quantity": 0 } ], "requiredDate": "2022-01-15", "shipAddress": "string", "shipCity": "string", "shipCountry": "string", "shipName": "string", "shipPostalCode": "string", "shipRegion": "string", "shipperId": 1 }
Po uruchomieniu dockera, należy udać się do http://localhost:8080/swagger-ui/#/. Załóżmy, że chcemy dodać nowego dostawcę: Supplier
Mamy do dyspozycji następujące operacje:
Tworzymy suppliera korzystając z POST /supplier
z następującym body:
{
"address": "ul. Krakowska",
"city": "Kraków",
"companyName": "Polimex",
"contactName": "Jan Kowalski",
"contactTitle": "Pan",
"country": "Polska",
"fax": "1234512323",
"homePage": "polimex.pl",
"phone": "+48 501 123 435",
"postalCode": "31-070",
"region": "malopolskie"
}
Po uruchomieniu dostajemy odpowiedź z nowo stworzonym dostawcą oraz kodem HTTP 200.
Nasz nowo dodany dostawca pojawia się w kolekcji dostawców zwracanej przez GET /suppliers
:
Nasz nowo dodany dostawca otrzymał id = 31. Możemy za jego pomocą wysłać zapytanie o dane dostawcy o tym id korzystając z GET /supplier/{supplierId}
. Otrzymujemy kompletną strukturę reprezentującą dostawcę w bazie danych:
{
"id": 31,
"companyName": "Polimex",
"contactName": "Jan Kowalski",
"contactTitle": "Pan",
"address": "ul. Krakowska",
"city": "Kraków",
"region": "malopolskie",
"postalCode": "31-070",
"country": "Polska",
"phone": "+48 501 123 435",
"fax": "1234512323",
"homePage": "polimex.pl"
}
Chcąc zupdatować adres tego dostawcy, wykorzystamy endpoint PUT /supplier/{supplierId}
. Wysyłamy zapytanie z parametrem supplierId=31
oraz BODY, w którym znajduje się nowy adres:
{
"companyName": "Polimex",
"contactName": "Jan Kowalski",
"contactTitle": "Pan",
"address": "ul. Warszawska 2/3",
"city": "Kraków",
"region": "malopolskie",
"postalCode": "31-070",
"country": "Polska",
"phone": "+48 501 123 435",
"fax": "1234512323",
"homePage": "polimex.pl"
}
Wreszcie, aby usunąć danego dostawcę możemy sykorzystać DELETE /supplier/{supplierId}
wraz z supplierId=31
Przykładowe operacje na bazie danych - Order
Załóżmy, że chcemy dodać nowe zamówienie. Wykorzystać do tego możemy POST /order
z następującym BODY:
{
"customerId": "ALFKI",
"employeeId": 1,
"freight": true,
"orderDetails": [
{
"discount": 30,
"productId": 1,
"quantity": 1
}
],
"requiredDate": "2022-01-15",
"shipAddress": "ul. Krakowska 2/3",
"shipCity": "Kraków",
"shipCountry": "Polska",
"shipName": "Jan Kowalski",
"shipPostalCode": "31-550",
"shipRegion": "małopolskie",
"shipperId": 1
}
W odpowiedzi otrzymujemy kompletną strukturę nowego zamówienia:
{
"id": 11080,
"customer": {
"id": "ALFKI",
"companyName": "Alfreds Futterkiste",
"contactName": "Maria Anders",
"contactTitle": null,
"address": "Obere Str. 57",
"city": "Berlin",
"region": "",
"postalCode": "12209",
"country": "Germany",
"phone": "030-0074321",
"fax": "030-0076545",
"customerDemographics": []
},
"employee": {
"id": 1,
"lastName": "Davolio",
"firstName": "Nancy",
"title": "Sales Representative",
"titleOfCourtesy": "Ms.",
"birthDate": "1968-12-08",
"hireDate": "1992-05-01",
"address": "507 - 20th Ave. E.\\r\\nApt. 2A",
"city": "Seattle",
"region": "WA",
"postalCode": "98122",
"country": "United States",
"homePhone": "(206) 555-9857",
"extension": "5467",
"photo": "",
"notes": "Education includes a BA in psychology from Colorado State University. She also completed \"The Art of the Cold Call.\" Nancy is a member of Toastmasters International.",
"reportsTo": 2,
"photoPath": null,
"territories": []
},
"orderDate": "2022-01-22",
"requiredDate": "2022-01-15",
"shippedDate": null,
"shipper": {
"id": 1,
"companyName": "Speedy Express",
"phone": "(503) 555-9831"
},
"freight": true,
"shipName": "Jan Kowalski",
"shipAddress": "ul. Krakowska 2/3",
"shipCity": "Kraków",
"shipRegion": "małopolskie",
"shipPostalCode": "31-550",
"shipCountry": "Polska",
"orderDetails": [
{
"product": {
"id": 1,
"productName": "Chai",
"supplier": {
"id": 1,
"companyName": "Exotic Liquids",
"contactName": "Charlotte Cooper",
"contactTitle": "Purchasing Manager",
"address": "49 Gilbert St.",
"city": "London",
"region": null,
"postalCode": "EC1 4SD",
"country": "United Kingdom",
"phone": "(171) 555-2222",
"fax": null,
"homePage": null
},
"category": {
"id": 1,
"categoryName": "Beverages",
"description": "Soft drinks, coffees, teas, beers, and ales",
"picture": null
},
"quantityPerUnit": "10 boxes x 20 bags",
"unitPrice": 10,
"unitsInStock": 38,
"unitsOnOrder": 1,
"reorderLevel": 10,
"discontinued": false
},
"unitPrice": 10,
"quantity": 1,
"discount": 30
}
]
}
Chcąc zakupić więcej produktów, niż jest dostępnych w magazynie, wysyłamy przy identycznym zapytaniu jak powyżej dodatkowo "quantity": 10000
. Otrzymujemy odpowiedź:
{
"timestamp": "2022-01-22T09:52:39.875+00:00",
"status": 400,
"error": "Bad Request",
"message": "There is no 10000 products 1 in stock",
"path": "/order"
}
Podobnie dla nieistniejącego produktu "productId": 9876
:
{
"timestamp": "2022-01-22T09:54:41.645+00:00",
"status": 404,
"error": "Not Found",
"message": "Product 9876 not found",
"path": "/order"
}
Nieistniejący "shipperId": 9876
:
{
"timestamp": "2022-01-22T09:55:44.251+00:00",
"status": 404,
"error": "Not Found",
"message": "Shipper not found",
"path": "/order"
}