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

39 lines
595 B
Go
Raw Normal View History

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 {
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 {
c.JSON(http.StatusNotFound, json{
2021-07-11 21:19:37 +00:00
"success": false,
"message": "Database is empty!",
})
return
}
c.JSON(http.StatusOK, json{
2021-07-11 21:19:37 +00:00
"success": true,
"db": results,
2021-07-11 21:19:37 +00:00
})
}