package public import ( "net/http" "github.com/gin-gonic/gin" "yyjishu.com/rubbish-class/community" ) //CommunityListHandler 社区列表 func CommunityListHandler(c *gin.Context) { service := community.NewService() data, err := service.Map() if err != nil { c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{ "err": err.Error(), }) return } c.JSON(http.StatusOK, data) } //CommunityCreateHandler 社区创建 func CommunityCreateHandler(c *gin.Context) { var model community.CommunityModel if err := c.ShouldBindJSON(&model); err != nil { c.AbortWithStatusJSON(http.StatusBadRequest, nil) return } service := community.NewService() err := service.Create(&model) if err != nil { c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{ "err": err.Error(), }) return } c.JSON(http.StatusOK, &model) }