mirror of
https://github.com/pikami/cosmium.git
synced 2025-12-19 08:50:46 +00:00
Implement CRUD for UDFs, SPs and Triggers
This commit is contained in:
@@ -22,3 +22,97 @@ func (h *Handlers) GetAllStoredProcedures(c *gin.Context) {
|
||||
|
||||
c.IndentedJSON(http.StatusInternalServerError, gin.H{"message": "Unknown error"})
|
||||
}
|
||||
|
||||
func (h *Handlers) GetStoredProcedure(c *gin.Context) {
|
||||
databaseId := c.Param("databaseId")
|
||||
collectionId := c.Param("collId")
|
||||
spId := c.Param("spId")
|
||||
|
||||
sp, status := h.repository.GetStoredProcedure(databaseId, collectionId, spId)
|
||||
|
||||
if status == repositorymodels.StatusOk {
|
||||
c.IndentedJSON(http.StatusOK, sp)
|
||||
return
|
||||
}
|
||||
|
||||
if status == repositorymodels.StatusNotFound {
|
||||
c.IndentedJSON(http.StatusNotFound, gin.H{"message": "NotFound"})
|
||||
return
|
||||
}
|
||||
|
||||
c.IndentedJSON(http.StatusInternalServerError, gin.H{"message": "Unknown error"})
|
||||
}
|
||||
|
||||
func (h *Handlers) DeleteStoredProcedure(c *gin.Context) {
|
||||
databaseId := c.Param("databaseId")
|
||||
collectionId := c.Param("collId")
|
||||
spId := c.Param("spId")
|
||||
|
||||
status := h.repository.DeleteStoredProcedure(databaseId, collectionId, spId)
|
||||
if status == repositorymodels.StatusOk {
|
||||
c.Status(http.StatusNoContent)
|
||||
return
|
||||
}
|
||||
|
||||
if status == repositorymodels.StatusNotFound {
|
||||
c.IndentedJSON(http.StatusNotFound, gin.H{"message": "NotFound"})
|
||||
return
|
||||
}
|
||||
|
||||
c.IndentedJSON(http.StatusInternalServerError, gin.H{"message": "Unknown error"})
|
||||
}
|
||||
|
||||
func (h *Handlers) ReplaceStoredProcedure(c *gin.Context) {
|
||||
databaseId := c.Param("databaseId")
|
||||
collectionId := c.Param("collId")
|
||||
spId := c.Param("spId")
|
||||
|
||||
var sp repositorymodels.StoredProcedure
|
||||
if err := c.BindJSON(&sp); err != nil {
|
||||
c.IndentedJSON(http.StatusBadRequest, gin.H{"message": "Invalid body"})
|
||||
return
|
||||
}
|
||||
|
||||
status := h.repository.DeleteStoredProcedure(databaseId, collectionId, spId)
|
||||
if status == repositorymodels.StatusNotFound {
|
||||
c.IndentedJSON(http.StatusNotFound, gin.H{"message": "NotFound"})
|
||||
return
|
||||
}
|
||||
|
||||
createdSP, status := h.repository.CreateStoredProcedure(databaseId, collectionId, sp)
|
||||
if status == repositorymodels.Conflict {
|
||||
c.IndentedJSON(http.StatusConflict, gin.H{"message": "Conflict"})
|
||||
return
|
||||
}
|
||||
|
||||
if status == repositorymodels.StatusOk {
|
||||
c.IndentedJSON(http.StatusOK, createdSP)
|
||||
return
|
||||
}
|
||||
|
||||
c.IndentedJSON(http.StatusInternalServerError, gin.H{"message": "Unknown error"})
|
||||
}
|
||||
|
||||
func (h *Handlers) CreateStoredProcedure(c *gin.Context) {
|
||||
databaseId := c.Param("databaseId")
|
||||
collectionId := c.Param("collId")
|
||||
|
||||
var sp repositorymodels.StoredProcedure
|
||||
if err := c.BindJSON(&sp); err != nil {
|
||||
c.IndentedJSON(http.StatusBadRequest, gin.H{"message": "Invalid body"})
|
||||
return
|
||||
}
|
||||
|
||||
createdSP, status := h.repository.CreateStoredProcedure(databaseId, collectionId, sp)
|
||||
if status == repositorymodels.Conflict {
|
||||
c.IndentedJSON(http.StatusConflict, gin.H{"message": "Conflict"})
|
||||
return
|
||||
}
|
||||
|
||||
if status == repositorymodels.StatusOk {
|
||||
c.IndentedJSON(http.StatusCreated, createdSP)
|
||||
return
|
||||
}
|
||||
|
||||
c.IndentedJSON(http.StatusInternalServerError, gin.H{"message": "Unknown error"})
|
||||
}
|
||||
|
||||
@@ -22,3 +22,97 @@ func (h *Handlers) GetAllTriggers(c *gin.Context) {
|
||||
|
||||
c.IndentedJSON(http.StatusInternalServerError, gin.H{"message": "Unknown error"})
|
||||
}
|
||||
|
||||
func (h *Handlers) GetTrigger(c *gin.Context) {
|
||||
databaseId := c.Param("databaseId")
|
||||
collectionId := c.Param("collId")
|
||||
triggerId := c.Param("triggerId")
|
||||
|
||||
trigger, status := h.repository.GetTrigger(databaseId, collectionId, triggerId)
|
||||
|
||||
if status == repositorymodels.StatusOk {
|
||||
c.IndentedJSON(http.StatusOK, trigger)
|
||||
return
|
||||
}
|
||||
|
||||
if status == repositorymodels.StatusNotFound {
|
||||
c.IndentedJSON(http.StatusNotFound, gin.H{"message": "NotFound"})
|
||||
return
|
||||
}
|
||||
|
||||
c.IndentedJSON(http.StatusInternalServerError, gin.H{"message": "Unknown error"})
|
||||
}
|
||||
|
||||
func (h *Handlers) DeleteTrigger(c *gin.Context) {
|
||||
databaseId := c.Param("databaseId")
|
||||
collectionId := c.Param("collId")
|
||||
triggerId := c.Param("triggerId")
|
||||
|
||||
status := h.repository.DeleteTrigger(databaseId, collectionId, triggerId)
|
||||
if status == repositorymodels.StatusOk {
|
||||
c.Status(http.StatusNoContent)
|
||||
return
|
||||
}
|
||||
|
||||
if status == repositorymodels.StatusNotFound {
|
||||
c.IndentedJSON(http.StatusNotFound, gin.H{"message": "NotFound"})
|
||||
return
|
||||
}
|
||||
|
||||
c.IndentedJSON(http.StatusInternalServerError, gin.H{"message": "Unknown error"})
|
||||
}
|
||||
|
||||
func (h *Handlers) ReplaceTrigger(c *gin.Context) {
|
||||
databaseId := c.Param("databaseId")
|
||||
collectionId := c.Param("collId")
|
||||
triggerId := c.Param("triggerId")
|
||||
|
||||
var trigger repositorymodels.Trigger
|
||||
if err := c.BindJSON(&trigger); err != nil {
|
||||
c.IndentedJSON(http.StatusBadRequest, gin.H{"message": "Invalid body"})
|
||||
return
|
||||
}
|
||||
|
||||
status := h.repository.DeleteTrigger(databaseId, collectionId, triggerId)
|
||||
if status == repositorymodels.StatusNotFound {
|
||||
c.IndentedJSON(http.StatusNotFound, gin.H{"message": "NotFound"})
|
||||
return
|
||||
}
|
||||
|
||||
createdTrigger, status := h.repository.CreateTrigger(databaseId, collectionId, trigger)
|
||||
if status == repositorymodels.Conflict {
|
||||
c.IndentedJSON(http.StatusConflict, gin.H{"message": "Conflict"})
|
||||
return
|
||||
}
|
||||
|
||||
if status == repositorymodels.StatusOk {
|
||||
c.IndentedJSON(http.StatusOK, createdTrigger)
|
||||
return
|
||||
}
|
||||
|
||||
c.IndentedJSON(http.StatusInternalServerError, gin.H{"message": "Unknown error"})
|
||||
}
|
||||
|
||||
func (h *Handlers) CreateTrigger(c *gin.Context) {
|
||||
databaseId := c.Param("databaseId")
|
||||
collectionId := c.Param("collId")
|
||||
|
||||
var trigger repositorymodels.Trigger
|
||||
if err := c.BindJSON(&trigger); err != nil {
|
||||
c.IndentedJSON(http.StatusBadRequest, gin.H{"message": "Invalid body"})
|
||||
return
|
||||
}
|
||||
|
||||
createdTrigger, status := h.repository.CreateTrigger(databaseId, collectionId, trigger)
|
||||
if status == repositorymodels.Conflict {
|
||||
c.IndentedJSON(http.StatusConflict, gin.H{"message": "Conflict"})
|
||||
return
|
||||
}
|
||||
|
||||
if status == repositorymodels.StatusOk {
|
||||
c.IndentedJSON(http.StatusCreated, createdTrigger)
|
||||
return
|
||||
}
|
||||
|
||||
c.IndentedJSON(http.StatusInternalServerError, gin.H{"message": "Unknown error"})
|
||||
}
|
||||
|
||||
@@ -22,3 +22,97 @@ func (h *Handlers) GetAllUserDefinedFunctions(c *gin.Context) {
|
||||
|
||||
c.IndentedJSON(http.StatusInternalServerError, gin.H{"message": "Unknown error"})
|
||||
}
|
||||
|
||||
func (h *Handlers) GetUserDefinedFunction(c *gin.Context) {
|
||||
databaseId := c.Param("databaseId")
|
||||
collectionId := c.Param("collId")
|
||||
udfId := c.Param("udfId")
|
||||
|
||||
udf, status := h.repository.GetUserDefinedFunction(databaseId, collectionId, udfId)
|
||||
|
||||
if status == repositorymodels.StatusOk {
|
||||
c.IndentedJSON(http.StatusOK, udf)
|
||||
return
|
||||
}
|
||||
|
||||
if status == repositorymodels.StatusNotFound {
|
||||
c.IndentedJSON(http.StatusNotFound, gin.H{"message": "NotFound"})
|
||||
return
|
||||
}
|
||||
|
||||
c.IndentedJSON(http.StatusInternalServerError, gin.H{"message": "Unknown error"})
|
||||
}
|
||||
|
||||
func (h *Handlers) DeleteUserDefinedFunction(c *gin.Context) {
|
||||
databaseId := c.Param("databaseId")
|
||||
collectionId := c.Param("collId")
|
||||
udfId := c.Param("udfId")
|
||||
|
||||
status := h.repository.DeleteUserDefinedFunction(databaseId, collectionId, udfId)
|
||||
if status == repositorymodels.StatusOk {
|
||||
c.Status(http.StatusNoContent)
|
||||
return
|
||||
}
|
||||
|
||||
if status == repositorymodels.StatusNotFound {
|
||||
c.IndentedJSON(http.StatusNotFound, gin.H{"message": "NotFound"})
|
||||
return
|
||||
}
|
||||
|
||||
c.IndentedJSON(http.StatusInternalServerError, gin.H{"message": "Unknown error"})
|
||||
}
|
||||
|
||||
func (h *Handlers) ReplaceUserDefinedFunction(c *gin.Context) {
|
||||
databaseId := c.Param("databaseId")
|
||||
collectionId := c.Param("collId")
|
||||
udfId := c.Param("udfId")
|
||||
|
||||
var udf repositorymodels.UserDefinedFunction
|
||||
if err := c.BindJSON(&udf); err != nil {
|
||||
c.IndentedJSON(http.StatusBadRequest, gin.H{"message": "Invalid body"})
|
||||
return
|
||||
}
|
||||
|
||||
status := h.repository.DeleteUserDefinedFunction(databaseId, collectionId, udfId)
|
||||
if status == repositorymodels.StatusNotFound {
|
||||
c.IndentedJSON(http.StatusNotFound, gin.H{"message": "NotFound"})
|
||||
return
|
||||
}
|
||||
|
||||
createdUdf, status := h.repository.CreateUserDefinedFunction(databaseId, collectionId, udf)
|
||||
if status == repositorymodels.Conflict {
|
||||
c.IndentedJSON(http.StatusConflict, gin.H{"message": "Conflict"})
|
||||
return
|
||||
}
|
||||
|
||||
if status == repositorymodels.StatusOk {
|
||||
c.IndentedJSON(http.StatusOK, createdUdf)
|
||||
return
|
||||
}
|
||||
|
||||
c.IndentedJSON(http.StatusInternalServerError, gin.H{"message": "Unknown error"})
|
||||
}
|
||||
|
||||
func (h *Handlers) CreateUserDefinedFunction(c *gin.Context) {
|
||||
databaseId := c.Param("databaseId")
|
||||
collectionId := c.Param("collId")
|
||||
|
||||
var udf repositorymodels.UserDefinedFunction
|
||||
if err := c.BindJSON(&udf); err != nil {
|
||||
c.IndentedJSON(http.StatusBadRequest, gin.H{"message": "Invalid body"})
|
||||
return
|
||||
}
|
||||
|
||||
createdUdf, status := h.repository.CreateUserDefinedFunction(databaseId, collectionId, udf)
|
||||
if status == repositorymodels.Conflict {
|
||||
c.IndentedJSON(http.StatusConflict, gin.H{"message": "Conflict"})
|
||||
return
|
||||
}
|
||||
|
||||
if status == repositorymodels.StatusOk {
|
||||
c.IndentedJSON(http.StatusCreated, createdUdf)
|
||||
return
|
||||
}
|
||||
|
||||
c.IndentedJSON(http.StatusInternalServerError, gin.H{"message": "Unknown error"})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user