grouptasks pagination

main
alex 2023-08-29 23:16:35 +02:00
parent d094dec64e
commit c70b1c396a
5 changed files with 18 additions and 10 deletions

View File

@ -191,7 +191,7 @@ func GetEquipmentDocumentations(stockItemId string, query structs.PageQuery, c *
return c.SendStatus(fiber.StatusInternalServerError) return c.SendStatus(fiber.StatusInternalServerError)
} }
} else { } else {
totalPages = utils.GetTotalPages(&documentations, stockItemId, "stock_item_id = ?", stockItemId) totalPages = utils.GetTotalPages(&documentations, "stock_item_id = ?", stockItemId)
} }
logger.AddSystemLog(structs.LogMessage{ logger.AddSystemLog(structs.LogMessage{

View File

@ -110,7 +110,7 @@ type GroupTasksRequest struct {
// swagger:model GroupTasksResponse // swagger:model GroupTasksResponse
type GroupTasksResponse struct { type GroupTasksResponse struct {
CategoryGroups []CategoryGroup CategoryGroup CategoryGroup
GroupTasks []GroupTasks GroupTasks []GroupTasks
GroupTasksSteps []GroupTaskSteps TotalPages int
} }

View File

@ -37,7 +37,7 @@ const (
ConnectionStateOnline = 1 ConnectionStateOnline = 1
EquipmentDocumentationsPaginationLimit = 3 EquipmentDocumentationsPaginationLimit = 3
GroupTasksPaginationLimit = 10 GroupTasksPaginationLimit = 5
) )
var ( var (

View File

@ -115,8 +115,8 @@ func QueryParserHelper(c *fiber.Ctx, query interface{}) error {
} }
// GetTotalPages returns total pages for pagination // GetTotalPages returns total pages for pagination
// Example Where("stock_item_id = ?", stockItemId) -> whereQuery = "stock_item_id = ?" and whereQuery = stockItemId // Example whereQuery = "stock_item_id = ?" and args = stockItemId is Where("stock_item_id = ?", stockItemId)
func GetTotalPages(any interface{}, stockItemId string, whereQuery interface{}, args ...interface{}) int { func GetTotalPages(any interface{}, whereQuery interface{}, args ...interface{}) int {
var totalPages int64 var totalPages int64
database.DB.Model(any). database.DB.Model(any).

View File

@ -28,10 +28,18 @@ func GetGroupTasks(c *fiber.Ctx) error {
log.Info().Msgf("params: %v", params) log.Info().Msgf("params: %v", params)
log.Info().Msgf("query: %v", query) log.Info().Msgf("query: %v", query)
var categoryGroup structs.CategoryGroup
for _, cGroup := range cache.GetCategoryGroups() {
if cGroup.Category == params.Category {
categoryGroup = cGroup
}
}
return c.JSON(structs.GroupTasksResponse{ return c.JSON(structs.GroupTasksResponse{
CategoryGroups: cache.GetCategoryGroupsSorted(), CategoryGroup: categoryGroup,
GroupTasks: grouptasks.GetAllGroupTasks(params.Category, query), GroupTasks: grouptasks.GetAllGroupTasks(params.Category, query),
GroupTasksSteps: grouptasks.GetAllGroupTasksSteps(), TotalPages: utils.GetTotalPages([]structs.GroupTasks{}, "category = ?", params.Category),
}) })
} }