diff --git a/internal/database/queries.go b/internal/database/queries.go
index 75e7267..a71c720 100644
--- a/internal/database/queries.go
+++ b/internal/database/queries.go
)
type Article struct {
- Id int
- Title string
- Content string
- Picture string
- Category string
+ Id int
+ Title string
+ Content string
+ Picture string
+ CategoryId string
}
type Category struct {
}
func GetArticles(db *sql.DB) ([]Article, error) {
- rows, err := db.Query("SELECT article_id, article_title, article_content, article_picture, category_name FROM articles INNER JOIN categories ON articles.category_id = categories.category_id;")
+ rows, err := db.Query("SELECT * FROM articles")
if err != nil {
return nil, err
}
for rows.Next() {
article := Article{}
- if err := rows.Scan(&article.Id, &article.Title, &article.Content, &article.Picture, &article.Category); err != nil {
+ var category_id sql.NullString
+ if err := rows.Scan(&article.Id, &article.Title, &article.Content, &article.Picture, &category_id); err != nil {
return nil, err
}
+ if category_id.Valid {
+ article.CategoryId = category_id.String
+ }
articles = append(articles, article)
}
}
func GetCategoryArticles(db *sql.DB, category string) ([]Article, error) {
- stmtOut, err := db.Prepare("SELECT article_id, article_title, article_content, article_picture, category_name FROM articles INNER JOIN categories ON articles.category_id = categories.category_id WHERE category_name = ?;")
+ stmtOut, err := db.Prepare("SELECT article_id, article_title, article_content, article_picture FROM articles INNER JOIN categories ON articles.category_id = categories.category_id WHERE category_name = ?;")
if err != nil {
return nil, err
}
for rows.Next() {
article := Article{}
- if err := rows.Scan(&article.Id, &article.Title, &article.Content, &article.Picture, &article.Category); err != nil {
+ if err := rows.Scan(&article.Id, &article.Title, &article.Content, &article.Picture); err != nil {
return nil, err
}
articles = append(articles, article)
diff --git a/web/templates/index.html b/web/templates/index.html
index 10abebc..716dbc7 100644
--- a/web/templates/index.html
+++ b/web/templates/index.html
{{ define "index.html" }}
-<html>
- <head>
- <link rel="stylesheet" href="/static/styles.css">
- </head>
- {{range .Articles}}
+<html lang="fi">
+<head>
+ <meta charset="UTF-8">
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
+ <title>Uutissivusto</title>
+ <link rel="stylesheet" href="/static/styles.css">
+</head>
+<body>
+ <header>
+ <nav style="display: flex; gap: 15px;">
+ <a href="/">
+ Uutiset
+ </a>
+ {{ range .Categories}}
+ <a href="{{ .Name }}">{{ .Name }}</a>
+ {{ end }}
+ <a href="/">
+ Sanajuuri
+ </a>
+ </nav>
+ <nav id="theme-nav">
+ <button id="theme-button" class="theme-button">
+ </button>
+ </nav>
+ </header>
+ {{range .Articles}}
{{ .}}<br />
{{end}}
- {{range .Categories}}
- {{ .Name }}<br />
- {{end}}
+</body>
</html>
{{ end }}
\ No newline at end of file