This is a Web Service application allowing you to to CRUD operations on products. It also contains a call to an external API to convert prices into another currency.
Using Intellij and JBoss/Wildfly, the urls are
http://localhost:8080/EStore_02-1.0-SNAPSHOT/api/v1/
for the APIhttp://localhost:8080/EStore_02-1.0-SNAPSHOT/
for a simple website displaying a list of the current products in the database
To install this project, you need to clone it, and create the datasource in your server (This was made using JBoss/Wildfly).
There is also a .sql file to generate some dummy data once you have create the schema estore_bd
on your database.
For the first launch, you need to modify the persistence.xml
file to put the action to drop-and-create
instead of none
. Once you've launched it once, you can put it back to none
typical returned objects in JSON form:
{
"productId": 2,
"label": "Lave Vaisselle",
"category": "Electroménager",
"priceInEuro": 219.98,
"stock": 8,
"comments": []
}
and xml form:
<product>
<category>Electroménager</category>
<label>Lave Vaisselle</label>
<priceInEuro>219.98</priceInEuro>
<productId>2</productId>
<stock>8</stock>
</product>
About the price conversion while getting multiple products, we decided, rather than converting prices one by one for each product by requesting the api, we get the conversion rate a single time and use it to update all products in the list. This approach saves us some requests, mainly to stay under the request limit, it also optimises delay during the operation a bit.
The original project was an eclipse project, which we extracted to be able to create a maven project for easy dependency managing. We tried to keep as much of the original structure as possible (segmenting business, DAO, models and webservices), only making minor adjustments to the DAO and business to add needed features like the currency part.
get the information of all the products stored in the database
- application/xml
- application/json
category
: get all products of a specific category (example : "Alimentation")currency
: get the result with priceInCurrency in a different currency with its code (example : "USD")sort
: sort the result in ascending or descending order ("asc" or "desc");
/products?currency=USD?sort=asc?category=Alimentation
This specific query with the GET verb requests all products of the "Alimentation" category, with prices converted to USD, and sorts the resulting list by ascending price.
get the information for the product with a given id
- application/xml
- application/json
currency
: get the result with priceInCurrency in a different currency with its code (example : "USD")
/products/15?currency=USD
This specific query with the GET verb requests the product of Id 15 with its price converted to USD.
delete a specific product with the given id
. Will also delete any comments the product might have.
/products/18
This specific query with the DELETE verb requests the deletion of the product of id 18.
create an entirely new product
- application/xml
- application/json
/products
This specific query with the POST verb with an included product in "typical" format (as shown in the beginning examples) requests the creation of a product with id auto generated.
completely modify the product with a given id
- application/xml
- application/json
/products/28
This specific query with the PUT verb with an included product in "typical" format (as shown in the beginning examples) requests the modification of the product of id 28 to match the product object that was sent.
partially modify the product with a given id
- application/xml
- application/json
/products/28
This specific query with the PATCH verb with an included product in "typical" format (as shown in the beginning examples) requests the modification of the product of id 28 to match the product object that was sent, the object can be incomplete, in that case the unentered values will remain the same.
get all the comments of a product with a given id
- application/xml
- application/json
/products/3/comments
This specific query with the GET verb requests all the comments about the product of Id 3, in a arbitrarily sorted list.