mirror of
https://github.com/pikami/cosmium.git
synced 2024-12-02 18:37:52 +00:00
44 lines
1.1 KiB
Go
44 lines
1.1 KiB
Go
package handlers
|
|
|
|
import (
|
|
"fmt"
|
|
"net/http"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/pikami/cosmium/internal/repositories"
|
|
repositorymodels "github.com/pikami/cosmium/internal/repository_models"
|
|
)
|
|
|
|
func GetPartitionKeyRanges(c *gin.Context) {
|
|
databaseId := c.Param("databaseId")
|
|
collectionId := c.Param("collId")
|
|
|
|
if c.Request.Header.Get("if-none-match") != "" {
|
|
c.AbortWithStatus(http.StatusNotModified)
|
|
return
|
|
}
|
|
|
|
partitionKeyRanges, status := repositories.GetPartitionKeyRanges(databaseId, collectionId)
|
|
if status == repositorymodels.StatusOk {
|
|
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)))
|
|
|
|
c.IndentedJSON(http.StatusOK, gin.H{
|
|
"_rid": "",
|
|
"_count": len(partitionKeyRanges),
|
|
"PartitionKeyRanges": partitionKeyRanges,
|
|
})
|
|
return
|
|
}
|
|
|
|
if status == repositorymodels.StatusNotFound {
|
|
c.IndentedJSON(http.StatusNotFound, gin.H{"message": "NotFound"})
|
|
return
|
|
}
|
|
|
|
c.IndentedJSON(http.StatusInternalServerError, gin.H{"message": "Unknown error"})
|
|
}
|