2021-09-13 22:39:09 +01:00
|
|
|
package model
|
|
|
|
|
2021-09-25 16:23:56 +01:00
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
)
|
|
|
|
|
2021-09-13 22:39:09 +01:00
|
|
|
type Post struct {
|
|
|
|
ID int `json:"id"`
|
|
|
|
UserID int `json:"user_id"`
|
|
|
|
GameID int `json:"game_id"`
|
|
|
|
CreatedAt int `json:"createdat"`
|
|
|
|
Body string `json:"body"`
|
|
|
|
}
|
2021-09-25 16:23:56 +01:00
|
|
|
|
|
|
|
func (p *Post) IsValid() error {
|
|
|
|
if p.UserID == 0 {
|
|
|
|
return fmt.Errorf("user id must not be empty")
|
|
|
|
}
|
|
|
|
|
|
|
|
if p.GameID == 0 {
|
|
|
|
return fmt.Errorf("game id must not be empty")
|
|
|
|
}
|
|
|
|
|
|
|
|
if p.CreatedAt == 0 {
|
|
|
|
return fmt.Errorf("created at must not be empty")
|
|
|
|
}
|
|
|
|
|
|
|
|
if p.Body == "" {
|
|
|
|
return fmt.Errorf("body must not be empty")
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|