Generate legit ResourceIds for SDK compatibility

This commit is contained in:
Pijus Kamandulis
2024-02-26 21:03:47 +02:00
parent 6dd43ca7e0
commit 1158f93102
12 changed files with 142 additions and 53 deletions

View File

@@ -13,7 +13,13 @@ func GetAllCollections(c *gin.Context) {
collections, status := repositories.GetAllCollections(databaseId)
if status == repositorymodels.StatusOk {
c.IndentedJSON(http.StatusOK, gin.H{"_rid": "", "DocumentCollections": collections, "_count": len(collections)})
database, _ := repositories.GetDatabase(databaseId)
c.IndentedJSON(http.StatusOK, gin.H{
"_rid": database.ResourceID,
"DocumentCollections": collections,
"_count": len(collections),
})
return
}

View File

@@ -11,7 +11,11 @@ import (
func GetAllDatabases(c *gin.Context) {
databases, status := repositories.GetAllDatabases()
if status == repositorymodels.StatusOk {
c.IndentedJSON(http.StatusOK, gin.H{"_rid": "", "Databases": databases, "_count": len(databases)})
c.IndentedJSON(http.StatusOK, gin.H{
"_rid": "",
"Databases": databases,
"_count": len(databases),
})
return
}

View File

@@ -15,7 +15,13 @@ func GetAllDocuments(c *gin.Context) {
documents, status := repositories.GetAllDocuments(databaseId, collectionId)
if status == repositorymodels.StatusOk {
c.IndentedJSON(http.StatusOK, gin.H{"_rid": "", "Documents": documents, "_count": len(documents)})
collection, _ := repositories.GetCollection(databaseId, collectionId)
c.IndentedJSON(http.StatusOK, gin.H{
"_rid": collection.ID,
"Documents": documents,
"_count": len(documents),
})
return
}
@@ -121,7 +127,12 @@ func DocumentsPost(c *gin.Context) {
return
}
c.IndentedJSON(http.StatusOK, gin.H{"_rid": "", "Documents": docs, "_count": len(docs)})
collection, _ := repositories.GetCollection(databaseId, collectionId)
c.IndentedJSON(http.StatusOK, gin.H{
"_rid": collection.ResourceID,
"Documents": docs,
"_count": len(docs),
})
return
}

View File

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