meetandeat/controller/api/person.go

34 lines
521 B
Go
Raw Normal View History

2019-03-22 16:35:16 +01:00
package api
import (
"net/http"
"github.com/gin-gonic/gin"
"dev.sum7.eu/genofire/golang-lib/database"
"dev.sum7.eu/genofire/meetandeat/models"
)
func getPersonAll(c *gin.Context) {
list := []*models.Person{}
database.Read.Find(&list)
c.JSON(http.StatusOK, list)
}
func addPerson(c *gin.Context) {
var name string
if err := c.BindJSON(&name); err != nil {
c.JSON(http.StatusBadRequest, err.Error())
return
}
d := &models.Person{
Name: name,
}
database.Write.Save(d)
c.JSON(http.StatusOK, d)
}