32 lines
581 B
Go
32 lines
581 B
Go
package mindflow
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"strings"
|
|
"time"
|
|
)
|
|
|
|
type Post struct {
|
|
ID int64
|
|
Category Category
|
|
Date time.Time
|
|
Title string
|
|
Body string
|
|
}
|
|
|
|
func NewPost(category Category, title, body string) (*Post, error) {
|
|
if title == "" || body == "" {
|
|
return nil, errors.New("empty title or body is not allowed")
|
|
}
|
|
return &Post{
|
|
Category: category,
|
|
Date: time.Now().UTC(),
|
|
Title: title,
|
|
Body: body}, nil
|
|
}
|
|
|
|
func (p *Post) PostID() string {
|
|
return fmt.Sprint(strings.ToLower(p.Category.Name), "-", p.Date.Format("20060102-1504"))
|
|
}
|