Skip to content
Snippets Groups Projects
Commit 28408aa6 authored by albrecht's avatar albrecht
Browse files

finisched readme

parent 683c8079
No related branches found
No related tags found
No related merge requests found
...@@ -2,14 +2,20 @@ ...@@ -2,14 +2,20 @@
## Getting Started ## Getting Started
#### Start without Docker: ### Start without Docker Compose:
Wait a few seconds after the Database is up! (Database uses Docker)
``` ```
./scripts/start-mariadb.sh ./scripts/start-mariadb.sh
# cd src/gomazon && go run main.go cd src/gomazon && go run main.go
```
To close the Database use:
```
./scripts/stop-mariadb.sh
``` ```
#### Build, Start and Stop service using Docker Compose ### Build, Start and Stop service using Docker Compose
``` ```
docker compose build docker compose build
...@@ -21,9 +27,13 @@ docker compose down ...@@ -21,9 +27,13 @@ docker compose down
In this section all API-Functions will be presented with an example call! In this section all API-Functions will be presented with an example call!
### BASIC FUNCTIONS ### BASIC FUNCTIONS
This section contains all basic Functions.
#### GET JWT-Token #### GET JWT-Token
Use the Result-Token for all marked API-Functions! Use the Result-Token for all marked API-Functions!
This Token contains the Username and an isAdmin-Flag(true or false).
All Token-required Functions extract these information from the Token-String.
One Token is valid for 30 minutes!
``` ```
curl --location --request GET 'localhost:8080/createJWT' \ curl --location --request GET 'localhost:8080/createJWT' \
--header 'Content-Type: application/json' \ --header 'Content-Type: application/json' \
...@@ -42,6 +52,7 @@ curl --location 'localhost:8080/health' ...@@ -42,6 +52,7 @@ curl --location 'localhost:8080/health'
### Product-Functions ### Product-Functions
#### CREATE PRODUCT (Admin only) (TOKEN REQUIRED) #### CREATE PRODUCT (Admin only) (TOKEN REQUIRED)
This admin-only-Function adds a new Product with the name "WirePods", description "Kabellose Kopfhörer" and 130.20 as the price. The Totalrating is initial always 0.0!
``` ```
curl --location 'localhost:8080/products' \ curl --location 'localhost:8080/products' \
--header 'Content-Type: application/json' \ --header 'Content-Type: application/json' \
...@@ -54,29 +65,33 @@ curl --location 'localhost:8080/products' \ ...@@ -54,29 +65,33 @@ curl --location 'localhost:8080/products' \
``` ```
#### UPDATE PRODUCT (Admin only) (TOKEN REQUIRED) #### UPDATE PRODUCT (Admin only) (TOKEN REQUIRED)
This Function updates the Product with the ID = 1: the new Name is "WirePodsv2", description "Kopfhörer mit mehr Akkuleistung" and a new price (100.00).
``` ```
curl --location --request PUT 'localhost:8080/products/1' \ curl --location --request PUT 'localhost:8080/products/1' \
--header 'Content-Type: application/json' \ --header 'Content-Type: application/json' \
--header 'Authorization: Bearer INSERT_TOKEN_HERE' \ --header 'Authorization: Bearer INSERT_TOKEN_HERE' \
--data '{ --data '{
"name": "new Name", "name": "WirePodsv2",
"description": "new Description", "description": "Kopfhörer mit mehr Akkuleistung",
"price": 100.00 "price": 100.00
}' }'
``` ```
#### DELETE PRODUCT (Admin only) (TOKEN REQUIRED) #### DELETE PRODUCT (Admin only) (TOKEN REQUIRED)
This Function deletes the Product with the ID = 1.
``` ```
curl --location --request DELETE 'localhost:8080/products/1' \ curl --location --request DELETE 'localhost:8080/products/1' \
--header 'Authorization: Bearer INSERT_TOKEN_HERE' --header 'Authorization: Bearer INSERT_TOKEN_HERE'
``` ```
#### GET ALL PRODUCTS #### GET ALL PRODUCTS
To retrieve all avaiable Products, use this Function:
``` ```
curl --location 'localhost:8080/products' curl --location 'localhost:8080/products'
``` ```
#### GET SINGLE PRODUCT #### GET SINGLE PRODUCT
To retrieve a specific Product (here Product with the ID = 1), use this Function:
``` ```
curl --location 'localhost:8080/products/1' curl --location 'localhost:8080/products/1'
``` ```
...@@ -84,8 +99,9 @@ curl --location 'localhost:8080/products/1' ...@@ -84,8 +99,9 @@ curl --location 'localhost:8080/products/1'
### Rating-Functions ### Rating-Functions
#### POST RATING (TOKEN REQUIRED) #### POST RATING (TOKEN REQUIRED)
With this Function a new Rating will be added. The username will be extracted from the Token-String. The Totalrating of this Product (here ID = 1) will be calculated by all Ratings of this Product (mean).
``` ```
curl --location 'localhost:8080/products/2/rating' \ curl --location 'localhost:8080/products/1/rating' \
--header 'Content-Type: application/json' \ --header 'Content-Type: application/json' \
--header 'Authorization: Bearer INSERT_TOKEN_HERE' \ --header 'Authorization: Bearer INSERT_TOKEN_HERE' \
--data '{ --data '{
...@@ -95,13 +111,14 @@ curl --location 'localhost:8080/products/2/rating' \ ...@@ -95,13 +111,14 @@ curl --location 'localhost:8080/products/2/rating' \
``` ```
#### DELETE RATING (TOKEN REQUIRED) #### DELETE RATING (TOKEN REQUIRED)
Only Admins and Owner of the Rating can use this Only Admins and Owner of the Rating can use this! In this example, the rating with the ID = 3 will be deleted. If the request contains a Token-String with an Non-Admin or Token.Username != Rating.Owner nothing will happen.
``` ```
curl --location --request DELETE 'localhost:8080/ratings/3' \ curl --location --request DELETE 'localhost:8080/ratings/3' \
--header 'Authorization: Bearer INSERT_TOKEN_HERE' --header 'Authorization: Bearer INSERT_TOKEN_HERE'
``` ```
#### READ ALL RATINGS #### READ ALL RATINGS
To get all Ratings of all Products, use this Get-Function:
``` ```
curl --location 'localhost:8080/ratings' curl --location 'localhost:8080/ratings'
``` ```
...@@ -110,6 +127,7 @@ curl --location 'localhost:8080/ratings' ...@@ -110,6 +127,7 @@ curl --location 'localhost:8080/ratings'
#### CREATE BANKACCOUNT (TOKEN REQUIRED) #### CREATE BANKACCOUNT (TOKEN REQUIRED)
If one user has already an account, the existing account is the result value. If one user has already an account, the existing account is the result value.
The Owner will be detected by the Token-String
``` ```
curl --location 'localhost:8080/bankaccounts' \ curl --location 'localhost:8080/bankaccounts' \
--header 'Content-Type: application/json' \ --header 'Content-Type: application/json' \
...@@ -122,6 +140,8 @@ curl --location 'localhost:8080/bankaccounts' \ ...@@ -122,6 +140,8 @@ curl --location 'localhost:8080/bankaccounts' \
``` ```
#### Deposit or withdraw (TOKEN REQUIRED) #### Deposit or withdraw (TOKEN REQUIRED)
To increase or decrease the Accountbalance, this Function can be used.
The Bankaccount will be detected by the username in the Token-String.
``` ```
curl --location --request PUT 'localhost:8080/bankaccounts' \ curl --location --request PUT 'localhost:8080/bankaccounts' \
--header 'Content-Type: application/json' \ --header 'Content-Type: application/json' \
...@@ -135,12 +155,15 @@ curl --location --request PUT 'localhost:8080/bankaccounts' \ ...@@ -135,12 +155,15 @@ curl --location --request PUT 'localhost:8080/bankaccounts' \
#### CREATE SHOPPINGCART (TOKEN REQUIRED) #### CREATE SHOPPINGCART (TOKEN REQUIRED)
If one user has already an ShoppingCart, the existing ShoppingCart is the result value. If one user has already an ShoppingCart, the existing ShoppingCart is the result value.
The user will also be detected with the Token-String.
``` ```
curl --location --request POST 'localhost:8080/ShoppingCart' \ curl --location --request POST 'localhost:8080/ShoppingCart' \
--header 'Authorization: Bearer INSERT_TOKEN_HERE' --header 'Authorization: Bearer INSERT_TOKEN_HERE'
``` ```
#### ADD PRODUCT TO SHOPPINGCART (TOKEN REQUIRED) #### ADD PRODUCT TO SHOPPINGCART (TOKEN REQUIRED)
To add a Product (here Product with the ID = 1) use this function. In the request Body the amount will be specified.
The user will also be detected with the Token-String.
``` ```
curl --location 'localhost:8080/ShoppingCart/Product/1' \ curl --location 'localhost:8080/ShoppingCart/Product/1' \
--header 'Content-Type: application/json' \ --header 'Content-Type: application/json' \
...@@ -151,6 +174,9 @@ curl --location 'localhost:8080/ShoppingCart/Product/1' \ ...@@ -151,6 +174,9 @@ curl --location 'localhost:8080/ShoppingCart/Product/1' \
``` ```
#### PAY SHOPPINGCART (TOKEN REQUIRED) #### PAY SHOPPINGCART (TOKEN REQUIRED)
With this Function, all Products will be buyed. If the Balance is lesser than the Totalprice, the Payment process will be canceled.
If the Payment process is successfull, the Shoppingcart will be tranformed into the default version.
The user will also be detected with the Token-String.
``` ```
curl --location --request POST 'localhost:8080/ShoppingCart/pay' \ curl --location --request POST 'localhost:8080/ShoppingCart/pay' \
--header 'Authorization: Bearer INSERT_TOKEN_HERE' --header 'Authorization: Bearer INSERT_TOKEN_HERE'
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment