Skip to content

Commit 3a2127f

Browse files
committed
SnapShot
1 parent f285bfc commit 3a2127f

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

main.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,43 @@ func main() {
173173
c.JSON(200, gin.H{"code": 0, "message": "修改个人信息成功"})
174174
})
175175

176+
// 地点添加接口
177+
r.POST("/addlocation", func(c *gin.Context) {
178+
var request struct {
179+
Token string `json:"token"`
180+
Name string `json:"name"`
181+
Description string `json:"description"`
182+
}
183+
if err := c.ShouldBindJSON(&request); err != nil {
184+
c.JSON(400, gin.H{"code": 1, "message": "参数错误"})
185+
return
186+
}
187+
188+
var tokenRecord Token
189+
if err := db.Where("token = ?", request.Token).First(&tokenRecord).Error; err != nil {
190+
c.JSON(400, gin.H{"code": 1, "message": "身份验证失败"})
191+
return
192+
}
193+
194+
var user User
195+
if err := db.First(&user, tokenRecord.UserID).Error; err != nil {
196+
c.JSON(400, gin.H{"code": 1, "message": "获取用户信息失败"})
197+
return
198+
}
199+
200+
location := Location{
201+
Name: request.Name,
202+
Description: request.Description,
203+
}
204+
205+
if err := db.Create(&location).Error; err != nil {
206+
c.JSON(400, gin.H{"code": 1, "message": "添加地点失败"})
207+
return
208+
}
209+
210+
c.JSON(200, gin.H{"code": 0, "message": "添加地点成功", "data": location})
211+
})
212+
176213
// 预约地点搜索接口
177214
r.POST("/searchlocation", func(c *gin.Context) {
178215
var request struct {

0 commit comments

Comments
 (0)