Rename types.Payment to types.DbPayment and types.ItemBought to be types.DbItemBought
sq
This commit is contained in:
parent
e6d53c4d17
commit
dd5f67536e
|
@ -9,16 +9,33 @@ import (
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
)
|
)
|
||||||
|
|
||||||
var itemBoughtTransform func(inp *db.ItemBought) types.ItemBought = func(inp *db.ItemBought) types.ItemBought {
|
var itemBoughtTransform func(inp *db.ItemBought) types.DbItemBought = func(inp *db.ItemBought) types.DbItemBought {
|
||||||
return types.ItemBought{}
|
var item types.DbItem
|
||||||
|
var price uint64 = 0
|
||||||
|
if inp.Item != nil {
|
||||||
|
item = itemTransform(inp.Item)
|
||||||
|
price = inp.Item.Price
|
||||||
|
}
|
||||||
|
return types.DbItemBought{
|
||||||
|
ID: inp.ID,
|
||||||
|
ItemID: inp.ItemID,
|
||||||
|
PaymentID: inp.PaymentID,
|
||||||
|
TypeID: inp.TypeID,
|
||||||
|
Price: price,
|
||||||
|
Quantity: inp.Quantity,
|
||||||
|
TotalCost: inp.TotalCost,
|
||||||
|
MetricType: inp.MetricType,
|
||||||
|
MetricValue: inp.MetricValue,
|
||||||
|
Item: item,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var paymentTransform func(inp *db.Payment) types.Payment = func(inp *db.Payment) types.Payment {
|
var paymentTransform func(inp *db.Payment) types.DbPayment = func(inp *db.Payment) types.DbPayment {
|
||||||
var items []types.ItemBought
|
var items []types.DbItemBought
|
||||||
for _, item := range inp.Items {
|
for _, item := range inp.Items {
|
||||||
items = append(items, itemBoughtTransform(&item))
|
items = append(items, itemBoughtTransform(&item))
|
||||||
}
|
}
|
||||||
return types.Payment{
|
return types.DbPayment{
|
||||||
ID: inp.ID,
|
ID: inp.ID,
|
||||||
CardID: inp.CardID,
|
CardID: inp.CardID,
|
||||||
CategoryID: inp.CategoryID,
|
CategoryID: inp.CategoryID,
|
||||||
|
@ -36,7 +53,7 @@ var paymentTransform func(inp *db.Payment) types.Payment = func(inp *db.Payment)
|
||||||
// @Accept json
|
// @Accept json
|
||||||
// @Produce json
|
// @Produce json
|
||||||
// @Param Authorization header string true "Bearer token"
|
// @Param Authorization header string true "Bearer token"
|
||||||
// @Param payment body types.Payment true "Payment"
|
// @Param payment body types.DbPayment true "Payment"
|
||||||
// @Success 200 {object} types.Message
|
// @Success 200 {object} types.Message
|
||||||
// @Failure 400 {object} types.ErrorResponse
|
// @Failure 400 {object} types.ErrorResponse
|
||||||
// @Failure 500 {object} types.ErrorResponse
|
// @Failure 500 {object} types.ErrorResponse
|
||||||
|
@ -49,7 +66,7 @@ func PaymentAdd(c *gin.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
var updates types.Payment
|
var updates types.DbPayment
|
||||||
if err := c.ShouldBindJSON(&updates); err != nil {
|
if err := c.ShouldBindJSON(&updates); err != nil {
|
||||||
log.Printf("err is %v\n", err)
|
log.Printf("err is %v\n", err)
|
||||||
c.JSON(400, types.ErrorResponse{Message: "Invalid request"})
|
c.JSON(400, types.ErrorResponse{Message: "Invalid request"})
|
||||||
|
|
|
@ -155,7 +155,7 @@ type DbCurrency struct {
|
||||||
Symbol string `json:"symbol" example:"$"`
|
Symbol string `json:"symbol" example:"$"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Payment struct {
|
type DbPayment struct {
|
||||||
ID uint `json:"id" example:"1"`
|
ID uint `json:"id" example:"1"`
|
||||||
CardID uint `json:"card_id" example:"1"`
|
CardID uint `json:"card_id" example:"1"`
|
||||||
CategoryID uint `json:"category_id" example:"1"`
|
CategoryID uint `json:"category_id" example:"1"`
|
||||||
|
@ -163,10 +163,10 @@ type Payment struct {
|
||||||
Description string `json:"descr" example:"i bought some title for 20$"`
|
Description string `json:"descr" example:"i bought some title for 20$"`
|
||||||
Note string `json:"note" example:"no i did not hit domain"`
|
Note string `json:"note" example:"no i did not hit domain"`
|
||||||
Date time.Time `json:"date" example:"29/11/2001 12:00"`
|
Date time.Time `json:"date" example:"29/11/2001 12:00"`
|
||||||
Items []ItemBought `json:"items" example:"[]"`
|
Items []DbItemBought `json:"items" example:"[]"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type ItemBought struct {
|
type DbItemBought struct {
|
||||||
ID uint `json:"id" example:"1"`
|
ID uint `json:"id" example:"1"`
|
||||||
NewName string `json:"new_name" example:"itemName"`
|
NewName string `json:"new_name" example:"itemName"`
|
||||||
NewComment string `json:"new_comment" example:"itemName"`
|
NewComment string `json:"new_comment" example:"itemName"`
|
||||||
|
|
Loading…
Reference in New Issue
Block a user