package controller
|
|
import (
|
"net/http"
|
|
"gat1400Exchange/repository"
|
"gat1400Exchange/vo"
|
"github.com/gin-gonic/gin"
|
)
|
|
type SubPlatformController struct {
|
Repository repository.SubPlatformRepository
|
}
|
|
// 构造函数
|
func NewSubPlatformController() SubPlatformController {
|
svr := repository.NewSubPlatformRepository()
|
controller := SubPlatformController{svr}
|
|
return controller
|
}
|
|
func (s SubPlatformController) List(c *gin.Context) {
|
subList, _ := s.Repository.List()
|
|
c.JSON(http.StatusOK, gin.H{"data": subList})
|
}
|
|
func (s SubPlatformController) Create(c *gin.Context) {
|
var req vo.RequestSubPlatform
|
if err := c.BindJSON(&req); err != nil {
|
c.JSON(http.StatusBadRequest, gin.H{"msg": err.Error()})
|
return
|
}
|
|
if err := s.Repository.Create(&req); err != nil {
|
c.JSON(http.StatusInternalServerError, gin.H{"msg": err.Error()})
|
return
|
}
|
|
c.JSON(http.StatusOK, gin.H{"msg": "ok"})
|
}
|
|
func (s SubPlatformController) Update(c *gin.Context) {
|
var req vo.RequestSubPlatform
|
if err := c.BindJSON(&req); err != nil {
|
c.JSON(http.StatusBadRequest, gin.H{"msg": err.Error()})
|
return
|
}
|
|
if err := s.Repository.Update(&req); err != nil {
|
c.JSON(http.StatusInternalServerError, gin.H{"msg": err.Error()})
|
return
|
}
|
|
c.JSON(http.StatusOK, gin.H{"msg": "ok"})
|
}
|
|
func (s SubPlatformController) Delete(c *gin.Context) {
|
if c.Param("id") == "" {
|
c.JSON(http.StatusBadRequest, gin.H{"msg": "请求的id为空"})
|
return
|
}
|
|
if err := s.Repository.Delete(c.Param("id")); err != nil {
|
c.JSON(http.StatusInternalServerError, gin.H{"msg": err.Error()})
|
return
|
}
|
|
c.JSON(http.StatusOK, gin.H{"msg": "ok"})
|
}
|