mirror of https://github.com/pikami/cosmium.git
Implement Document update
This commit is contained in:
parent
b45431cd01
commit
a656f33009
|
@ -60,6 +60,38 @@ func DeleteDocument(c *gin.Context) {
|
||||||
c.IndentedJSON(http.StatusInternalServerError, gin.H{"message": "Unknown error"})
|
c.IndentedJSON(http.StatusInternalServerError, gin.H{"message": "Unknown error"})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: Maybe move "replace" logic to repository
|
||||||
|
func ReplaceDocument(c *gin.Context) {
|
||||||
|
databaseId := c.Param("databaseId")
|
||||||
|
collectionId := c.Param("collId")
|
||||||
|
documentId := c.Param("docId")
|
||||||
|
|
||||||
|
var requestBody map[string]interface{}
|
||||||
|
if err := c.BindJSON(&requestBody); err != nil {
|
||||||
|
c.JSON(http.StatusBadRequest, gin.H{"message": err.Error()})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
status := repositories.DeleteDocument(databaseId, collectionId, documentId)
|
||||||
|
if status == repositorymodels.StatusNotFound {
|
||||||
|
c.IndentedJSON(http.StatusNotFound, gin.H{"message": "NotFound"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
status = repositories.CreateDocument(databaseId, collectionId, requestBody)
|
||||||
|
if status == repositorymodels.Conflict {
|
||||||
|
c.IndentedJSON(http.StatusConflict, gin.H{"message": "Conflict"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if status == repositorymodels.StatusOk {
|
||||||
|
c.IndentedJSON(http.StatusCreated, requestBody)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
c.IndentedJSON(http.StatusInternalServerError, gin.H{"message": "Unknown error"})
|
||||||
|
}
|
||||||
|
|
||||||
func DocumentsPost(c *gin.Context) {
|
func DocumentsPost(c *gin.Context) {
|
||||||
databaseId := c.Param("databaseId")
|
databaseId := c.Param("databaseId")
|
||||||
collectionId := c.Param("collId")
|
collectionId := c.Param("collId")
|
||||||
|
|
|
@ -16,6 +16,7 @@ func CreateRouter() *gin.Engine {
|
||||||
router.POST("/dbs/:databaseId/colls/:collId/docs", handlers.DocumentsPost)
|
router.POST("/dbs/:databaseId/colls/:collId/docs", handlers.DocumentsPost)
|
||||||
router.GET("/dbs/:databaseId/colls/:collId/docs", handlers.GetAllDocuments)
|
router.GET("/dbs/:databaseId/colls/:collId/docs", handlers.GetAllDocuments)
|
||||||
router.GET("/dbs/:databaseId/colls/:collId/docs/:docId", handlers.GetDocument)
|
router.GET("/dbs/:databaseId/colls/:collId/docs/:docId", handlers.GetDocument)
|
||||||
|
router.PUT("/dbs/:databaseId/colls/:collId/docs/:docId", handlers.ReplaceDocument)
|
||||||
router.DELETE("/dbs/:databaseId/colls/:collId/docs/:docId", handlers.DeleteDocument)
|
router.DELETE("/dbs/:databaseId/colls/:collId/docs/:docId", handlers.DeleteDocument)
|
||||||
|
|
||||||
router.POST("/dbs/:databaseId/colls", handlers.CreateCollection)
|
router.POST("/dbs/:databaseId/colls", handlers.CreateCollection)
|
||||||
|
|
Loading…
Reference in New Issue