Skip to content
Snippets Groups Projects
Commit 09f03179 authored by albrecht's avatar albrecht
Browse files

changes

parent 35df0958
No related branches found
No related tags found
No related merge requests found
...@@ -23,6 +23,9 @@ docker compose up ...@@ -23,6 +23,9 @@ docker compose up
docker compose down docker compose down
``` ```
## Technical Highlights
This service does not use Gorilla as framework. Here will be Gin-Gonic used. Gin is the most popular framework used by Golang-Developers. It is an extremely fast web framework and it suits the requirements of developers when they create microservices and web applications. (https://github.com/gin-gonic/gin)
## All API Functions ## All API Functions
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!
...@@ -157,7 +160,7 @@ curl --location --request PUT 'localhost:8080/bankaccounts' \ ...@@ -157,7 +160,7 @@ curl --location --request PUT 'localhost:8080/bankaccounts' \
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. 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'
``` ```
...@@ -165,7 +168,7 @@ curl --location --request POST 'localhost:8080/ShoppingCart' \ ...@@ -165,7 +168,7 @@ curl --location --request POST 'localhost:8080/ShoppingCart' \
To add a Product (here Product with the ID = 1) use this function. In the request Body the amount will be specified. 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. 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' \
--header 'Authorization: Bearer INSERT_TOKEN_HERE' \ --header 'Authorization: Bearer INSERT_TOKEN_HERE' \
--data '{ --data '{
...@@ -178,7 +181,7 @@ With this Function, all Products will be buyed. If the Balance is lesser than th ...@@ -178,7 +181,7 @@ With this Function, all Products will be buyed. If the Balance is lesser than th
If the Payment process is successfull, the Shoppingcart will be tranformed into the default version. 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. 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'
``` ```
......
...@@ -4,10 +4,9 @@ import "gorm.io/gorm" ...@@ -4,10 +4,9 @@ import "gorm.io/gorm"
type Position struct { type Position struct {
gorm.Model gorm.Model
Amount int `gorm:"notNull"` Amount int `gorm:"notNull"`
ProductId uint `gorm:"notNull"` ProductId uint `gorm:"notNull"`
Price float64 `gorm:"notNull"` Price float64 `gorm:"notNull"`
Totalprice float64 `gorm:"notNull"` Totalprice float64 `gorm:"notNull"`
ShoppingCartId uint `gorm:"notNull"` ShoppingCartId uint `gorm:"notNull"`
ShoppingCart ShoppingCart `gorm:"-"`
} }
...@@ -106,17 +106,6 @@ func (s *ShoppingCartService) TransferMoney(username string) error { ...@@ -106,17 +106,6 @@ func (s *ShoppingCartService) TransferMoney(username string) error {
return err return err
} }
// Set Shoppingcart to default
for i := range ShoppingCart.Positions {
ShoppingCart.Positions[i].Amount = 0
}
ShoppingCart.Totalprice = 0.0
if err := db.DB.Where("shopping_cart_id = ?", ShoppingCart.Username).Delete(&model.Position{}).Error; err != nil {
return err
}
result = db.DB.Save(ShoppingCart) result = db.DB.Save(ShoppingCart)
if result.Error != nil { if result.Error != nil {
log.Error("Could not save Shoppingcart") log.Error("Could not save Shoppingcart")
......
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