Fix swagger deps

This commit is contained in:
Florian Hoss 2023-07-04 23:18:05 +02:00
parent 28f068c890
commit f63210272d
28 changed files with 307 additions and 310 deletions

View file

@ -4,8 +4,6 @@ import (
"fmt"
"strconv"
"time"
"gitlab.unjx.de/flohoss/cafe-plaetschwiesle/internal/types"
)
type (
@ -17,13 +15,13 @@ type (
}
BillItem struct {
ID uint64 `gorm:"primaryKey" json:"id" validate:"optional"`
BillID uint64 `json:"bill_id" validate:"required"`
Description string `json:"description" validate:"required"`
Total float32 `json:"total" validate:"required"`
Price float32 `json:"price" validate:"required"`
Amount uint64 `json:"amount" validate:"required"`
ItemType types.ItemType `json:"item_type" validate:"required"`
ID uint64 `gorm:"primaryKey" json:"id" validate:"optional"`
BillID uint64 `json:"bill_id" validate:"required"`
Description string `json:"description" validate:"required"`
Total float32 `json:"total" validate:"required"`
Price float32 `json:"price" validate:"required"`
Amount uint64 `json:"amount" validate:"required"`
ItemType ItemType `json:"item_type" validate:"required"`
}
)
@ -31,7 +29,7 @@ func (c *Controller) DoesBillExist(id string) (Bill, error) {
var bill Bill
result := c.orm.Limit(1).Find(&bill, id)
if result.RowsAffected == 0 {
return bill, fmt.Errorf(types.CannotFind.String())
return bill, fmt.Errorf(CannotFind.String())
}
return bill, nil
}
@ -40,7 +38,7 @@ func (c *Controller) GetAllBillItems(billId uint64) ([]BillItem, error) {
var billItems []BillItem
result := c.orm.Where("bill_id = ?", billId).Find(&billItems)
if result.RowsAffected == 0 {
return billItems, fmt.Errorf(types.CannotFind.String())
return billItems, fmt.Errorf(CannotFind.String())
}
return billItems, nil
}
@ -48,19 +46,19 @@ func (c *Controller) GetAllBillItems(billId uint64) ([]BillItem, error) {
func getDate(year string, month string, day string) (time.Time, error) {
yearI, yearErr := strconv.Atoi(year)
if yearErr != nil {
return time.Time{}, fmt.Errorf("jahr " + types.CannotParse.String())
return time.Time{}, fmt.Errorf("jahr " + CannotParse.String())
}
monthI, monthErr := strconv.Atoi(month)
if monthErr != nil {
return time.Time{}, fmt.Errorf("monat " + types.CannotParse.String())
return time.Time{}, fmt.Errorf("monat " + CannotParse.String())
}
dayI, dayErr := strconv.Atoi(day)
if dayErr != nil {
return time.Time{}, fmt.Errorf("tag " + types.CannotParse.String())
return time.Time{}, fmt.Errorf("tag " + CannotParse.String())
}
loc, locErr := time.LoadLocation("Local")
if locErr != nil {
return time.Time{}, fmt.Errorf("timezone " + types.CannotParse.String())
return time.Time{}, fmt.Errorf("timezone " + CannotParse.String())
}
return time.Date(yearI, time.Month(monthI), dayI, 0, 0, 0, 0, loc), nil
}
@ -88,7 +86,7 @@ func (c *Controller) createBill(options GetOrderOptions) (Bill, error) {
bill.Total = total
err := c.orm.Create(&bill).Error
if err != nil {
return bill, fmt.Errorf(types.CannotCreate.String())
return bill, fmt.Errorf(CannotCreate.String())
}
for _, order := range orders {
billItem := BillItem{
@ -104,10 +102,10 @@ func (c *Controller) createBill(options GetOrderOptions) (Bill, error) {
ordersToDelete := c.getAllOrdersForTable(GetOrderOptions{TableId: options.TableId, Grouped: false, Filter: options.Filter})
err = c.orm.Delete(&ordersToDelete).Error
if err != nil {
return bill, fmt.Errorf(types.CannotDelete.String())
return bill, fmt.Errorf(CannotDelete.String())
}
c.publishMessage(StatusMessage{
Type: types.DeleteAll,
Type: DeleteAll,
Payload: ordersToDelete,
})
return bill, nil
@ -116,7 +114,7 @@ func (c *Controller) createBill(options GetOrderOptions) (Bill, error) {
func (c *Controller) deleteBill(bill *Bill) error {
err := c.orm.Delete(bill).Error
if err != nil {
return fmt.Errorf(types.CannotDelete.String())
return fmt.Errorf(CannotDelete.String())
}
billItemsToDelete, _ := c.GetAllBillItems(bill.ID)
c.orm.Delete(&billItemsToDelete)