mirror of
https://github.com/Starlio-app/StarlioX
synced 2024-12-23 13:43:46 +03:00
add favorites image
This commit is contained in:
parent
d054fb63a9
commit
f9022a5182
4 changed files with 255 additions and 0 deletions
133
api/controllers/favorite.go
Normal file
133
api/controllers/favorite.go
Normal file
|
@ -0,0 +1,133 @@
|
|||
package controllers
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"github.com/Redume/EveryNasa/api/utils"
|
||||
"github.com/Redume/EveryNasa/functions"
|
||||
"github.com/gofiber/fiber/v2"
|
||||
)
|
||||
|
||||
var GetFavorites = func(c *fiber.Ctx) error {
|
||||
FavoriteTitle := c.Query("title")
|
||||
|
||||
type Favorite struct {
|
||||
Title string `json:"title"`
|
||||
Explanation string `json:"explanation"`
|
||||
Date string `json:"date"`
|
||||
URL string `json:"url"`
|
||||
HDURL string `json:"hdurl"`
|
||||
MediaType string `json:"media_type"`
|
||||
}
|
||||
|
||||
var title, explanation, date, url, hdurl, media_type string
|
||||
db := functions.GetDatabase()
|
||||
|
||||
if FavoriteTitle != "" {
|
||||
queryFavorites, err := db.Query("SELECT * FROM favorite WHERE title LIKE ?", FavoriteTitle)
|
||||
if err != nil {
|
||||
functions.Logger(err.Error())
|
||||
}
|
||||
|
||||
defer func(query *sql.Rows) {
|
||||
err := query.Close()
|
||||
if err != nil {
|
||||
functions.Logger(err.Error())
|
||||
}
|
||||
}(queryFavorites)
|
||||
|
||||
for queryFavorites.Next() {
|
||||
err := queryFavorites.Scan(&title, &explanation, &date, &url, &hdurl, &media_type)
|
||||
if err != nil {
|
||||
functions.Logger(err.Error())
|
||||
}
|
||||
|
||||
return c.JSON(fiber.Map{
|
||||
"title": title,
|
||||
"explanation": explanation,
|
||||
"date": date,
|
||||
"url": url,
|
||||
"hdurl": hdurl,
|
||||
"media_type": media_type,
|
||||
})
|
||||
}
|
||||
} else {
|
||||
queryFavorite, err := db.Query("SELECT * FROM favorite")
|
||||
if err != nil {
|
||||
functions.Logger(err.Error())
|
||||
}
|
||||
|
||||
defer func(query *sql.Rows) {
|
||||
err := query.Close()
|
||||
if err != nil {
|
||||
functions.Logger(err.Error())
|
||||
}
|
||||
}(queryFavorite)
|
||||
var favorites []Favorite
|
||||
for queryFavorite.Next() {
|
||||
err := queryFavorite.Scan(&title, &explanation, &date, &url, &hdurl, &media_type)
|
||||
if err != nil {
|
||||
functions.Logger(err.Error())
|
||||
}
|
||||
|
||||
favorites = append(favorites, Favorite{
|
||||
Title: title,
|
||||
Explanation: explanation,
|
||||
Date: date,
|
||||
URL: url,
|
||||
HDURL: hdurl,
|
||||
MediaType: media_type})
|
||||
}
|
||||
|
||||
return c.JSON(favorites)
|
||||
}
|
||||
|
||||
return c.SendString("No favorites found")
|
||||
}
|
||||
|
||||
var AddFavorite = func(c *fiber.Ctx) error {
|
||||
title := c.FormValue("title")
|
||||
explanation := c.FormValue("explanation")
|
||||
date := c.FormValue("date")
|
||||
url := c.FormValue("url")
|
||||
hdurl := c.FormValue("hdurl")
|
||||
media_type := c.FormValue("media_type")
|
||||
|
||||
fmt.Println(title, explanation, date, url, hdurl, media_type)
|
||||
|
||||
if title == "" && explanation == "" && date == "" && url == "" && hdurl == "" && media_type == "" {
|
||||
utils.Respond(c, utils.Message(false, "All fields are required"))
|
||||
return nil
|
||||
}
|
||||
|
||||
db := functions.GetDatabase()
|
||||
|
||||
_, err := db.Exec("INSERT INTO favorite (title, explanation, date, url, hdurl, media_type) VALUES (?, ?, ?, ?, ?, ?)",
|
||||
title,
|
||||
explanation,
|
||||
date,
|
||||
url,
|
||||
hdurl,
|
||||
media_type)
|
||||
|
||||
if err != nil {
|
||||
functions.Logger(err.Error())
|
||||
}
|
||||
|
||||
utils.Respond(c, utils.Message(true, "Favorite added"))
|
||||
return nil
|
||||
}
|
||||
|
||||
var DeleteFavorite = func(c *fiber.Ctx) error {
|
||||
title := c.FormValue("title")
|
||||
|
||||
db := functions.GetDatabase()
|
||||
|
||||
_, err := db.Exec("DELETE FROM favorite WHERE title = ?", title)
|
||||
if err != nil {
|
||||
functions.Logger(err.Error())
|
||||
}
|
||||
|
||||
utils.Respond(c, utils.Message(true, "Favorite deleted"))
|
||||
return nil
|
||||
}
|
15
web/page/favorite.go
Normal file
15
web/page/favorite.go
Normal file
|
@ -0,0 +1,15 @@
|
|||
package page
|
||||
|
||||
import (
|
||||
"github.com/Redume/EveryNasa/functions"
|
||||
"github.com/gofiber/fiber/v2"
|
||||
)
|
||||
|
||||
func Favorite(c *fiber.Ctx) error {
|
||||
con := functions.Connected()
|
||||
if con == false {
|
||||
return c.SendFile("./web/errors/500.html")
|
||||
}
|
||||
|
||||
return c.SendFile("./web/src/favorite.html")
|
||||
}
|
98
web/src/favorite.html
Normal file
98
web/src/favorite.html
Normal file
|
@ -0,0 +1,98 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>EveryNasa</title>
|
||||
|
||||
<link rel="icon" href="/static/image/icons/favicon.png">
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-iYQeCzEYFbKjA/T2uDLTpkwGzCiq6soy8tYaI1GyVh/UjpbCx/TYkiZhlZB6+fzT" crossorigin="anonymous">
|
||||
<link rel="stylesheet" href="/static/style/gallery.css" type="text/css">
|
||||
<link rel="stylesheet" href="/static/style/favorite.css" type="text/css">
|
||||
</head>
|
||||
<nav class="navbar navbar-expand-lg bg-dark navbar-dark">
|
||||
<div class="container-fluid">
|
||||
<a class="navbar-brand" href="/" draggable="false">
|
||||
<img src="/static/image/icons/favicon.png" width="45" alt="EveryNasa">
|
||||
</a>
|
||||
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNavDropdown" aria-controls="navbarNavDropdown" aria-expanded="false" aria-label="Toggle navigation">
|
||||
<span class="navbar-toggler-icon"></span>
|
||||
</button>
|
||||
<div class="collapse navbar-collapse" id="navbarNavDropdown">
|
||||
<ul class="navbar-nav">
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="/">Gallery</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link active" aria-current="page" href="/favorite">Favorite</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="/settings">Settings</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="/about">About</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
<div class="modal fade" id="WallpaperModal" aria-hidden="true" aria-labelledby="WallpaperModal" tabindex="-1" style="color: black;">
|
||||
<div class="modal-dialog modal-dialog-centered">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title" id="WallpaperModale">
|
||||
<span class="d-inline-block text-truncate w-modal-title" style="max-width: 429px;"></span>
|
||||
</h5>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
||||
</div>
|
||||
<div class="modal-body"></div>
|
||||
<div class="modal-footer">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="container">
|
||||
<header class="header-row"></header>
|
||||
</div>
|
||||
<div class="preloader">
|
||||
<lottie-player src="https://assets4.lottiefiles.com/datafiles/a3YH0ragZcwfKHS/data.json" background="transparent" speed="1" style="width: 600px; height: 600px;" loop autoplay></lottie-player>
|
||||
</div>
|
||||
<body>
|
||||
<script src="https://code.jquery.com/jquery-3.6.1.min.js"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.1/dist/js/bootstrap.min.js" integrity="sha384-7VPbUDkoPSGFnVtYi0QogXtr74QeVeeIs99Qfg5YCF+TidwNdjvaKZX19NZ/e6oz" crossorigin="anonymous"></script>
|
||||
<script src="https://unpkg.com/@lottiefiles/lottie-player@latest/dist/lottie-player.js"></script>
|
||||
<script src="/static/scripts/analytics.js" type="module"></script>
|
||||
<script src="/static/scripts/gallery.js" type="application/javascript"></script>
|
||||
<script type="application/javascript">
|
||||
$(document).ready(function () {
|
||||
$.ajax({
|
||||
url: "http://localhost:3000/api/get/favorites",
|
||||
type: "GET",
|
||||
success: function(data) {
|
||||
console.log(data);
|
||||
if(data === null) {
|
||||
$(".preloader").hide();
|
||||
$("body").append(`
|
||||
<lottie-player id="star"
|
||||
src="https://assets2.lottiefiles.com/private_files/lf30_rcvcAS.json"
|
||||
background="transparent"
|
||||
autoplay
|
||||
speed="1">
|
||||
</lottie-player>
|
||||
|
||||
<div class="container">
|
||||
<div class="row">
|
||||
<div class="col-12">
|
||||
<h1 class="text-center" style="color: white; margin-top: -5%">You don't have any favorites</h1>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
`);
|
||||
}
|
||||
|
||||
wallpaperLoad(data);
|
||||
},
|
||||
});
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
9
web/static/style/favorite.css
Normal file
9
web/static/style/favorite.css
Normal file
|
@ -0,0 +1,9 @@
|
|||
body {
|
||||
background-color: #131313;
|
||||
}
|
||||
|
||||
lottie-player {
|
||||
width: 30%;
|
||||
height: 30%;
|
||||
margin-top: -10%;
|
||||
}
|
Loading…
Add table
Reference in a new issue