From 28408aa67baec8e77f4e4bd18784cb03addf51c1 Mon Sep 17 00:00:00 2001 From: albrecht <flo@DESKTOP-ERC0T8S> Date: Mon, 10 Jul 2023 15:29:34 +0200 Subject: [PATCH] finisched readme --- README.md | 40 +++++++++++++++++++++++++++++++++------- 1 file changed, 33 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index ec22eba..49ae76f 100644 --- a/README.md +++ b/README.md @@ -2,14 +2,20 @@ ## 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 -# 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 @@ -21,9 +27,13 @@ docker compose down In this section all API-Functions will be presented with an example call! ### BASIC FUNCTIONS +This section contains all basic Functions. #### GET JWT-Token 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' \ --header 'Content-Type: application/json' \ @@ -42,6 +52,7 @@ curl --location 'localhost:8080/health' ### Product-Functions #### 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' \ --header 'Content-Type: application/json' \ @@ -54,29 +65,33 @@ curl --location 'localhost:8080/products' \ ``` #### 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' \ --header 'Content-Type: application/json' \ --header 'Authorization: Bearer INSERT_TOKEN_HERE' \ --data '{ - "name": "new Name", - "description": "new Description", + "name": "WirePodsv2", + "description": "Kopfhörer mit mehr Akkuleistung", "price": 100.00 }' ``` #### DELETE PRODUCT (Admin only) (TOKEN REQUIRED) +This Function deletes the Product with the ID = 1. ``` curl --location --request DELETE 'localhost:8080/products/1' \ --header 'Authorization: Bearer INSERT_TOKEN_HERE' ``` #### GET ALL PRODUCTS +To retrieve all avaiable Products, use this Function: ``` curl --location 'localhost:8080/products' ``` #### GET SINGLE PRODUCT +To retrieve a specific Product (here Product with the ID = 1), use this Function: ``` curl --location 'localhost:8080/products/1' ``` @@ -84,8 +99,9 @@ curl --location 'localhost:8080/products/1' ### Rating-Functions #### 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 'Authorization: Bearer INSERT_TOKEN_HERE' \ --data '{ @@ -95,13 +111,14 @@ curl --location 'localhost:8080/products/2/rating' \ ``` #### 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' \ --header 'Authorization: Bearer INSERT_TOKEN_HERE' ``` #### READ ALL RATINGS +To get all Ratings of all Products, use this Get-Function: ``` curl --location 'localhost:8080/ratings' ``` @@ -110,6 +127,7 @@ curl --location 'localhost:8080/ratings' #### CREATE BANKACCOUNT (TOKEN REQUIRED) 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' \ --header 'Content-Type: application/json' \ @@ -122,6 +140,8 @@ curl --location 'localhost:8080/bankaccounts' \ ``` #### 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' \ --header 'Content-Type: application/json' \ @@ -135,12 +155,15 @@ curl --location --request PUT 'localhost:8080/bankaccounts' \ #### CREATE SHOPPINGCART (TOKEN REQUIRED) 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' \ --header 'Authorization: Bearer INSERT_TOKEN_HERE' ``` #### 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' \ --header 'Content-Type: application/json' \ @@ -151,6 +174,9 @@ curl --location 'localhost:8080/ShoppingCart/Product/1' \ ``` #### 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' \ --header 'Authorization: Bearer INSERT_TOKEN_HERE' -- GitLab