Implement parsing and persisting notes
This commit is contained in:
@@ -2,6 +2,7 @@ package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"time"
|
||||
)
|
||||
|
||||
@@ -30,10 +31,15 @@ func (ns *NoteService) Query(query NoteServiceQuery) ([]Note, error) {
|
||||
|
||||
for rows.Next() {
|
||||
note := Note{}
|
||||
err := rows.Scan(¬e.ID, ¬e.Content, ¬e.Timestamp, ¬e.Player.ID)
|
||||
var ts string
|
||||
err := rows.Scan(¬e.ID, ¬e.Content, &ts, ¬e.Player.ID)
|
||||
if err != nil {
|
||||
return res, fmt.Errorf("failed scanning note: %v", err)
|
||||
}
|
||||
note.Timestamp, err = time.Parse(time.RFC3339, ts)
|
||||
if err != nil {
|
||||
return res, fmt.Errorf("failed parsing timestamp: %v", err)
|
||||
}
|
||||
res = append(res, note)
|
||||
}
|
||||
|
||||
@@ -41,8 +47,9 @@ func (ns *NoteService) Query(query NoteServiceQuery) ([]Note, error) {
|
||||
}
|
||||
|
||||
func (ns *NoteService) Create(content string, timestamp time.Time, player Player) (Note, error) {
|
||||
log.Printf("Creating note %q with timestamp %s and player %d", content, timestamp, player.ID)
|
||||
note := Note{}
|
||||
res, err := ns.db.writeConn.Exec("insert into note (content, timestamp, player) values (?, ?, ?)", content, timestamp, player.ID)
|
||||
res, err := ns.db.writeConn.Exec("insert into note (content, timestamp, player) values (?, ?, ?)", content, timestamp.Format(time.RFC3339), player.ID)
|
||||
if err != nil {
|
||||
return note, fmt.Errorf("failed to insert note: %v", err)
|
||||
}
|
||||
@@ -51,6 +58,7 @@ func (ns *NoteService) Create(content string, timestamp time.Time, player Player
|
||||
if err != nil {
|
||||
return note, fmt.Errorf("failed to get last insert id: %v", err)
|
||||
}
|
||||
log.Printf("Created note %q with timestamp %s and player %d with id %d", content, timestamp, player.ID, id)
|
||||
|
||||
qres, err := ns.Query(NoteServiceQuery{ID: &id})
|
||||
if err != nil {
|
||||
|
Reference in New Issue
Block a user