diff --git a/db.go b/db.go index 5ecf9a2..c7fa86d 100644 --- a/db.go +++ b/db.go @@ -20,12 +20,12 @@ func initializeDatabase() { } func writeToDB(post BlogPost) { - stmt, _ := db.Prepare("INSERT INTO blogposts(author, title, content, time) VALUES (?, ?, ?, ?)") - stmt.Exec(post.Author, post.Title, post.Content, time.Now().Unix()) + stmt, _ := db.Prepare("INSERT INTO blogposts(author, content, time) VALUES (?, ?, ?)") + stmt.Exec(post.Author, post.Content, time.Now().Unix()) } func readBlogpostsFromDB() []BlogPost { - res, err := db.Query("SELECT content, author, title, time from blogposts") + res, err := db.Query("SELECT content, title, time from blogposts limit 50") if err != nil { log.Println("Error reading blogposts") return make([]BlogPost, 0) @@ -38,10 +38,10 @@ func resultToBlogposts(res *sql.Rows) []BlogPost { defer res.Close() entries := make([]BlogPost, 0) for res.Next() { - var content, author, title string + var content, author string var timeInt int64 - res.Scan(&content, &author, &title, &timeInt) - post := BlogPost{Content:content, Author:author, Title:title, FTime:time.Unix(timeInt, 0).Format("02.01.2006 - 15:04:05")} + res.Scan(&content, &author, &timeInt) + post := BlogPost{Content:content, Author:author, FTime:time.Unix(timeInt, 0).Format("02.01.2006 - 15:04:05")} entries = append(entries, post) } return entries diff --git a/main.go b/main.go index 9963689..74c524d 100644 --- a/main.go +++ b/main.go @@ -16,7 +16,6 @@ func main() { type BlogPost struct { Id int64 `"id"` Content string `"content"` - Title string `"title"` Author string `"author"` Secret string `"secret"` Time time.Time `"time"` diff --git a/schema b/schema index 06b0e87..9b95255 100644 --- a/schema +++ b/schema @@ -1 +1 @@ -CREATE TABLE `blogposts` ( `id` INTEGER PRIMARY KEY AUTOINCREMENT, `author` VARCHAR(32) NULL, `title` text NULL, `content` text null, `time` time null); +CREATE TABLE `blogposts` ( `id` INTEGER PRIMARY KEY AUTOINCREMENT, `author` VARCHAR(32) NULL, `content` text null, `time` time null); diff --git a/test.sh b/test.sh index ca122d8..329518b 100755 --- a/test.sh +++ b/test.sh @@ -5,5 +5,5 @@ else msg="$1" fi -curl localhost:12345/add -d "{\"content\": \"$msg\", \"Title\": \"title\", \"Secret\": \"asdf\", \"author\": \"kageru\"}" -H "Content-Type: application/json" -v +curl localhost:12345/add -d "{\"content\": \"$msg\", \"Secret\": \"asdf\", \"author\": \"kageru\"}" -H "Content-Type: application/json" -v