justguestbook

package module
v1.3.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 21, 2023 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DateFormat is a format of the date and time used in a guestbook.
	DateFormat = "2006-01-02 15:04:05"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Entry

type Entry struct {
	// ID of an entry.
	ID int64 `json:"entry_id"`

	// Created holds the date and time when an entry was created.
	Created time.Time `json:"created"`

	// Name holds a nick-/name of a guest who posted an entry.
	Name string `json:"name"`

	// Website of a guest. Can be empty.
	Website string `json:"website,omitempty"`

	// HideWebsite tells wether to hide or show guest's website.
	HideWebsite bool `json:"hide_website,omitempty"`

	// Message that a guest wrote.
	Message string `json:"message"`

	// Reply holds a reply for this entry.
	Reply *Reply `json:"reply,omitempty"`
}

Entry holds a guestbook entry.

func NewEntry

func NewEntry(name, message, website string, hideWebsite bool) (*Entry, error)

NewEntry creates a new Entry and, before that, verifies if the name and message aren't empty and the website field do not exceed the limit.

type Guestbook

type Guestbook interface {
	// Entries returns a slice of guestbook entries.
	Entries(page, pageSize int64) ([]*Entry, error)
	// Count returns how much entries are in a DB.
	Count() (int64, error)
	// NewEntry inserts a given Entry into a DB.
	NewEntry(entry *Entry) error
	// EditEntry modifies the fields of an existing entry.
	EditEntry(entry *Entry) error
	// DeleteEntry removes an Entry with a given ID.
	DeleteEntry(entryID int64) error
	// NewReply inserts a given Reply into a DB.
	NewReply(reply *Reply) error
	// EditReply modifies a message field of a given Reply.
	EditReply(reply *Reply) error
	// DeleteReply removes a Reply with a given ID of an Entry.
	DeleteReply(entryID int64) error
	// Close closes a DB.
	Close() error
}

Guestbook is an interface that should be implemented by a DB.

func NewSQLiteDB

func NewSQLiteDB(filePath string) (Guestbook, error)

NewSQLiteDB returns an instance of a SQLite Guestbook implementation.

type Reply

type Reply struct {
	// ID of a guestbook's entry is used when update of a reply is performed.
	//
	// Not present in JSON because a reply comes within its corresponding entry.
	ID int64 `json:"-"`

	// Created holds a date and time when a reply was created.
	Created time.Time `json:"created,omitempty"`

	// Message holds a reply's message.
	Message string `json:"message"`
}

Reply holds a reply for a guestbook's entry.

func NewReply

func NewReply(entryID int64, message string) (*Reply, error)

NewReply creates a new reply and, before that, verifies that a passed message is not empty.

type SQLiteDatabase

type SQLiteDatabase struct {
	// contains filtered or unexported fields
}

SQLiteDatabase implements a Guestbook that works with a SQLite DB under the hood.

func (*SQLiteDatabase) Close

func (d *SQLiteDatabase) Close() error

func (*SQLiteDatabase) Count

func (d *SQLiteDatabase) Count() (count int64, err error)

Count returns how much entries are in an `entry` table.

func (*SQLiteDatabase) DeleteEntry

func (d *SQLiteDatabase) DeleteEntry(entryID int64) error

func (*SQLiteDatabase) DeleteReply

func (d *SQLiteDatabase) DeleteReply(entryID int64) error

func (*SQLiteDatabase) EditEntry

func (d *SQLiteDatabase) EditEntry(entry *Entry) error

func (*SQLiteDatabase) EditReply

func (d *SQLiteDatabase) EditReply(reply *Reply) error

func (*SQLiteDatabase) Entries

func (d *SQLiteDatabase) Entries(page, pageSize int64) (entries []*Entry, err error)

func (*SQLiteDatabase) NewEntry

func (d *SQLiteDatabase) NewEntry(entry *Entry) error

NewEntry inserts a passed Entry struct and fills its ID field if successful.

func (*SQLiteDatabase) NewReply

func (d *SQLiteDatabase) NewReply(reply *Reply) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL