2021-07-11 21:19:37 +00:00
|
|
|
package api
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"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 GetAll(c *gin.Context) {
|
2021-07-29 18:51:15 +00:00
|
|
|
results, err := mongo.GetAll()
|
2021-07-11 21:19:37 +00:00
|
|
|
// Error Handling
|
|
|
|
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 fetching URLs!",
|
|
|
|
})
|
|
|
|
fmt.Println(err)
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// DB Is Empty
|
|
|
|
if results == nil {
|
2021-07-22 08:23:49 +00:00
|
|
|
c.JSON(http.StatusNotFound, json{
|
2021-07-11 21:19:37 +00:00
|
|
|
"success": false,
|
|
|
|
"message": "Database is empty!",
|
|
|
|
})
|
|
|
|
|
|
|
|
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-31 20:59:43 +00:00
|
|
|
"db": results,
|
2021-07-11 21:19:37 +00:00
|
|
|
})
|
|
|
|
}
|