add delete
This commit is contained in:
@@ -11,13 +11,13 @@ import (
|
||||
|
||||
// GetDadJoke godoc
|
||||
//
|
||||
// @Summary Generate dadjoke
|
||||
// @Summary Generate dadjokelocaloca
|
||||
// @Description get a dad joke
|
||||
// @Tags DadJoke
|
||||
// @Accept json
|
||||
// @Produce application/json
|
||||
// @Success 200 {object} model.Message "response"
|
||||
// @failure 400 {object} model.Message "error"
|
||||
// @failure 500 {object} model.Message "error"
|
||||
// @Router /jokes/dadjoke [get]
|
||||
func (c *Controller) GetDadJoke(ctx *gin.Context) {
|
||||
joke, err := service.GetRandomDadJoke(c.Db.DB)
|
||||
@@ -36,23 +36,46 @@ func (c *Controller) GetDadJoke(ctx *gin.Context) {
|
||||
// @Tags DadJoke
|
||||
// @Accept json
|
||||
// @Produce application/json
|
||||
// @Param joke query string true "Dad Joke you wish to enter into database"
|
||||
// @Success 200 {object} model.Message "response"
|
||||
// @failure 400 {object} model.Message "error"
|
||||
// @failure 500 {object} model.Message "error"
|
||||
// @Router /jokes/dadjoke [post]
|
||||
func (c *Controller) PostDadJoke(ctx *gin.Context) {
|
||||
var req model.DadJoke
|
||||
|
||||
if err := ctx.ShouldBindJSON(&req); err != nil {
|
||||
ctx.JSON(http.StatusInternalServerError, gin.H{"message": err})
|
||||
return
|
||||
}
|
||||
entry := model.DadJoke{
|
||||
JOKE: req.JOKE,
|
||||
req.JOKE = ctx.Query("joke")
|
||||
}
|
||||
|
||||
err := c.Db.DB.Create(&entry).Error
|
||||
err := service.PostDadJoke(c.Db.DB, req)
|
||||
if err != nil {
|
||||
ctx.JSON(http.StatusInternalServerError, gin.H{"message": err})
|
||||
ctx.JSON(http.StatusInternalServerError, gin.H{"message": err.Error()})
|
||||
return
|
||||
}
|
||||
ctx.JSON(http.StatusOK, gin.H{"message": "OK"})
|
||||
}
|
||||
|
||||
// DeleteDadJoke godoc
|
||||
//
|
||||
// @Summary Generate dadjoke
|
||||
// @Description create a dad joke
|
||||
// @Tags DadJoke
|
||||
// @Accept json
|
||||
// @Produce application/json
|
||||
// @Param joke query string true "Dad joke you wish to delete from the database"
|
||||
// @Success 200 {object} model.Message "response"
|
||||
// @failure 500 {object} model.Message "error"
|
||||
// @Router /jokes/dadjoke [delete]
|
||||
func (c *Controller) DeleteDadJoke(ctx *gin.Context) {
|
||||
var req model.DadJoke
|
||||
|
||||
if err := ctx.ShouldBindJSON(&req); err != nil {
|
||||
req.JOKE = ctx.Query("joke")
|
||||
}
|
||||
|
||||
err := service.DeleteDadJoke(c.Db.DB, req)
|
||||
if err != nil {
|
||||
ctx.JSON(http.StatusInternalServerError, gin.H{"message": err.Error()})
|
||||
return
|
||||
}
|
||||
ctx.JSON(http.StatusOK, gin.H{"message": "OK"})
|
||||
|
||||
Reference in New Issue
Block a user