rubbishclass-srv/public/public-handler.go

46 lines
961 B
Go
Raw Normal View History

2020-03-24 07:12:31 +00:00
package public
2020-03-30 05:46:11 +00:00
import (
"net/http"
2020-03-24 07:12:31 +00:00
2020-03-30 05:46:11 +00:00
"github.com/gin-gonic/gin"
"yyjishu.com/rubbish-class/community"
)
//CommunityListHandler 社区列表
2020-03-24 07:12:31 +00:00
func CommunityListHandler(c *gin.Context) {
2020-04-12 02:41:11 +00:00
// swagger:route GET /community/list commid
//
// 社区列表
//
// Responses:
// 200: map<string,int>
2020-03-30 05:46:11 +00:00
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)
}
2020-03-24 07:12:31 +00:00
2020-03-30 05:46:11 +00:00
//CommunityCreateHandler 社区创建
func CommunityCreateHandler(c *gin.Context) {
2020-03-30 06:27:05 +00:00
var model community.Community
2020-03-30 05:46:11 +00:00
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)
2020-03-24 07:12:31 +00:00
}