mirror of
https://github.com/mainflux/mainflux.git
synced 2025-04-26 13:48:53 +08:00

* MF-1425 - Rebase mainflux master to resolve conflicts MF-1425 Enhancement to supply an external UUID for Things and Channels. Resolve conflicts. Signed-off-by: Q.s <wangqs_eclipse@yahoo.com> * MF-1425 - Test cases changes for SDK MF-1425 Enhancement to supply an external UUID for Things and Channels. These are the new testcases added for - Things Service Testcases - SDK Things and Channel Testcases Signed-off-by: Anand Sivaram Palassery <aspnair@gmail.com> Signed-off-by: Q.s <wangqs_eclipse@yahoo.com> * MF-1425 - Fixing Testcases MF-1425 Enhancement to supply an external UUID for Things and Channels. Because of the previous commits, the testcases were getting failed because the way ID was modified. This change is to make sure that all testcases are revisited to get them fixed. Signed-off-by: Anand Sivaram Palassery <aspnair@gmail.com> Signed-off-by: Q.s <wangqs_eclipse@yahoo.com> * MF-1425 - Fixing review comments Fixing the review comments provided. Signed-off-by: Anand Sivaram Palassery <aspnair@gmail.com> Signed-off-by: Q.s <wangqs_eclipse@yahoo.com> * MF-1425 - Fixing more review comments Signed-off-by: Anand Sivaram Palassery <aspnair@gmail.com> Signed-off-by: Q.s <wangqs_eclipse@yahoo.com> * MF-1425 - Fixing conflicts MF-1425 Enhancement to supply an external UUID for Things and Channels. Fixing the conflicts between aspnair master, and the mainflux master. Signed-off-by: Q.s <wangqs_eclipse@yahoo.com> * MF-1425 Fix the comment and code format per review comments MF-1425 Enhancement to supply an external UUID for Things and Channels. 1. Remove un-valued comment for a private function 2. Format the code for better readibility Signed-off-by: Q.S. Wang <wangqs_eclipse@yahoo.com> * MF-1425 Enhancement to supply an external UUID for Things and Channels. Fix the format of the API document Signed-off-by: Q.S. Wang <wangqs_eclipse@yahoo.com> * MF-1425 Enhancement to supply an external UUID for Things and Channels. Rename the variable to make it readible. Signed-off-by: Q.s <wangqs_eclipse@yahoo.com> Co-authored-by: Anand Sivaram Palassery <aspnair@gmail.com> Co-authored-by: Dušan Borovčanin <dusan.borovcanin@mainflux.com>
100 lines
2.0 KiB
Go
100 lines
2.0 KiB
Go
// Copyright (c) Mainflux
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
package mocks
|
|
|
|
import (
|
|
"fmt"
|
|
"sort"
|
|
"strconv"
|
|
|
|
"github.com/mainflux/mainflux/things"
|
|
)
|
|
|
|
const uuidLen = 36
|
|
|
|
// Since mocks will store data in map, and they need to resemble the real
|
|
// identifiers as much as possible, a key will be created as combination of
|
|
// owner and their own identifiers. This will allow searching either by
|
|
// prefix or suffix.
|
|
func key(owner string, id string) string {
|
|
return fmt.Sprintf("%s-%s", owner, id)
|
|
}
|
|
|
|
func sortThings(pm things.PageMetadata, ths []things.Thing) []things.Thing {
|
|
switch pm.Order {
|
|
case "name":
|
|
if pm.Dir == "asc" {
|
|
sort.SliceStable(ths, func(i, j int) bool {
|
|
return ths[i].Name < ths[j].Name
|
|
})
|
|
}
|
|
if pm.Dir == "desc" {
|
|
sort.SliceStable(ths, func(i, j int) bool {
|
|
return ths[i].Name > ths[j].Name
|
|
})
|
|
}
|
|
case "id":
|
|
if pm.Dir == "asc" {
|
|
sort.SliceStable(ths, func(i, j int) bool {
|
|
return ths[i].ID < ths[j].ID
|
|
})
|
|
}
|
|
if pm.Dir == "desc" {
|
|
sort.SliceStable(ths, func(i, j int) bool {
|
|
return ths[i].ID > ths[j].ID
|
|
})
|
|
}
|
|
default:
|
|
sort.SliceStable(ths, func(i, j int) bool {
|
|
return ths[i].ID < ths[j].ID
|
|
})
|
|
}
|
|
|
|
return ths
|
|
}
|
|
|
|
func sortChannels(pm things.PageMetadata, chs []things.Channel) []things.Channel {
|
|
switch pm.Order {
|
|
case "name":
|
|
if pm.Dir == "asc" {
|
|
sort.SliceStable(chs, func(i, j int) bool {
|
|
return chs[i].Name < chs[j].Name
|
|
})
|
|
}
|
|
if pm.Dir == "desc" {
|
|
sort.SliceStable(chs, func(i, j int) bool {
|
|
return chs[i].Name > chs[j].Name
|
|
})
|
|
}
|
|
case "id":
|
|
if pm.Dir == "asc" {
|
|
sort.SliceStable(chs, func(i, j int) bool {
|
|
return chs[i].ID < chs[j].ID
|
|
})
|
|
}
|
|
if pm.Dir == "desc" {
|
|
sort.SliceStable(chs, func(i, j int) bool {
|
|
return chs[i].ID > chs[j].ID
|
|
})
|
|
}
|
|
default:
|
|
sort.SliceStable(chs, func(i, j int) bool {
|
|
return chs[i].ID < chs[j].ID
|
|
})
|
|
}
|
|
|
|
return chs
|
|
}
|
|
|
|
func parseID(ID string) (id uint64) {
|
|
var serialNum string
|
|
|
|
if len(ID) == uuidLen {
|
|
serialNum = ID[len(ID)-6:]
|
|
}
|
|
id, _ = strconv.ParseUint(serialNum, 10, 64)
|
|
|
|
return
|
|
}
|