1
0

Place Category and Post types into one mindflow.go.

This commit is contained in:
Alexander Andreev 2023-05-22 22:35:47 +04:00
parent ecf9da5b3d
commit 0fbc121e38
Signed by: Arav
GPG Key ID: D22A817D95815393
3 changed files with 35 additions and 37 deletions

View File

@ -1,6 +0,0 @@
package mindflow
type Category struct {
ID int64
Name string
}

View File

@ -1,5 +1,40 @@
package mindflow package mindflow
import (
"errors"
"fmt"
"strings"
"time"
)
type Category struct {
ID int64
Name string
}
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"))
}
type Mindflow interface { type Mindflow interface {
New(post *Post) error New(post *Post) error
Edit(post *Post) error Edit(post *Post) error

View File

@ -1,31 +0,0 @@
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"))
}