mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-21 22:05:44 +00:00
adjust export format purchase and filter
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
entity "gitlab.com/mbugroup/lti-api.git/internal/entities"
|
||||
"gitlab.com/mbugroup/lti-api.git/internal/modules/finance/transactions/dto"
|
||||
service "gitlab.com/mbugroup/lti-api.git/internal/modules/finance/transactions/services"
|
||||
validation "gitlab.com/mbugroup/lti-api.git/internal/modules/finance/transactions/validations"
|
||||
@@ -13,6 +14,8 @@ import (
|
||||
"github.com/gofiber/fiber/v2"
|
||||
)
|
||||
|
||||
const transactionExcelExportFetchLimit = 99999999
|
||||
|
||||
type TransactionController struct {
|
||||
TransactionService service.TransactionService
|
||||
}
|
||||
@@ -107,6 +110,14 @@ func (u *TransactionController) GetAll(c *fiber.Ctx) error {
|
||||
return fiber.NewError(fiber.StatusBadRequest, "page and limit must be greater than 0")
|
||||
}
|
||||
|
||||
if isTransactionExcelExportRequest(c) {
|
||||
results, err := u.getAllTransactionsForExcel(c, query)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return exportTransactionListExcel(c, results)
|
||||
}
|
||||
|
||||
result, totalResults, err := u.TransactionService.GetAll(c, query)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -149,6 +160,32 @@ func (u *TransactionController) GetOne(c *fiber.Ctx) error {
|
||||
})
|
||||
}
|
||||
|
||||
func isTransactionExcelExportRequest(c *fiber.Ctx) bool {
|
||||
return strings.EqualFold(strings.TrimSpace(c.Query("export")), "excel")
|
||||
}
|
||||
|
||||
func (u *TransactionController) getAllTransactionsForExcel(c *fiber.Ctx, baseQuery *validation.Query) ([]entity.Payment, error) {
|
||||
query := *baseQuery
|
||||
query.Page = 1
|
||||
query.Limit = transactionExcelExportFetchLimit
|
||||
results := make([]entity.Payment, 0)
|
||||
for {
|
||||
pageResults, total, err := u.TransactionService.GetAll(c, &query)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(pageResults) == 0 || total == 0 {
|
||||
break
|
||||
}
|
||||
results = append(results, pageResults...)
|
||||
if int64(len(results)) >= total {
|
||||
break
|
||||
}
|
||||
query.Page++
|
||||
}
|
||||
return results, nil
|
||||
}
|
||||
|
||||
func (u *TransactionController) DeleteOne(c *fiber.Ctx) error {
|
||||
param := c.Params("id")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user