Skip to content
This repository was archived by the owner on Apr 25, 2025. It is now read-only.

Commit 9f4a98c

Browse files
committed
fix: insert query
1 parent 5564e90 commit 9f4a98c

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

cmd/web/handlers.go

+8-8
Original file line numberDiff line numberDiff line change
@@ -83,18 +83,18 @@ func (app *application) snippetCreate(w http.ResponseWriter, r *http.Request) {
8383
return
8484
}
8585

86-
w.Header().Set("Content-Type", "application/json")
87-
88-
title := "snail"
89-
content := "snail\nClimb Mount Fuji,\nBut slowly, slowly!\n\n– Kobayashi Issa"
90-
expires := 7
91-
92-
id, err := app.snippets.Insert(title, content, strconv.Itoa(expires))
86+
// Create some variables holding dummy data. We'll remove these later on
87+
// during the build.
88+
title := "O snail"
89+
content := "O snail\nClimb Mount Fuji,\nBut slowly, slowly!\n\n– Kobayashi Issa"
90+
expires := "7"
91+
// Pass the data to the SnippetModel.Insert() method, receiving the
92+
// ID of the new record back.
93+
id, err := app.snippets.Insert(title, content, expires)
9394
if err != nil {
9495
app.serverError(w, r, err)
9596
return
9697
}
97-
9898
// Redirect the user to the relevant page for the snippet.
9999
http.Redirect(w, r, fmt.Sprintf("/snippet/view?id=%d", id), http.StatusSeeOther)
100100
}

internal/models/snippets.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ type SnippetModel struct {
2525
func (m *SnippetModel) Insert(title, content, expires string) (int, error) {
2626

2727
stmt := `INSERT INTO snippets (title, content, created, expires)
28-
VALUES(?, ?, UTC_TIMESTAMP(), DATE_ADD(UTC_TIMESTAMP(), INTERVAL ? DAY))`
28+
VALUES(?, ?, UTC_TIMESTAMP(), DATE_ADD(UTC_TIMESTAMP(), INTERVAL ? DAY))`
2929

3030
result, err := m.DB.Exec(stmt, title, content, expires)
3131
if err != nil {

0 commit comments

Comments
 (0)