rubbishclass-srv/public/public-handler.go

52 lines
1.0 KiB
Go

package public
import (
"net/http"
"github.com/gin-gonic/gin"
"yyjishu.com/rubbish-class/community"
)
//CommunityListHandler 社区列表
func CommunityListHandler(c *gin.Context) {
// swagger:route GET /community/list commid
//
// 社区列表
//
// Responses:
// 200: map<string,int>
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) {
// swagger:route POST /community/create community
//
// 社区创建
//
// Responses:
// 200: Community
var model community.Community
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)
}