Add create post endpoint and check target to the makefile
This commit is contained in:
parent
08ab312f92
commit
3067beb96c
12 changed files with 280 additions and 5 deletions
|
@ -1,5 +1,9 @@
|
|||
package model
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type Post struct {
|
||||
ID int `json:"id"`
|
||||
UserID int `json:"user_id"`
|
||||
|
@ -7,3 +11,23 @@ type Post struct {
|
|||
CreatedAt int `json:"createdat"`
|
||||
Body string `json:"body"`
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue