Skip to content

Commit

Permalink
update controller stub
Browse files Browse the repository at this point in the history
  • Loading branch information
Shipu committed Mar 2, 2022
1 parent d7a3f62 commit 6ee0ec6
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions cmd/generate/stubs/controller.stub
Original file line number Diff line number Diff line change
Expand Up @@ -23,34 +23,34 @@ func {{TitleName}}Create() gin.HandlerFunc {

defer func() {
if err := recover(); err != nil {
artifact.Res.Status(http.StatusUnprocessableEntity).Message("error").Data(err).Json(c)
artifact.Res.Code(http.StatusUnprocessableEntity).Message("error").Data(err).Json(c)
}
}()

if err := c.ShouldBind(&{{SingularLowerName}}); err != nil {
artifact.Res.Status(http.StatusBadRequest).Message("Bad Request").Data(err.Error()).AbortWithStatusJSON(c)
artifact.Res.Code(http.StatusBadRequest).Message("Bad Request").Data(err.Error()).AbortWithStatusJSON(c)
return
}

{{SingularLowerName}} = services.CreateA{{TitleName}}({{SingularLowerName}})

artifact.Res.Status(http.StatusCreated).Message("success").Data({{SingularLowerName}}).Json(c)
artifact.Res.Code(http.StatusCreated).Message("success").Data({{SingularLowerName}}).Json(c)
}
}

func {{TitleName}}Show() gin.HandlerFunc {
return func(c *gin.Context) {
defer func() {
if err := recover(); err != nil {
artifact.Res.Status(http.StatusNotFound).Message(http.StatusText(http.StatusNotFound)).Json(c)
artifact.Res.Code(http.StatusNotFound).Message(http.StatusText(http.StatusNotFound)).Json(c)
}
}()

{{SingularLowerName}}Id := c.Param("{{SingularLowerName}}Id")

{{SingularLowerName}} := services.A{{TitleName}}({{SingularLowerName}}Id)

artifact.Res.Status(http.StatusOK).Message("success").Data({{SingularLowerName}}).Json(c)
artifact.Res.Code(http.StatusOK).Message("success").Data({{SingularLowerName}}).Json(c)
}
}

Expand All @@ -60,44 +60,44 @@ func {{TitleName}}Update() gin.HandlerFunc {

defer func() {
if err := recover(); err != nil {
artifact.Res.Status(http.StatusUnprocessableEntity).Message(http.StatusText(http.StatusUnprocessableEntity)).Data(err).Json(c)
artifact.Res.Code(http.StatusUnprocessableEntity).Message(http.StatusText(http.StatusUnprocessableEntity)).Data(err).Json(c)
}
}()

{{SingularLowerName}}Id := c.Param("{{SingularLowerName}}Id")

if err := c.ShouldBind(&update{{TitleName}}); err != nil {
artifact.Res.Status(http.StatusBadRequest).Message(http.StatusText(http.StatusBadRequest)).Data(err.Error()).AbortWithStatusJSON(c)
artifact.Res.Code(http.StatusBadRequest).Message(http.StatusText(http.StatusBadRequest)).Data(err.Error()).AbortWithStatusJSON(c)
return
}

{{SingularLowerName}}, err := services.UpdateA{{TitleName}}({{SingularLowerName}}Id, update{{TitleName}})

if err != nil {
artifact.Res.Status(http.StatusInternalServerError).Message(http.StatusText(http.StatusInternalServerError)).Json(c)
artifact.Res.Code(http.StatusInternalServerError).Message(http.StatusText(http.StatusInternalServerError)).Json(c)
return
}

artifact.Res.Status(http.StatusOK).Message("Successfully Updated !!!").Data({{SingularLowerName}}).Json(c)
artifact.Res.Code(http.StatusOK).Message("Successfully Updated !!!").Data({{SingularLowerName}}).Json(c)
}
}

func {{TitleName}}Delete() gin.HandlerFunc {
return func(c *gin.Context) {
defer func() {
if err := recover(); err != nil {
artifact.Res.Status(http.StatusUnprocessableEntity).Message("error").Data(err).Json(c)
artifact.Res.Code(http.StatusUnprocessableEntity).Message("error").Data(err).Json(c)
}
}()

{{SingularLowerName}}Id := c.Param("{{SingularLowerName}}Id")
{{SingularLowerName}}, err := services.DeleteA{{TitleName}}({{SingularLowerName}}Id)

if !err {
artifact.Res.Status(http.StatusInternalServerError).Message("something wrong").Json(c)
artifact.Res.Code(http.StatusInternalServerError).Message("something wrong").Json(c)
return
}

artifact.Res.Status(http.StatusOK).Message("Successfully Delete !!!").Data({{SingularLowerName}}).Json(c)
artifact.Res.Code(http.StatusOK).Message("Successfully Delete !!!").Data({{SingularLowerName}}).Json(c)
}
}

0 comments on commit 6ee0ec6

Please sign in to comment.