Skip to content

Commit

Permalink
create /course in the api to get the course to make
Browse files Browse the repository at this point in the history
  • Loading branch information
BaptTF committed Apr 26, 2024
1 parent 8dbec9f commit 43c01fe
Show file tree
Hide file tree
Showing 5 changed files with 476 additions and 127 deletions.
43 changes: 43 additions & 0 deletions backend/api/course.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package api

import (
"bar/autogen"

"github.com/labstack/echo/v4"
"github.com/sirupsen/logrus"
)

// (GET /course)
func (s *Server) GetCourse(c echo.Context, params autogen.GetCourseParams) error {
// Get admin account from cookie
_, err := MustGetAdmin(c)
if err != nil {
return nil
}
search := ""
if params.Fournisseur != nil {
search = *params.Fournisseur
}
var course []autogen.CourseItem

data, err := s.DBackend.GetItems(c.Request().Context(), "", 0, 0, "", "", search)
if err != nil {
logrus.Error(err)
return Error500(c)
}

for _, item := range data {
var amount_needed uint64 = item.OptimalAmount - item.AmountLeft
if amount_needed > 0 && item.AmountPerBundle != nil {
course = append(course, autogen.CourseItem{
AmountToBuy: amount_needed / *item.AmountPerBundle + (amount_needed % *item.AmountPerBundle) * 2 / *item.AmountPerBundle,
Item: item.Item,
})
}
}

autogen.GetCourse200JSONResponse{
Items: course,
}.VisitGetCourseResponse(c.Response())
return nil
}
Loading

0 comments on commit 43c01fe

Please sign in to comment.