Refactoring validation to belong to model

This commit is contained in:
2026-03-19 00:44:37 +00:00
parent a33cedf09e
commit de6c9d6ae5
6 changed files with 224 additions and 57 deletions

View File

@@ -19,3 +19,22 @@ type Note struct {
// 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
}