1
0

Dates are now of type time.Time.

This commit is contained in:
Alexander Andreev 2023-02-05 16:28:55 +04:00
parent 729e58fdca
commit 309044f651
Signed by: Arav
GPG Key ID: 0388CC8FAA51063F
3 changed files with 19 additions and 13 deletions

View File

@ -4,6 +4,7 @@ import (
"database/sql" "database/sql"
_ "embed" _ "embed"
"fmt" "fmt"
"time"
"git.arav.top/Arav/justguestbook/guestbook" "git.arav.top/Arav/justguestbook/guestbook"
_ "github.com/mattn/go-sqlite3" _ "github.com/mattn/go-sqlite3"
@ -137,9 +138,14 @@ func (d *SQLiteDatabase) Entries(page, pageSize int64) (entries []*guestbook.Ent
} }
if reply_message.Valid /* reply_created is also valid if reply is */ { if reply_message.Valid /* reply_created is also valid if reply is */ {
date, err := time.Parse(guestbook.DateFormat, reply_created.String)
if err != nil {
return nil, err
}
entry.Reply = &guestbook.Reply{ entry.Reply = &guestbook.Reply{
ID: entry.ID, ID: entry.ID,
Created: reply_created.String, Created: date,
Message: reply_message.String} Message: reply_message.String}
} }

View File

@ -6,13 +6,13 @@ import (
) )
type Entry struct { type Entry struct {
ID int64 `json:"entry_id"` ID int64 `json:"entry_id"`
Created string `json:"created"` Created time.Time `json:"created"`
Name string `json:"name"` Name string `json:"name"`
Website string `json:"website,omitempty"` Website string `json:"website,omitempty"`
Message string `json:"message"` Message string `json:"message"`
HideWebsite bool `json:"hide_website,omitempty"` HideWebsite bool `json:"hide_website,omitempty"`
Reply *Reply `json:"reply,omitempty"` Reply *Reply `json:"reply,omitempty"`
} }
func NewEntry(name, message, website string, hideWebsite bool) (*Entry, error) { func NewEntry(name, message, website string, hideWebsite bool) (*Entry, error) {
@ -21,7 +21,7 @@ func NewEntry(name, message, website string, hideWebsite bool) (*Entry, error) {
} }
return &Entry{ return &Entry{
Created: time.Now().UTC().Format(DateFormat), Created: time.Now().UTC(),
Name: name, Name: name,
Website: website, Website: website,
HideWebsite: hideWebsite, HideWebsite: hideWebsite,

View File

@ -6,9 +6,9 @@ import (
) )
type Reply struct { type Reply struct {
ID int64 `json:"-"` ID int64 `json:"-"`
Created string `json:"created,omitempty"` Created time.Time `json:"created,omitempty"`
Message string `json:"message"` Message string `json:"message"`
} }
func NewReply(entryID int64, message string) (*Reply, error) { func NewReply(entryID int64, message string) (*Reply, error) {
@ -18,6 +18,6 @@ func NewReply(entryID int64, message string) (*Reply, error) {
return &Reply{ return &Reply{
ID: entryID, ID: entryID,
Created: time.Now().UTC().Format(DateFormat), Created: time.Now().UTC(),
Message: message}, nil Message: message}, nil
} }