Skip to content

Commit 3898a20

Browse files
committed
Update README
1 parent 8f32693 commit 3898a20

File tree

2 files changed

+46
-10
lines changed

2 files changed

+46
-10
lines changed

README.md

+41-2
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ Content-Type: application/json
280280

281281
请求参数:
282282
- token:用户登录后生成的令牌,类型为字符串
283-
- location_id:地点ID,类型为字符串
283+
- location_id:地点ID,类型为整数
284284
- date:预约日期,类型为字符串
285285

286286
请求示例:
@@ -290,7 +290,7 @@ Content-Type: application/json
290290
291291
{
292292
"token": "abcd1234",
293-
"location_id": "1",
293+
"location_id": 1,
294294
"date": "2022-01-01"
295295
}
296296
```
@@ -358,4 +358,43 @@ Content-Type: application/json
358358
}
359359
]
360360
}
361+
```
362+
363+
## 查询地点信息接口
364+
365+
接口地址:/locationinfo
366+
367+
请求方法:POST
368+
369+
请求参数:
370+
- token:用户登录后生成的令牌,类型为字符串
371+
- location_id:地点ID,类型为整数
372+
373+
请求示例:
374+
```
375+
POST /locationinfo
376+
Content-Type: application/json
377+
378+
{
379+
"token": "abcd1234",
380+
"location_id": 1
381+
}
382+
```
383+
384+
返回数据:
385+
- code:返回状态码,0 表示成功,非0 表示失败
386+
- message:返回信息,查询成功或失败的提示信息
387+
- data:返回的数据,查询成功后返回地点的详细信息
388+
389+
返回示例:
390+
```
391+
{
392+
"code": 0,
393+
"message": "查询成功",
394+
"data": {
395+
"id": 1,
396+
"name": "New Location",
397+
"description": "This is a new location"
398+
}
399+
}
361400
```

main.go

+5-8
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package main
22

33
import (
4-
"strconv"
5-
64
"github.com/gin-gonic/gin"
75
"github.com/google/uuid"
86
"gorm.io/driver/sqlite"
@@ -271,7 +269,7 @@ func main() {
271269
r.POST("/reservation", func(c *gin.Context) {
272270
var request struct {
273271
Token string `json:"token"`
274-
LocationID string `json:"location_id"`
272+
LocationID int `json:"location_id"`
275273
Date string `json:"date"`
276274
}
277275
if err := c.ShouldBindJSON(&request); err != nil {
@@ -287,11 +285,10 @@ func main() {
287285

288286
var record Record
289287
record.UserID = tokenData.UserID
290-
locationIDUint, err := strconv.ParseUint(request.LocationID, 10, 32)
291288
if err != nil {
292289
// Handle the error if the conversion fails
293290
}
294-
record.LocationID = uint(locationIDUint)
291+
record.LocationID = uint(request.LocationID)
295292
record.Date = request.Date
296293

297294
if err := db.Create(&record).Error; err != nil {
@@ -329,15 +326,15 @@ func main() {
329326
r.POST("/locationinfo", func(c *gin.Context) {
330327
var request struct {
331328
Token string `json:"token"`
332-
LocationID string `json:"location_id"`
329+
LocationID int `json:"location_id"`
333330
}
334331
if err := c.ShouldBindJSON(&request); err != nil {
335332
c.JSON(400, gin.H{"code": 1, "message": "参数错误"})
336333
return
337334
}
338335

339-
var user User
340-
if err := db.Where("token = ?", request.Token).First(&user).Error; err != nil {
336+
var tokenData Token
337+
if err := db.Model(&tokenData).Where("token = ?", request.Token).First(&tokenData).Error; err != nil {
341338
c.JSON(400, gin.H{"code": 1, "message": "身份验证失败"})
342339
return
343340
}

0 commit comments

Comments
 (0)