mirror of
https://codeberg.org/pluja/kycnot.me
synced 2025-01-08 21:57:58 -05:00
sort attributes
This commit is contained in:
parent
ecf7c38911
commit
f13596e6ac
@ -3,6 +3,7 @@ package database
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"sort"
|
||||
|
||||
"github.com/pluja/pocketbase"
|
||||
)
|
||||
@ -64,14 +65,25 @@ func (p *PbClient) GetServiceByNameOrUrl(id string) (*Service, error) {
|
||||
Filters: fmt.Sprintf("((name='%v') || (urls~'%v'))", id, id),
|
||||
}
|
||||
|
||||
// TODO: Sort attributes by rating
|
||||
|
||||
response, err := collection.List(params)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &response.Items[0], nil
|
||||
service := response.Items[0]
|
||||
|
||||
// Sort attributes by rating
|
||||
sort.SliceStable(service.Expand["attributes"], func(i, j int) bool {
|
||||
ratingOrder := map[string]int{
|
||||
"bad": 4,
|
||||
"warn": 3,
|
||||
"good": 2,
|
||||
"info": 1,
|
||||
}
|
||||
return ratingOrder[service.Expand["attributes"][i].Rating] > ratingOrder[service.Expand["attributes"][j].Rating]
|
||||
})
|
||||
|
||||
return &service, nil
|
||||
}
|
||||
|
||||
func (p *PbClient) GetServiceById(id string) (*Service, error) {
|
||||
|
Loading…
Reference in New Issue
Block a user