feat(hospital): add delete & modify apis for hospital
This commit is contained in:
@ -15,7 +15,7 @@ func FetchHospitalList(c *gin.Context) {
|
||||
if result.Error != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{
|
||||
"code": 500,
|
||||
"msg": "内部服务器错误",
|
||||
"msg": "获取医院列表失败",
|
||||
"data": nil,
|
||||
})
|
||||
}
|
||||
@ -24,7 +24,7 @@ func FetchHospitalList(c *gin.Context) {
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"code": 200,
|
||||
"msg": "ok",
|
||||
"msg": "获取医院列表成功",
|
||||
"data": hosList,
|
||||
})
|
||||
}
|
||||
@ -44,7 +44,7 @@ func AddHospital(c *gin.Context) {
|
||||
if result.Error != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{
|
||||
"code": 500,
|
||||
"msg": "内部服务器错误",
|
||||
"msg": "添加医院失败",
|
||||
"data": nil,
|
||||
})
|
||||
return
|
||||
@ -53,6 +53,67 @@ func AddHospital(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"code": 200,
|
||||
"msg": "添加医院成功",
|
||||
"data": "",
|
||||
"data": nil,
|
||||
})
|
||||
}
|
||||
|
||||
func ModifyHospital(c *gin.Context) {
|
||||
var hospital models.Hospital
|
||||
if err := c.ShouldBindJSON(&hospital); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{
|
||||
"code": 400,
|
||||
"msg": "无效的请求参数",
|
||||
"data": err,
|
||||
})
|
||||
return
|
||||
}
|
||||
result := config.DB.
|
||||
Model(&hospital).
|
||||
Where("hospital_id = ?", hospital.HospitalID).
|
||||
Updates(map[string]interface{}{
|
||||
"hospital_name": hospital.HospitalName,
|
||||
"address": hospital.Address,
|
||||
})
|
||||
|
||||
if result.Error != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{
|
||||
"code": 500,
|
||||
"msg": "修改医院信息失败",
|
||||
"data": result.Error,
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"code": 200,
|
||||
"msg": "修改医院信息成功",
|
||||
"data": nil,
|
||||
})
|
||||
}
|
||||
|
||||
func DeleteHospital(c *gin.Context) {
|
||||
var hospital models.Hospital
|
||||
if err := c.ShouldBindJSON(&hospital); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{
|
||||
"code": 400,
|
||||
"msg": "无效的请求参数",
|
||||
"data": nil,
|
||||
})
|
||||
return
|
||||
}
|
||||
result := config.DB.Delete(&hospital)
|
||||
if result.Error != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{
|
||||
"code": 500,
|
||||
"msg": "删除指定医院失败",
|
||||
"data": nil,
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"code": 200,
|
||||
"msg": "删除指定医院成功",
|
||||
"data": nil,
|
||||
})
|
||||
}
|
||||
|
Reference in New Issue
Block a user