This documentation provides information on how to use the Supermarket API endpoints.
To run the project locally, follow these steps:
- Ensure that Java 17 is installed on your machine. You can download it from here.
- Clone this repository:
git clone https://github.com/MURATKAYMAZ56/supermarket.git
- Navigate to the project directory:
cd supermarket
- Build the project:
./mvnw clean install
- Run the application:
./mvnw spring-boot:run
You can use Postman (or any other client ) to make API calls to expose endpoints.
http://localhost:8080/api/products
1. Upload a File
URL: POST /
Description: Upload a CSV file containing product information. You can use supermarket.csv file (resides in resource folder) for test purposes.
Parameters: file (multipart file): CSV file containing product information.
Example: Use Postman or any REST client to make a POST request to the base URL with a multipart form-data body containing a CSV file.
2. Get All Products
URL: GET /
Description: Retrieve all products sorted by expiry date.
Response: A JSON array of product objects.
Example: Make a GET request to the base URL.
3. Get Product by Barcode
URL: GET /{barcode}
Description: Retrieve product information by its barcode.
Parameters: barcode (path parameter): The unique identifier of the product.
Response: A JSON object containing product details.
Example: Make a GET request to the base URL with the barcode appended to it.
4. Delete Product by Barcode
URL: DELETE /{barcode}
Description: Delete a product by its barcode.
Parameters: barcode (path parameter): The unique identifier of the product.
Example: Make a DELETE request to the base URL with the barcode appended
Supermarket application uses an H2 in-memory database, and you can access the H2 Console to view and query the data.
- Open your browser and go to
http://localhost:8080/h2-console
. - In the login page, set the following values:
JDBC URL: jdbc:h2:mem:testdb
User Name: sa
Password: pwd
3.Click the "Connect" button.
4. You will be redirected to the H2 Console. Here, you can view and execute SQL queries against the in-memory database.
5. To see data Click on PRODUCT
table and run below script.
SELECT * FROM PRODUCT
To run tests, execute the following command:
./mvnw test