check isUpsert header in POST document request (#5)

* check isUpsert header in POST document request

* Verify response code on "CreateItem that already exists" test

---------

Co-authored-by: Pijus Kamandulis <[email protected]>
This commit is contained in:
erikzenecoandPijus Kamandulis authored and GitHub committed 2024-11-01 21:11:59 +02:00
1 parent a6b5d32ff7
commit 2834f3f641
2 files changed
+94

No files matched your search

+6
View File
@@ -4,6 +4,7 @@ import (
"encoding/json"
"fmt"
"net/http"
"strconv"
jsonpatch "github.com/evanphx/json-patch/v5"
"github.com/gin-gonic/gin"
@@ -223,6 +224,11 @@ func DocumentsPost(c *gin.Context) {
return
}
isUpsert, _ := strconv.ParseBool(c.GetHeader("x-ms-documentdb-is-upsert"))
if isUpsert {
repositories.DeleteDocument(databaseId, collectionId, requestBody["id"].(string))
}
createdDocument, status := repositories.CreateDocument(databaseId, collectionId, requestBody)
if status == repositorymodels.Conflict {
c.IndentedJSON(http.StatusConflict, gin.H{"message": "Conflict"})