# HackMyCart The most hackable Web Shop! ## How to use ### Prepare development environment 1. Install node.js ```bash sudo apt install npm # If outdated version: sudo npm install -g n sudo n stable ``` 2. Download + extract the project 3. Open the root folder with VS Code (recommended) 4. Open the bash inside VS Code, navigate to the `software/` folder and install all necessary packages: ```bash npm i ``` ### Test/development There are multiple commands to test parts or the whole project: - `npm run dev`: Starts the Vue frontend only - `npm run server`: Starts the ExpressJs backend only - `npm run serve`: Starts front- and backend The frontend runs on `http://localhost:5173/` and the backend on `http://localhost:3000/` ### Compile for production TODO ## Structure ### Database ![database-erm](misc/images//database.png) ### Backend API endpoints The application host it's data in a SQLite database. The access is managed by an [ExpressJs](https://expressjs.com/) server which offers many REST-API endpoints for the frontend. The REST-API server runs on port 3000. #### `/api`
Server check

Description

Check if server is available

Request

GET /api
Parameter Required? Description
- - -
Database reset

Description

Delete and refill the database with example values

Request

GET /api/resetdatabase
Parameter Required? Description
- - -
#### `/categories`
All categories

Description

Get all categories

Request

GET /categories
Parameter Required? Description
- - -

Example Response

```json [ { "id": 0, "name": "Electronic", "icon": "mdi-chip", "createdAt": "2024-09-13T07:51:40.118Z", "updatedAt": "2024-09-13T07:51:40.118Z" }, { "id": 1, "name": "Sports", "icon": "mdi-soccer", "createdAt": "2024-09-13T07:51:40.118Z", "updatedAt": "2024-09-13T07:51:40.118Z" } ] ```
Add new category

Description

Add a new category

Request

POST /categories
Body Parameters Required? Description
name Yes Name of the category
icon Yes Material Design Icon
Delete category

Description

Delete a category by it's id

Request

DELETE /categories/:id
Parameter Required? Description
id Yes Database ID of CategoryModel
#### `/products`
All products

Description

Get all products

Request

GET /products
Parameter Required? Description
- - -

Example Response

```json [ { "id": 0, "brand": "Lenovo", "name": "Thinkpad T14", "categoryId": 0, "price": 799.99, "discount": 10, "rating": 4.6, "imageUrl": "thinkpad-t14s.jpg", "description": "Die stabile Arbeitsmaschine. Mit AMD Ryzen 7 89029U, 128 GB RAM und 8 TB M.2 SSD!", "createdAt": "2024-09-13T07:51:40.119Z", "updatedAt": "2024-09-13T07:51:40.119Z", "category": { "id": 0, "name": "Electronic", "icon": "mdi-chip", "createdAt": "2024-09-13T07:51:40.118Z", "updatedAt": "2024-09-13T07:51:40.118Z" } } ] ```
Request one product

Description

Get a specific product by it's id

Request

GET /products/:id
Parameter Required? Description
id Yes ID of the product in the database table

Example Response

```json { "id": 0, "brand": "Lenovo", "name": "Thinkpad T14", "categoryId": 0, "price": 799.99, "discount": 10, "rating": 4.6, "imageUrl": "thinkpad-t14s.jpg", "description": "Die stabile Arbeitsmaschine. Mit AMD Ryzen 7 89029U, 128 GB RAM und 8 TB M.2 SSD!", "createdAt": "2024-09-13T07:51:40.119Z", "updatedAt": "2024-09-13T07:51:40.119Z", "category": { "id": 0, "name": "Electronic", "icon": "mdi-chip", "createdAt": "2024-09-13T07:51:40.118Z", "updatedAt": "2024-09-13T07:51:40.118Z" } } ```
Add new product

Description

Add a new product to the database

Request

POST /products
Body Parameters Required? Description
brand Yes Brand of the product
name Yes Name of the product
description No Description of the product
categoryId Yes ID of a Category from database
price No Name of the product
discount No Procentual discount, 0 to 100
rating No Product rating from 1 to 5
imageUrl No Name of the uploaded image file
Delete product

Description

Delete a product by it's id

Request

DELETE /products/:id
Parameter Required? Description
id Yes Database ID of ProductModel
#### `/orders`
Request orders of user

Description

Get all orders from a user

Request

GET /orders/:id
Parameter Required? Description
id Yes ID of the user in the database table

Example Response

```json [ { "id": 1, "accountId": 3, "totalPrice": 7.99, "shippingProgress": 5, "createdAt": "2024-09-09T12:24:24.225Z", "updatedAt": "2024-09-13T07:51:40.120Z", "orderItem": [ { "id": 1, "orderId": 1, "quantity": 1, "productId": 6, "createdAt": "2024-09-13T07:51:40.120Z", "updatedAt": "2024-09-13T07:51:40.120Z", "product": { "id": 6, "brand": "Aldous Huxley", "name": "Brave New World", "categoryId": 3, "price": 7.99, "discount": 0, "rating": 4.4, "imageUrl": "brave-new-world.jpg", "description": "Brave New World beschreibt eine genormte Gesellschaft, in der Föten genetisch manipuliert und Menschen konditioniert werden. Ziel des Staates ist Zufriedenheit und Stabilität, und dies wird durch Gleichheit, Drogen und Propaganda erreicht. Gott und Religion...", "createdAt": "2024-09-13T07:51:40.119Z", "updatedAt": "2024-09-13T07:51:40.119Z" } } ] } ] ```
Place a new order

Description

Place a new order to the database

Request

POST /orders
Query Parameters Required? Description
accountId Yes ID of account who created this order
shippingProgress No Progress of shipping, 1 to 5
orderItem Yes List of ordered items (objects). Needs parameter quantity and productId
#### `/accounts`
Login user

Description

Login process for user

Request

GET /accounts
Query Parameters Required? Description
username Yes Name of user account
password Yes Password of user account

Example Response

```json { "loginSuccessful": true, "userId": 3, "message": "" } ```
Add an user

Description

Place a new account to the database

Request

POST /accounts
Body Parameters Required? Description
username Yes Login username
password Yes Login password
firstName No First name of user
lastName No Last name of user
street No Street where the user lives
houseNumber No House number of user
postalCode No Postal code of users home
city No Name of users city
Update account

Description

Updating values of an existing account

Request

PATCH /account
Body Parameters Required? Description
id Yes Identifier of dataset
username No Login username
password No Login password
firstName No First name of user
lastName No Last name of user
street No Street where the user lives
houseNumber No House number of user
postalCode No Postal code of users home
city No Name of users city