feat(BE-281): fixing recording error, fixing limit upload uniformity and purchase, add filter and statistic uniformity

This commit is contained in:
ragilap
2026-01-07 20:26:27 +07:00
parent 90f363bfdb
commit a2d2c4269a
14 changed files with 847 additions and 430 deletions
@@ -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)