Rename time_modified to last_modified

This commit is contained in:
Amarpreet Minhas 2019-04-22 16:28:36 -04:00
parent bdba843541
commit 0fd73db5ae

View file

@ -26,7 +26,7 @@ type BlogPost struct {
Content string `json:"content",db:"content"`
TimePublished time.Time `json:"time_published", db:"time_published"`
Modified bool `json:"modified", db:"modified"`
TimeModified time.Time `json:"time_modified", db:"time_modified"`
TimeModified time.Time `json:"last_modified", db:"last_modified"`
}
type Tag struct {
@ -59,7 +59,7 @@ func Init() {
content text,
time_published timestamp,
modified bool,
time_modified timestamp)`
last_modified timestamp)`
DB.Exec(createPostsTable)
createTagsTable := `
@ -129,7 +129,7 @@ func createBlogPost(w http.ResponseWriter, r *http.Request) {
return
}
}
s := `INSERT INTO posts (title, slug, author, content, time_published, modified, time_modified)
s := `INSERT INTO posts (title, slug, author, content, time_published, modified, last_modified)
VALUES ($1, $2, $3, $4, $5, $6, $7)
RETURNING id`
article_id := 0
@ -197,7 +197,7 @@ func updateBlogPostById(w http.ResponseWriter, r *http.Request) {
title = $1,
content = $2,
modified = $3,
time_modified = $4
last_modified = $4
WHERE id = $5`
// write the row update
_, err = DB.Exec(s, post.Title, post.Content, true, time.Now().UTC(), post.ID)
@ -220,7 +220,7 @@ func getBlogPosts(w http.ResponseWriter, r *http.Request) {
func getBlogPostBySlug(w http.ResponseWriter, r *http.Request) {
returnError := ReturnError{}
slug := chi.URLParam(r, "slug")
result := DB.QueryRow("SELECT id, title, slug, author, content, time_published, modified, time_modified FROM posts WHERE slug=$1", slug)
result := DB.QueryRow("SELECT id, title, slug, author, content, time_published, modified, last_modified FROM posts WHERE slug=$1", slug)
post := BlogPost{}
err := result.Scan(&post.ID, &post.Title, &post.Slug, &post.Author, &post.Content, &post.TimePublished, &post.Modified, &post.TimeModified)
if err != nil {
@ -238,7 +238,7 @@ func getBlogPostBySlug(w http.ResponseWriter, r *http.Request) {
func getBlogPostById(w http.ResponseWriter, r *http.Request) {
returnError := ReturnError{}
id := chi.URLParam(r, "id")
result := DB.QueryRow("SELECT id, title, slug, author, content, time_published, modified, time_modified FROM posts WHERE id=$1", id)
result := DB.QueryRow("SELECT id, title, slug, author, content, time_published, modified, last_modified FROM posts WHERE id=$1", id)
post := BlogPost{}
err := result.Scan(&post.ID, &post.Title, &post.Slug, &post.Author, &post.Content, &post.TimePublished, &post.Modified, &post.TimeModified)
if err != nil {