Diff between 409c87dd7fa3da2124025ca2292fc53f7f5764d3 and 693fedd58be44ba7e645dace02c82bf5f2a970c9

Changed Files

File Additions Deletions Status
internal/database/queries.go +13 -9 modified
web/templates/index.html +27 -8 modified

Full Patch

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
@@ -7,11 +7,11 @@ import (
 )
 
 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 {
@@ -20,7 +20,7 @@ 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
 	}
@@ -28,9 +28,13 @@ func GetArticles(db *sql.DB) ([]Article, error) {
 
 	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)
 	}
 
@@ -56,7 +60,7 @@ func GetCategories(db *sql.DB) ([]Category, error) {
 }
 
 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
 	}
@@ -70,7 +74,7 @@ func GetCategoryArticles(db *sql.DB, category string) ([]Article, error) {
 
 	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
@@ -1,13 +1,32 @@
 {{ 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