Skip to content

Commit

Permalink
feat(items): removable buy_limit & optimal_stock
Browse files Browse the repository at this point in the history
  • Loading branch information
yyewolf committed Aug 23, 2023
1 parent e1bd484 commit 5c7ccee
Show file tree
Hide file tree
Showing 8 changed files with 630 additions and 522 deletions.
11 changes: 11 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,14 @@

# Go workspace file
go.work
<<<<<<< Updated upstream
=======

*.img

*.tar

borne/OVMF.fd

borne/build/
>>>>>>> Stashed changes
2 changes: 1 addition & 1 deletion backend/Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ tasks:
cmds:
- oapi-codegen -generate="types,server,strict-server,spec" -package autogen ../bar.openapi.yml > autogen/bar.gen.go
- go mod tidy
- gomodifytags -all -file ./autogen/bar.gen.go -add-tags bson -add-options bson=omitempty -w > /dev/null
- gomodifytags -all -file ./autogen/bar.gen.go -add-tags bson -w > /dev/null
11 changes: 10 additions & 1 deletion backend/api/items.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ func (s *Server) PostItem(c echo.Context, categoryId autogen.UUID) error {
State: p.State,
AmountLeft: p.AmountLeft,
BuyLimit: p.BuyLimit,
OptimalAmount: p.OptimalAmount,
},
}

Expand Down Expand Up @@ -249,8 +250,16 @@ func (s *Server) PatchItem(c echo.Context, categoryId autogen.UUID, itemId autog
if p.AmountLeft != nil {
item.AmountLeft = *p.AmountLeft
}
if p.OptimalAmount != nil {
item.OptimalAmount = *p.OptimalAmount
}
if p.BuyLimit != nil {
item.BuyLimit = *p.BuyLimit
if *p.BuyLimit < 0 {
item.BuyLimit = nil
} else {
var buyLimit uint64 = uint64(*p.BuyLimit)
item.BuyLimit = &buyLimit
}
}

var rp = item.RealPrices()
Expand Down
12 changes: 8 additions & 4 deletions backend/api/transactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,11 @@ func (s *Server) PostTransactions(c echo.Context) error {
logrus.Warnf("Item %s is not in stock", item.Id.String())
return Error400(c)
}
if item.BuyLimit < potentialItem.Amount {
logrus.Warnf("Item %s cannot be bought for that amount", item.Id.String())
return Error400(c)
if item.BuyLimit != nil {
if *item.BuyLimit < potentialItem.Amount {
logrus.Warnf("Item %s cannot be bought for that amount", item.Id.String())
return Error400(c)
}
}

transaction.Items = append(transaction.Items, autogen.TransactionItem{
Expand Down Expand Up @@ -118,7 +120,9 @@ func (s *Server) PostTransactions(c echo.Context) error {

// update items
for _, item := range fetchedItems {
item.BuyLimit += item.AmountLeft
if item.BuyLimit != nil {
*item.BuyLimit += item.AmountLeft
}
err = s.DBackend.UpdateItem(ctx, item)
if err != nil {
logrus.Error(err)
Expand Down
Loading

0 comments on commit 5c7ccee

Please sign in to comment.