2023-02-05 04:48:53 +04:00
|
|
|
package mindflow
|
|
|
|
|
|
|
|
import (
|
2023-05-10 03:18:39 +04:00
|
|
|
"errors"
|
|
|
|
"fmt"
|
|
|
|
"strings"
|
2023-02-05 04:48:53 +04:00
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Post struct {
|
2023-05-10 03:18:39 +04:00
|
|
|
ID int64
|
|
|
|
Category Category
|
2023-02-05 04:48:53 +04:00
|
|
|
Date time.Time
|
|
|
|
Title string
|
|
|
|
Body string
|
|
|
|
}
|
2023-05-10 03:18:39 +04:00
|
|
|
|
|
|
|
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"))
|
|
|
|
}
|