First version of web UI

This commit is contained in:
Senad Uka
2022-02-13 05:12:49 +01:00
parent a040320827
commit f6e90deebd
9 changed files with 274 additions and 34 deletions

View File

@@ -4,7 +4,6 @@ import (
"database/sql"
"fmt"
_ "github.com/lib/pq"
"gitlab.com/kbr4/svevijesti/internal/model"
)
const (
@@ -24,36 +23,3 @@ func Connect() (*Store, error) {
db, err := sql.Open("postgres", psqlInfo)
return db, err
}
func InsertArticle(store *Store, article model.ScrapedArticle) (err error) {
query := `
INSERT INTO articles
(title, content, slug, original_url, source_id)
VALUES
($1,$2,$3,$4,$5);`
_, err = store.Exec(query, article.Title, article.Content, article.Slug, article.OriginalUrl, article.SourceId)
if err != nil {
return err
}
return nil
}
func IsSaved(store *Store, url string) bool {
exists := false
query, err := store.Prepare(`
select exists(select 1 from articles where original_url = $1);
`)
if err != nil {
panic(err)
}
row := query.QueryRow(url)
err = row.Scan(&exists)
if err != nil {
panic(err)
}
return exists
}