go-pingbot/website/routes/api/delete.go

51 lines
784 B
Go
Raw Normal View History

2021-07-11 21:19:37 +00:00
package api
import (
"encoding/base64"
"net/http"
"github.com/gin-gonic/gin"
2021-07-29 18:51:15 +00:00
"gitlab.com/gaming0skar123/go/pingbot/database/mongo"
2021-07-11 21:19:37 +00:00
)
func Delete(c *gin.Context) {
url := c.Param("url")
d, err := base64.StdEncoding.DecodeString(url)
if err != nil {
c.JSON(http.StatusBadRequest, json{
2021-07-11 21:19:37 +00:00
"success": false,
"message": "Error Parsing Base64!",
})
return
}
url = string(d)
2021-08-01 17:43:59 +00:00
r, err := mongo.Delete(url)
2021-07-11 21:19:37 +00:00
if r.DeletedCount <= 0 {
c.JSON(http.StatusNotFound, json{
2021-07-11 21:19:37 +00:00
"success": false,
2021-08-01 18:26:48 +00:00
"message": "Not Found!",
2021-07-11 21:19:37 +00:00
})
return
}
if err != nil {
c.JSON(http.StatusInternalServerError, json{
2021-07-11 21:19:37 +00:00
"success": false,
"message": "Error Deleting from Database!",
})
return
}
c.JSON(http.StatusOK, json{
2021-07-11 21:19:37 +00:00
"success": true,
"message": "Deleted!",
2021-07-11 21:19:37 +00:00
})
}