-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
create /course in the api to get the course to make
- Loading branch information
Showing
5 changed files
with
476 additions
and
127 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
Oops, something went wrong.