31 lines
543 B
Go
31 lines
543 B
Go
package mongo
|
|
|
|
import (
|
|
"strings"
|
|
|
|
"go.mongodb.org/mongo-driver/bson"
|
|
)
|
|
|
|
func AdaptOrder(orderString string, adaptMap map[string]string) string {
|
|
for old, new := range adaptMap {
|
|
orderString = strings.Replace(orderString, old, new, -1)
|
|
}
|
|
|
|
return orderString
|
|
}
|
|
|
|
func getOrder(queryOrder string) bson.M {
|
|
order := bson.M{"_id": -1}
|
|
orderSlice := strings.Split(queryOrder, " ")
|
|
if len(orderSlice) > 1 {
|
|
asc := 1
|
|
if strings.ToLower(orderSlice[1]) == "desc" {
|
|
asc = -1
|
|
}
|
|
|
|
order = bson.M{orderSlice[0]: asc}
|
|
}
|
|
|
|
return order
|
|
}
|