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 {
|
2021-07-22 08:23:49 +00:00
|
|
|
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 {
|
2021-07-22 08:23:49 +00:00
|
|
|
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 {
|
2021-07-22 08:23:49 +00:00
|
|
|
c.JSON(http.StatusInternalServerError, json{
|
2021-07-11 21:19:37 +00:00
|
|
|
"success": false,
|
|
|
|
"message": "Error Deleting from Database!",
|
|
|
|
})
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-07-22 08:23:49 +00:00
|
|
|
c.JSON(http.StatusOK, json{
|
2021-07-11 21:19:37 +00:00
|
|
|
"success": true,
|
2021-07-22 08:23:49 +00:00
|
|
|
"message": "Deleted!",
|
2021-07-11 21:19:37 +00:00
|
|
|
})
|
|
|
|
}
|