func (nr *NewsResource) PutNews(c *gin.Context) { id, err := nr.getId(c) if err != nil { c.JSON(400, api.NewError("problem decoding id sent")) } var news api.News if err := c.Bind(&news); err != nil { c.JSON(400, api.NewError("problem decoding body")) return } news.Id = int32(id) news.CalculateRisk() var existing api.News if nr.db.First(&existing, id).RecordNotFound() { c.JSON(404, api.NewError("not found")) } else { nr.db.Save(&news) c.JSON(200, news) } }
func (nr *NewsResource) CreateNews(c *gin.Context) { var news api.News if err := c.Bind(&news); err != nil { c.JSON(400, api.NewError("problem decoding body")) return } news.CalculateRisk() nr.db.Save(&news) c.JSON(201, news) }