Fix partition key ranges endpoint

This commit is contained in:
Pijus Kamandulis 2024-02-27 20:08:48 +02:00
parent d426dc23c0
commit 19f62f8173
2 changed files with 18 additions and 11 deletions

View File

@ -26,9 +26,14 @@ func GetPartitionKeyRanges(c *gin.Context) {
c.Header("x-ms-global-committed-lsn", "420")
c.Header("x-ms-item-count", fmt.Sprintf("%d", len(partitionKeyRanges)))
collectionRid := collectionId
collection, _ := repositories.GetCollection(databaseId, collectionId)
if collection.ResourceID != "" {
collectionRid = collection.ResourceID
}
c.IndentedJSON(http.StatusOK, gin.H{
"_rid": collection.ResourceID,
"_rid": collectionRid,
"_count": len(partitionKeyRanges),
"PartitionKeyRanges": partitionKeyRanges,
})

View File

@ -10,19 +10,21 @@ import (
// I have no idea what this is tbh
func GetPartitionKeyRanges(databaseId string, collectionId string) ([]repositorymodels.PartitionKeyRange, repositorymodels.RepositoryStatus) {
var ok bool
var database repositorymodels.Database
var collection repositorymodels.Collection
if database, ok = storeState.Databases[databaseId]; !ok {
return make([]repositorymodels.PartitionKeyRange, 0), repositorymodels.StatusNotFound
databaseRid := databaseId
collectionRid := collectionId
var timestamp int64 = 0
if database, ok := storeState.Databases[databaseId]; !ok {
databaseRid = database.ResourceID
}
if collection, ok = storeState.Collections[databaseId][collectionId]; !ok {
return make([]repositorymodels.PartitionKeyRange, 0), repositorymodels.StatusNotFound
if collection, ok := storeState.Collections[databaseId][collectionId]; !ok {
collectionRid = collection.ResourceID
timestamp = collection.TimeStamp
}
pkrResourceId := resourceid.NewCombined(database.ResourceID, collection.ResourceID, resourceid.New())
pkrSelf := fmt.Sprintf("dbs/%s/colls/%s/pkranges/%s/", database.ResourceID, collection.ResourceID, pkrResourceId)
pkrResourceId := resourceid.NewCombined(databaseRid, collectionRid, resourceid.New())
pkrSelf := fmt.Sprintf("dbs/%s/colls/%s/pkranges/%s/", databaseRid, collectionRid, pkrResourceId)
etag := fmt.Sprintf("\"%s\"", uuid.New())
return []repositorymodels.PartitionKeyRange{
@ -37,7 +39,7 @@ func GetPartitionKeyRanges(databaseId string, collectionId string) ([]repository
ThroughputFraction: 1,
Status: "online",
Parents: []interface{}{},
TimeStamp: collection.TimeStamp,
TimeStamp: timestamp,
Lsn: 17,
},
}, repositorymodels.StatusOk