mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-20 13:31:56 +00:00
feat(BE-281): fixing recording error, fixing limit upload uniformity and purchase, add filter and statistic uniformity
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"math"
|
||||
"mime/multipart"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
@@ -15,6 +16,8 @@ import (
|
||||
"github.com/gofiber/fiber/v2"
|
||||
)
|
||||
|
||||
const maxPurchaseUploadBytes = 5 * 1024 * 1024
|
||||
|
||||
type PurchaseController struct {
|
||||
service service.PurchaseService
|
||||
}
|
||||
@@ -184,6 +187,9 @@ func (ctrl *PurchaseController) ReceiveProducts(c *fiber.Ctx) error {
|
||||
if len(req.TravelDocuments) == 0 {
|
||||
req.TravelDocuments = form.File["documents"]
|
||||
}
|
||||
if err := validatePurchaseDocumentSizes(req.TravelDocuments); err != nil {
|
||||
return err
|
||||
}
|
||||
result, err := ctrl.service.ReceiveProducts(c, uint(id), req)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -198,6 +204,15 @@ func (ctrl *PurchaseController) ReceiveProducts(c *fiber.Ctx) error {
|
||||
})
|
||||
}
|
||||
|
||||
func validatePurchaseDocumentSizes(files []*multipart.FileHeader) error {
|
||||
for _, file := range files {
|
||||
if file != nil && file.Size > maxPurchaseUploadBytes {
|
||||
return fiber.NewError(fiber.StatusRequestEntityTooLarge, "Document size must be <= 5MB")
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (ctrl *PurchaseController) DeleteItems(c *fiber.Ctx) error {
|
||||
param := c.Params("id")
|
||||
id, err := strconv.Atoi(param)
|
||||
|
||||
Reference in New Issue
Block a user