Files
gotes/internal/models/note.go

41 lines
888 B
Go

package models
import (
"time"
)
const (
NoteTitleMaxLength = 50
)
// Note represents a single note with its metadata.
type Note struct {
// ID is the unique identifier of the note.
ID int `json:"id"`
// Title is a short title for human identification of a note
Title string `json:"title"`
// LastUpdate is the timestamp of when the note was last modified.
LastUpdate time.Time `json:"last_update"`
// Content is the actual text content of the note.
Content string `json:"content"`
}
func (n *Note) Validate() error {
errs := []error{}
if n.Title == "" {
errs = append(errs, &ErrEmptyNoteTitle{})
}
if n.Content == "" {
errs = append(errs, &ErrEmptyNoteContent{})
}
if len(errs) != 0 {
return &ErrNoteIncomplete{why: errs}
}
if titleLen := len(n.Title); titleLen > NoteTitleMaxLength {
return &ErrNoteTitleOverflow{
length: titleLen,
}
}
return nil
}