Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[UPDATE] Sort stock batch #62

Merged
merged 3 commits into from
Oct 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion internal/core/service/stock.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package service

import (
"sort"
"time"

"github.com/BakingUp/BakingUp-Backend/internal/core/domain"
"github.com/BakingUp/BakingUp-Backend/internal/core/port"
"github.com/BakingUp/BakingUp-Backend/internal/core/util"
"github.com/BakingUp/BakingUp-Backend/prisma/db"
"github.com/gofiber/fiber/v2"
"time"
)

type StockService struct {
Expand Down Expand Up @@ -162,6 +164,12 @@ func (s *StockService) GetStockDetail(c *fiber.Ctx, recipeID string) (*domain.St
stockDetails = append(stockDetails, detail)
}

sort.Slice(stockDetails, func(i, j int) bool {
dateI, _ := time.Parse("02/01/2006", stockDetails[i].SellByDate)
dateJ, _ := time.Parse("02/01/2006", stockDetails[j].SellByDate)
return dateI.Before(dateJ)
})

var stockURLs []string
for _, image := range stock.Recipe().RecipeImages() {
stockURLs = append(stockURLs, image.RecipeURL)
Expand Down
Loading