mirror of
https://github.com/pikami/cosmium.git
synced 2025-10-17 17:19:50 +01:00
53 lines
1.5 KiB
Go
53 lines
1.5 KiB
Go
package handlers
|
|
|
|
import (
|
|
"fmt"
|
|
"net/http"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/pikami/cosmium/api/headers"
|
|
"github.com/pikami/cosmium/internal/constants"
|
|
"github.com/pikami/cosmium/internal/datastore"
|
|
"github.com/pikami/cosmium/internal/resourceid"
|
|
)
|
|
|
|
func (h *Handlers) GetPartitionKeyRanges(c *gin.Context) {
|
|
databaseId := c.Param("databaseId")
|
|
collectionId := c.Param("collId")
|
|
|
|
if c.Request.Header.Get(headers.IfNoneMatch) != "" {
|
|
c.AbortWithStatus(http.StatusNotModified)
|
|
return
|
|
}
|
|
|
|
partitionKeyRanges, status := h.dataStore.GetPartitionKeyRanges(databaseId, collectionId)
|
|
if status == datastore.StatusOk {
|
|
c.Header(headers.ETag, "\"420\"")
|
|
c.Header(headers.LSN, "420")
|
|
c.Header(headers.CosmosLsn, "420")
|
|
c.Header(headers.GlobalCommittedLsn, "420")
|
|
c.Header(headers.ItemCount, fmt.Sprintf("%d", len(partitionKeyRanges)))
|
|
|
|
collectionRid := collectionId
|
|
collection, _ := h.dataStore.GetCollection(databaseId, collectionId)
|
|
if collection.ResourceID != "" {
|
|
collectionRid = collection.ResourceID
|
|
}
|
|
|
|
rid := resourceid.NewCombined(collectionRid, resourceid.New(resourceid.ResourceTypePartitionKeyRange))
|
|
c.IndentedJSON(http.StatusOK, gin.H{
|
|
"_rid": rid,
|
|
"_count": len(partitionKeyRanges),
|
|
"PartitionKeyRanges": partitionKeyRanges,
|
|
})
|
|
return
|
|
}
|
|
|
|
if status == datastore.StatusNotFound {
|
|
c.IndentedJSON(http.StatusNotFound, constants.NotFoundResponse)
|
|
return
|
|
}
|
|
|
|
c.IndentedJSON(http.StatusInternalServerError, constants.UnknownErrorResponse)
|
|
}
|