100 lines
2.3 KiB
Go
100 lines
2.3 KiB
Go
package utils
|
|
|
|
import (
|
|
"alfred/api/response"
|
|
"alfred/model/common"
|
|
"sort"
|
|
)
|
|
|
|
type responseDescSorter []common.Response
|
|
|
|
func (a responseDescSorter) Len() int {
|
|
return len(a)
|
|
}
|
|
|
|
func (a responseDescSorter) Swap(i, j int) {
|
|
a[i], a[j] = a[j], a[i]
|
|
}
|
|
|
|
func (a responseDescSorter) Less(i, j int) bool {
|
|
if a[i].Data == nil {
|
|
return false
|
|
}
|
|
first := a[i].Data.(response.SessionResponseData).RecordStartingTime
|
|
if a[j].Data == nil {
|
|
return true
|
|
}
|
|
second := a[j].Data.(response.SessionResponseData).RecordStartingTime
|
|
return first > second
|
|
}
|
|
|
|
type responseAscSorter []common.Response
|
|
|
|
func (a responseAscSorter) Len() int {
|
|
return len(a)
|
|
}
|
|
|
|
func (a responseAscSorter) Swap(i, j int) {
|
|
a[i], a[j] = a[j], a[i]
|
|
}
|
|
|
|
func (a responseAscSorter) Less(i, j int) bool {
|
|
first := a[i].Data.(response.SessionResponseData).RecordStartingTime
|
|
second := a[j].Data.(response.SessionResponseData).RecordStartingTime
|
|
return first > second
|
|
}
|
|
|
|
func Sort(unsortedSlice *[]common.Response) {
|
|
sort.Sort(responseDescSorter(*unsortedSlice))
|
|
}
|
|
|
|
func SortAsc(unsortedSlice *[]common.Response) {
|
|
sort.Sort(responseAscSorter(*unsortedSlice))
|
|
}
|
|
|
|
type searchSessionResponseDescSorter []common.Response
|
|
|
|
func (a searchSessionResponseDescSorter) Len() int {
|
|
return len(a)
|
|
}
|
|
|
|
func (a searchSessionResponseDescSorter) Swap(i, j int) {
|
|
a[i], a[j] = a[j], a[i]
|
|
}
|
|
|
|
func (a searchSessionResponseDescSorter) Less(i, j int) bool {
|
|
if a[i].Data == nil {
|
|
return false
|
|
}
|
|
first := a[i].Data.(response.SearchSessionResponseData).CreatedAt
|
|
if a[j].Data == nil {
|
|
return true
|
|
}
|
|
second := a[j].Data.(response.SearchSessionResponseData).CreatedAt
|
|
return first > second
|
|
}
|
|
|
|
type searchSessionResponseAscSorter []common.Response
|
|
|
|
func (a searchSessionResponseAscSorter) Len() int {
|
|
return len(a)
|
|
}
|
|
|
|
func (a searchSessionResponseAscSorter) Swap(i, j int) {
|
|
a[i], a[j] = a[j], a[i]
|
|
}
|
|
|
|
func (a searchSessionResponseAscSorter) Less(i, j int) bool {
|
|
first := a[i].Data.(response.SearchSessionResponseData).CreatedAt
|
|
second := a[j].Data.(response.SearchSessionResponseData).CreatedAt
|
|
return first < second
|
|
}
|
|
|
|
func SortSession(unsortedSlice *[]common.Response) {
|
|
sort.Sort(searchSessionResponseDescSorter(*unsortedSlice))
|
|
}
|
|
|
|
func SortAscSession(unsortedSlice *[]common.Response) {
|
|
sort.Sort(searchSessionResponseAscSorter(*unsortedSlice))
|
|
}
|