2023-01-10 20:23:47 -07:00
|
|
|
package utils
|
|
|
|
|
|
|
|
import (
|
2023-08-27 18:09:46 -06:00
|
|
|
"github.com/fastenhealth/fasten-onprem/backend/pkg/models"
|
2023-01-10 20:23:47 -07:00
|
|
|
"sort"
|
|
|
|
)
|
|
|
|
|
|
|
|
//default sort ASC (a, b, c, d, e...)
|
2023-07-08 08:43:30 -06:00
|
|
|
func SortResourcePtrListByTitle(resourceList []*models.ResourceBase) []*models.ResourceBase {
|
2023-01-10 20:23:47 -07:00
|
|
|
sort.SliceStable(resourceList, func(i, j int) bool {
|
|
|
|
if resourceList[i].SortTitle != nil && resourceList[j].SortTitle != nil {
|
|
|
|
return (*resourceList[i].SortTitle) < (*resourceList[j].SortTitle)
|
|
|
|
} else if resourceList[i].SortTitle != nil {
|
|
|
|
return true
|
|
|
|
} else {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
})
|
|
|
|
return resourceList
|
|
|
|
}
|
|
|
|
|
2023-07-08 08:43:30 -06:00
|
|
|
func SortResourceListByTitle(resourceList []models.ResourceBase) []models.ResourceBase {
|
2023-01-10 20:23:47 -07:00
|
|
|
sort.SliceStable(resourceList, func(i, j int) bool {
|
|
|
|
if resourceList[i].SortTitle != nil && resourceList[j].SortTitle != nil {
|
|
|
|
return (*resourceList[i].SortTitle) < (*resourceList[j].SortTitle)
|
|
|
|
} else if resourceList[i].SortTitle != nil {
|
|
|
|
return true
|
|
|
|
} else {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
})
|
|
|
|
return resourceList
|
|
|
|
}
|
|
|
|
|
|
|
|
//default sort DESC (today, yesterday, 2 days ago, 3 days ago...)
|
2023-07-08 08:43:30 -06:00
|
|
|
func SortResourcePtrListByDate(resourceList []*models.ResourceBase) []*models.ResourceBase {
|
2023-01-10 20:23:47 -07:00
|
|
|
sort.SliceStable(resourceList, func(i, j int) bool {
|
|
|
|
if resourceList[i].SortDate != nil && resourceList[j].SortDate != nil {
|
|
|
|
return (*resourceList[i].SortDate).After(*resourceList[j].SortDate)
|
|
|
|
} else if resourceList[i].SortDate != nil {
|
|
|
|
return true
|
|
|
|
} else {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
})
|
|
|
|
return resourceList
|
|
|
|
}
|
|
|
|
|
2023-07-08 08:43:30 -06:00
|
|
|
func SortResourceListByDate(resourceList []models.ResourceBase) []models.ResourceBase {
|
2023-01-10 20:23:47 -07:00
|
|
|
sort.SliceStable(resourceList, func(i, j int) bool {
|
|
|
|
if resourceList[i].SortDate != nil && resourceList[j].SortDate != nil {
|
|
|
|
return (*resourceList[i].SortDate).After(*resourceList[j].SortDate)
|
|
|
|
} else if resourceList[i].SortDate != nil {
|
|
|
|
return true
|
|
|
|
} else {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
})
|
|
|
|
return resourceList
|
|
|
|
}
|