Rename stuff to time_ and modified instead of updated

This commit is contained in:
Amarpreet Minhas 2019-04-22 16:24:58 -04:00
parent 63c8a24f38
commit bdba843541

View file

@ -24,9 +24,9 @@ type BlogPost struct {
Slug string `json:"slug",db:"slug"`
Author string `json:"author",db:"author"`
Content string `json:"content",db:"content"`
DatePublished time.Time `json:"date", db:"date"`
Updated bool `json:"updated", db:"updated"`
UpdateTime time.Time `json:"update_time", db:"update_time"`
TimePublished time.Time `json:"time_published", db:"time_published"`
Modified bool `json:"modified", db:"modified"`
TimeModified time.Time `json:"time_modified", db:"time_modified"`
}
type Tag struct {
@ -57,9 +57,9 @@ func Init() {
slug text,
author text REFERENCES users (username),
content text,
date timestamp,
updated bool,
update_time timestamp)`
time_published timestamp,
modified bool,
time_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, date, updated, update_time)
s := `INSERT INTO posts (title, slug, author, content, time_published, modified, time_modified)
VALUES ($1, $2, $3, $4, $5, $6, $7)
RETURNING id`
article_id := 0
@ -167,9 +167,9 @@ func updateBlogPostById(w http.ResponseWriter, r *http.Request) {
returnError := ReturnError{}
// Get the actual post
id := chi.URLParam(r, "id")
result := DB.QueryRow("SELECT id, title, slug, author, content, date FROM posts WHERE id=$1", id)
result := DB.QueryRow("SELECT id, title, slug, author, content, time_published FROM posts WHERE id=$1", id)
post := BlogPost{}
err := result.Scan(&post.ID, &post.Title, &post.Slug, &post.Author, &post.Content, &post.DatePublished)
err := result.Scan(&post.ID, &post.Title, &post.Slug, &post.Author, &post.Content, &post.TimePublished)
if err != nil {
if err == sql.ErrNoRows {
returnError.Message = "blog post requested for update not found"
@ -196,8 +196,8 @@ func updateBlogPostById(w http.ResponseWriter, r *http.Request) {
UPDATE posts SET
title = $1,
content = $2,
updated = $3,
update_time = $4
modified = $3,
time_modified = $4
WHERE id = $5`
// write the row update
_, err = DB.Exec(s, post.Title, post.Content, true, time.Now().UTC(), post.ID)
@ -220,9 +220,9 @@ 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, date, updated, update_time FROM posts WHERE slug=$1", slug)
result := DB.QueryRow("SELECT id, title, slug, author, content, time_published, modified, time_modified FROM posts WHERE slug=$1", slug)
post := BlogPost{}
err := result.Scan(&post.ID, &post.Title, &post.Slug, &post.Author, &post.Content, &post.DatePublished, &post.Updated, &post.UpdateTime)
err := result.Scan(&post.ID, &post.Title, &post.Slug, &post.Author, &post.Content, &post.TimePublished, &post.Modified, &post.TimeModified)
if err != nil {
fmt.Println(err)
returnError.Message = "post not found"
@ -238,9 +238,9 @@ 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, date, updated, update_time FROM posts WHERE id=$1", id)
result := DB.QueryRow("SELECT id, title, slug, author, content, time_published, modified, time_modified FROM posts WHERE id=$1", id)
post := BlogPost{}
err := result.Scan(&post.ID, &post.Title, &post.Slug, &post.Author, &post.Content, &post.DatePublished, &post.Updated, &post.UpdateTime)
err := result.Scan(&post.ID, &post.Title, &post.Slug, &post.Author, &post.Content, &post.TimePublished, &post.Modified, &post.TimeModified)
if err != nil {
fmt.Println(err)
returnError.Message = "post not found"