2024-02-10 23:44:20 +00:00
|
|
|
package handlers
|
|
|
|
|
|
|
|
import (
|
2024-02-14 18:14:10 +00:00
|
|
|
"fmt"
|
2024-02-10 23:44:20 +00:00
|
|
|
"net/http"
|
|
|
|
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
"github.com/pikami/cosmium/internal/repositories"
|
2024-02-12 19:38:03 +00:00
|
|
|
repositorymodels "github.com/pikami/cosmium/internal/repository_models"
|
2024-02-10 23:44:20 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func GetPartitionKeyRanges(c *gin.Context) {
|
|
|
|
databaseId := c.Param("databaseId")
|
|
|
|
collectionId := c.Param("collId")
|
|
|
|
|
2024-02-14 18:14:10 +00:00
|
|
|
if c.Request.Header.Get("if-none-match") != "" {
|
|
|
|
c.AbortWithStatus(http.StatusNotModified)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2024-02-10 23:44:20 +00:00
|
|
|
partitionKeyRanges, status := repositories.GetPartitionKeyRanges(databaseId, collectionId)
|
2024-02-12 19:38:03 +00:00
|
|
|
if status == repositorymodels.StatusOk {
|
2024-02-14 18:14:10 +00:00
|
|
|
c.Header("etag", "\"420\"")
|
|
|
|
c.Header("lsn", "420")
|
|
|
|
c.Header("x-ms-cosmos-llsn", "420")
|
|
|
|
c.Header("x-ms-global-committed-lsn", "420")
|
|
|
|
c.Header("x-ms-item-count", fmt.Sprintf("%d", len(partitionKeyRanges)))
|
|
|
|
|
2024-02-27 18:08:48 +00:00
|
|
|
collectionRid := collectionId
|
2024-02-26 19:03:47 +00:00
|
|
|
collection, _ := repositories.GetCollection(databaseId, collectionId)
|
2024-02-27 18:08:48 +00:00
|
|
|
if collection.ResourceID != "" {
|
|
|
|
collectionRid = collection.ResourceID
|
|
|
|
}
|
|
|
|
|
2024-02-10 23:44:20 +00:00
|
|
|
c.IndentedJSON(http.StatusOK, gin.H{
|
2024-02-27 18:08:48 +00:00
|
|
|
"_rid": collectionRid,
|
2024-02-10 23:44:20 +00:00
|
|
|
"_count": len(partitionKeyRanges),
|
|
|
|
"PartitionKeyRanges": partitionKeyRanges,
|
|
|
|
})
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2024-02-12 19:38:03 +00:00
|
|
|
if status == repositorymodels.StatusNotFound {
|
2024-02-10 23:44:20 +00:00
|
|
|
c.IndentedJSON(http.StatusNotFound, gin.H{"message": "NotFound"})
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
c.IndentedJSON(http.StatusInternalServerError, gin.H{"message": "Unknown error"})
|
|
|
|
}
|