mirror of https://github.com/pikami/cosmium.git
Fix partition key ranges endpoint
This commit is contained in:
parent
d426dc23c0
commit
19f62f8173
|
@ -26,9 +26,14 @@ func GetPartitionKeyRanges(c *gin.Context) {
|
||||||
c.Header("x-ms-global-committed-lsn", "420")
|
c.Header("x-ms-global-committed-lsn", "420")
|
||||||
c.Header("x-ms-item-count", fmt.Sprintf("%d", len(partitionKeyRanges)))
|
c.Header("x-ms-item-count", fmt.Sprintf("%d", len(partitionKeyRanges)))
|
||||||
|
|
||||||
|
collectionRid := collectionId
|
||||||
collection, _ := repositories.GetCollection(databaseId, collectionId)
|
collection, _ := repositories.GetCollection(databaseId, collectionId)
|
||||||
|
if collection.ResourceID != "" {
|
||||||
|
collectionRid = collection.ResourceID
|
||||||
|
}
|
||||||
|
|
||||||
c.IndentedJSON(http.StatusOK, gin.H{
|
c.IndentedJSON(http.StatusOK, gin.H{
|
||||||
"_rid": collection.ResourceID,
|
"_rid": collectionRid,
|
||||||
"_count": len(partitionKeyRanges),
|
"_count": len(partitionKeyRanges),
|
||||||
"PartitionKeyRanges": partitionKeyRanges,
|
"PartitionKeyRanges": partitionKeyRanges,
|
||||||
})
|
})
|
||||||
|
|
|
@ -10,19 +10,21 @@ import (
|
||||||
|
|
||||||
// I have no idea what this is tbh
|
// I have no idea what this is tbh
|
||||||
func GetPartitionKeyRanges(databaseId string, collectionId string) ([]repositorymodels.PartitionKeyRange, repositorymodels.RepositoryStatus) {
|
func GetPartitionKeyRanges(databaseId string, collectionId string) ([]repositorymodels.PartitionKeyRange, repositorymodels.RepositoryStatus) {
|
||||||
var ok bool
|
databaseRid := databaseId
|
||||||
var database repositorymodels.Database
|
collectionRid := collectionId
|
||||||
var collection repositorymodels.Collection
|
var timestamp int64 = 0
|
||||||
if database, ok = storeState.Databases[databaseId]; !ok {
|
|
||||||
return make([]repositorymodels.PartitionKeyRange, 0), repositorymodels.StatusNotFound
|
if database, ok := storeState.Databases[databaseId]; !ok {
|
||||||
|
databaseRid = database.ResourceID
|
||||||
}
|
}
|
||||||
|
|
||||||
if collection, ok = storeState.Collections[databaseId][collectionId]; !ok {
|
if collection, ok := storeState.Collections[databaseId][collectionId]; !ok {
|
||||||
return make([]repositorymodels.PartitionKeyRange, 0), repositorymodels.StatusNotFound
|
collectionRid = collection.ResourceID
|
||||||
|
timestamp = collection.TimeStamp
|
||||||
}
|
}
|
||||||
|
|
||||||
pkrResourceId := resourceid.NewCombined(database.ResourceID, collection.ResourceID, resourceid.New())
|
pkrResourceId := resourceid.NewCombined(databaseRid, collectionRid, resourceid.New())
|
||||||
pkrSelf := fmt.Sprintf("dbs/%s/colls/%s/pkranges/%s/", database.ResourceID, collection.ResourceID, pkrResourceId)
|
pkrSelf := fmt.Sprintf("dbs/%s/colls/%s/pkranges/%s/", databaseRid, collectionRid, pkrResourceId)
|
||||||
etag := fmt.Sprintf("\"%s\"", uuid.New())
|
etag := fmt.Sprintf("\"%s\"", uuid.New())
|
||||||
|
|
||||||
return []repositorymodels.PartitionKeyRange{
|
return []repositorymodels.PartitionKeyRange{
|
||||||
|
@ -37,7 +39,7 @@ func GetPartitionKeyRanges(databaseId string, collectionId string) ([]repository
|
||||||
ThroughputFraction: 1,
|
ThroughputFraction: 1,
|
||||||
Status: "online",
|
Status: "online",
|
||||||
Parents: []interface{}{},
|
Parents: []interface{}{},
|
||||||
TimeStamp: collection.TimeStamp,
|
TimeStamp: timestamp,
|
||||||
Lsn: 17,
|
Lsn: 17,
|
||||||
},
|
},
|
||||||
}, repositorymodels.StatusOk
|
}, repositorymodels.StatusOk
|
||||||
|
|
Loading…
Reference in New Issue