Rename stuff to time_ and modified instead of updated
This commit is contained in:
parent
63c8a24f38
commit
bdba843541
1 changed files with 15 additions and 15 deletions
|
@ -24,9 +24,9 @@ type BlogPost struct {
|
||||||
Slug string `json:"slug",db:"slug"`
|
Slug string `json:"slug",db:"slug"`
|
||||||
Author string `json:"author",db:"author"`
|
Author string `json:"author",db:"author"`
|
||||||
Content string `json:"content",db:"content"`
|
Content string `json:"content",db:"content"`
|
||||||
DatePublished time.Time `json:"date", db:"date"`
|
TimePublished time.Time `json:"time_published", db:"time_published"`
|
||||||
Updated bool `json:"updated", db:"updated"`
|
Modified bool `json:"modified", db:"modified"`
|
||||||
UpdateTime time.Time `json:"update_time", db:"update_time"`
|
TimeModified time.Time `json:"time_modified", db:"time_modified"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Tag struct {
|
type Tag struct {
|
||||||
|
@ -57,9 +57,9 @@ func Init() {
|
||||||
slug text,
|
slug text,
|
||||||
author text REFERENCES users (username),
|
author text REFERENCES users (username),
|
||||||
content text,
|
content text,
|
||||||
date timestamp,
|
time_published timestamp,
|
||||||
updated bool,
|
modified bool,
|
||||||
update_time timestamp)`
|
time_modified timestamp)`
|
||||||
DB.Exec(createPostsTable)
|
DB.Exec(createPostsTable)
|
||||||
|
|
||||||
createTagsTable := `
|
createTagsTable := `
|
||||||
|
@ -129,7 +129,7 @@ func createBlogPost(w http.ResponseWriter, r *http.Request) {
|
||||||
return
|
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)
|
VALUES ($1, $2, $3, $4, $5, $6, $7)
|
||||||
RETURNING id`
|
RETURNING id`
|
||||||
article_id := 0
|
article_id := 0
|
||||||
|
@ -167,9 +167,9 @@ func updateBlogPostById(w http.ResponseWriter, r *http.Request) {
|
||||||
returnError := ReturnError{}
|
returnError := ReturnError{}
|
||||||
// Get the actual post
|
// Get the actual post
|
||||||
id := chi.URLParam(r, "id")
|
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{}
|
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 != nil {
|
||||||
if err == sql.ErrNoRows {
|
if err == sql.ErrNoRows {
|
||||||
returnError.Message = "blog post requested for update not found"
|
returnError.Message = "blog post requested for update not found"
|
||||||
|
@ -196,8 +196,8 @@ func updateBlogPostById(w http.ResponseWriter, r *http.Request) {
|
||||||
UPDATE posts SET
|
UPDATE posts SET
|
||||||
title = $1,
|
title = $1,
|
||||||
content = $2,
|
content = $2,
|
||||||
updated = $3,
|
modified = $3,
|
||||||
update_time = $4
|
time_modified = $4
|
||||||
WHERE id = $5`
|
WHERE id = $5`
|
||||||
// write the row update
|
// write the row update
|
||||||
_, err = DB.Exec(s, post.Title, post.Content, true, time.Now().UTC(), post.ID)
|
_, 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) {
|
func getBlogPostBySlug(w http.ResponseWriter, r *http.Request) {
|
||||||
returnError := ReturnError{}
|
returnError := ReturnError{}
|
||||||
slug := chi.URLParam(r, "slug")
|
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{}
|
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 {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
returnError.Message = "post not found"
|
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) {
|
func getBlogPostById(w http.ResponseWriter, r *http.Request) {
|
||||||
returnError := ReturnError{}
|
returnError := ReturnError{}
|
||||||
id := chi.URLParam(r, "id")
|
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{}
|
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 {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
returnError.Message = "post not found"
|
returnError.Message = "post not found"
|
||||||
|
|
Reference in a new issue