Compare commits

..

No commits in common. '9645f103535b9b2fec1e49dc34cd10d8e0e462b4' and '5f375f654a766e6a8a21643eada07f233c2f23a9' have entirely different histories.

@ -1,13 +1,10 @@
package main
import (
"errors"
"fmt"
"html/template"
"net/http"
"strconv"
"gitea.wagshome.duckdns.org/nathan/golearn/internal/models"
)
func (app *application) home(w http.ResponseWriter, r *http.Request) {
@ -37,16 +34,7 @@ func (app *application) snippetView(w http.ResponseWriter, r *http.Request) {
app.notFound(w)
return
}
snippet, err := app.snippets.Get(id)
if err != nil {
if errors.Is(err, models.ErrNoRecord) {
app.notFound(w)
} else {
app.serverError(w, err)
}
return
}
fmt.Fprintf(w, "%+v", snippet)
fmt.Fprintf(w, "Display a specific snippet with ID %d...", id)
}
func (app *application) snippetCreate(w http.ResponseWriter, r *http.Request) {
if r.Method != "POST" {

@ -1,7 +0,0 @@
package models
import (
"errors"
)
var ErrNoRecord = errors.New("models: no matchin record found")

@ -2,7 +2,6 @@ package models
import (
"database/sql"
"errors"
"time"
)
@ -32,19 +31,8 @@ func (m *SnippetModel) Insert(title string, content string, expires int) (int, e
}
func (m *SnippetModel) Get(id int) (*Snippet, error) {
stmt := `SELECT id, title, content, created, expires FROM snippets WHERE expires > UTC_TIMESTAMP() and id = ?`
row := m.DB.QueryRow(stmt, id)
s := &Snippet{}
err := row.Scan(&s.ID, &s.Title, &s.Content, &s.Created, &s.Expires)
if err != nil {
if errors.Is(err, sql.ErrNoRows) {
return nil, ErrNoRecord
} else {
return nil, err
}
}
return s, nil
stmt := `SELECT`
return nil, nil
}
func (m *SnippetModel) Latest() ([]*Snippet, error) {

Loading…
Cancel
Save