Add create post endpoint and check target to the makefile

This commit is contained in:
Miguel de la Cruz 2021-09-25 17:23:56 +02:00
parent 08ab312f92
commit 3067beb96c
12 changed files with 280 additions and 5 deletions

View file

@ -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
}