2021-07-11 21:19:37 +00:00
|
|
|
package api
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
"gitlab.com/gaming0skar123/go/pingbot/database"
|
|
|
|
)
|
|
|
|
|
|
|
|
func GetAll(c *gin.Context) {
|
|
|
|
results, err := database.GetAll()
|
|
|
|
|
|
|
|
// Error Handling
|
|
|
|
if err != nil {
|
|
|
|
c.JSON(http.StatusInternalServerError, gin.H{
|
|
|
|
"success": false,
|
|
|
|
"message": "Error fetching URLs!",
|
|
|
|
})
|
|
|
|
fmt.Println(err)
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// DB Is Empty
|
|
|
|
if results == nil {
|
|
|
|
c.JSON(http.StatusInternalServerError, gin.H{
|
|
|
|
"success": false,
|
|
|
|
"message": "Database is empty!",
|
|
|
|
})
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-07-19 14:24:33 +00:00
|
|
|
var db []database.URL
|
2021-07-11 21:19:37 +00:00
|
|
|
|
|
|
|
for _, value := range results {
|
2021-07-19 14:24:33 +00:00
|
|
|
db = append(db, database.URL{
|
|
|
|
URL: value.URL,
|
2021-07-11 21:19:37 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
c.JSON(http.StatusOK, gin.H{
|
|
|
|
"success": true,
|
|
|
|
"db": db,
|
|
|
|
})
|
|
|
|
}
|