init
This commit is contained in:
		
							
								
								
									
										58
									
								
								handlers/HospitalHandler.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										58
									
								
								handlers/HospitalHandler.go
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,58 @@ | ||||
| package handlers | ||||
|  | ||||
| import ( | ||||
| 	"fmt" | ||||
| 	"github.com/gin-gonic/gin" | ||||
| 	"health-go/config" | ||||
| 	"health-go/models" | ||||
| 	"net/http" | ||||
| ) | ||||
|  | ||||
| func FetchHospitalList(c *gin.Context) { | ||||
| 	var hosList []models.Hospital | ||||
| 	result := config.DB.Table("hospital").Find(&hosList) | ||||
| 	if result.Error != nil { | ||||
| 		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":  "ok", | ||||
| 		"data": hosList, | ||||
| 	}) | ||||
| } | ||||
|  | ||||
| func AddHospital(c *gin.Context) { | ||||
| 	var newHospital models.Hospital | ||||
| 	if err := c.ShouldBindJSON(&newHospital); err != nil { | ||||
| 		c.JSON(http.StatusBadRequest, gin.H{ | ||||
| 			"code": 400, | ||||
| 			"msg":  "无效的请求参数", | ||||
| 			"data": nil, | ||||
| 		}) | ||||
| 		return | ||||
| 	} | ||||
| 	result := config.DB.Create(newHospital) | ||||
| 	fmt.Println(newHospital) | ||||
| 	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": "", | ||||
| 	}) | ||||
| } | ||||
							
								
								
									
										33
									
								
								handlers/RecordHandler.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										33
									
								
								handlers/RecordHandler.go
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,33 @@ | ||||
| package handlers | ||||
|  | ||||
| import ( | ||||
| 	"github.com/gin-gonic/gin" | ||||
| 	"health-go/config" | ||||
| 	"health-go/models" | ||||
| 	"net/http" | ||||
| ) | ||||
|  | ||||
| // FetchAllRecords 每个用户全部化验记录 | ||||
| func FetchAllRecords(c *gin.Context) { | ||||
| 	var records []models.Check | ||||
| 	result := config.DB.Where("user_id = ?", c.Query("user_id")).Find(&records) | ||||
| 	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":  "ok", | ||||
| 		"data": records, | ||||
| 	}) | ||||
| } | ||||
|  | ||||
| func InsertRecord(c *gin.Context) { | ||||
| 	//var aNewRecord models.CheckItem | ||||
|  | ||||
| } | ||||
							
								
								
									
										39
									
								
								handlers/UserHandler.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										39
									
								
								handlers/UserHandler.go
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,39 @@ | ||||
| package handlers | ||||
|  | ||||
| import ( | ||||
| 	"errors" | ||||
| 	"github.com/gin-gonic/gin" | ||||
| 	"gorm.io/gorm" | ||||
| 	"health-go/config" | ||||
| 	"health-go/models" | ||||
| 	"net/http" | ||||
| ) | ||||
|  | ||||
| func FirstUser(c *gin.Context) { | ||||
| 	var user models.User | ||||
| 	result := config.DB.Where("user_name = ?", "Biid").First(&user) | ||||
| 	if result.Error != nil { | ||||
| 		if errors.Is(result.Error, gorm.ErrRecordNotFound) { | ||||
| 			c.JSON(http.StatusNotFound, gin.H{ | ||||
| 				"code": 404, | ||||
| 				"msg":  "用户未找到", | ||||
| 				"data": nil, | ||||
| 			}) | ||||
| 		} else { | ||||
| 			c.JSON(http.StatusInternalServerError, gin.H{ | ||||
| 				"code": 500, | ||||
| 				"msg":  "内部服务器错误", | ||||
| 				"data": nil, | ||||
| 			}) | ||||
| 		} | ||||
| 		return | ||||
| 	} | ||||
|  | ||||
| 	c.JSON(http.StatusOK, gin.H{ | ||||
| 		"code": 200, | ||||
| 		"msg":  "ok", | ||||
| 		"data": map[string]interface{}{ | ||||
| 			"first_user": user, | ||||
| 		}, | ||||
| 	}) | ||||
| } | ||||
							
								
								
									
										13
									
								
								handlers/defaultHandler.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										13
									
								
								handlers/defaultHandler.go
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,13 @@ | ||||
| package handlers | ||||
|  | ||||
| import ( | ||||
| 	"github.com/gin-gonic/gin" | ||||
| ) | ||||
|  | ||||
| func TestPage(c *gin.Context) { | ||||
| 	c.JSON(200, gin.H{ | ||||
| 		"code": 200, | ||||
| 		"msg":  "test", | ||||
| 		"data": map[string]string{"test": "test"}, | ||||
| 	}) | ||||
| } | ||||
		Reference in New Issue
	
	Block a user