zhangzengfei
2024-10-22 a254bc563003a9e7b3a8f1307df38b8ae4274a4f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
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"})
}