Skip to content

Commit

Permalink
Update README
Browse files Browse the repository at this point in the history
  • Loading branch information
DataEraserC committed Aug 12, 2023
1 parent 8f32693 commit 3898a20
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 10 deletions.
43 changes: 41 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ Content-Type: application/json

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

请求示例:
Expand All @@ -290,7 +290,7 @@ Content-Type: application/json
{
"token": "abcd1234",
"location_id": "1",
"location_id": 1,
"date": "2022-01-01"
}
```
Expand Down Expand Up @@ -358,4 +358,43 @@ Content-Type: application/json
}
]
}
```

## 查询地点信息接口

接口地址:/locationinfo

请求方法:POST

请求参数:
- token:用户登录后生成的令牌,类型为字符串
- location_id:地点ID,类型为整数

请求示例:
```
POST /locationinfo
Content-Type: application/json
{
"token": "abcd1234",
"location_id": 1
}
```

返回数据:
- code:返回状态码,0 表示成功,非0 表示失败
- message:返回信息,查询成功或失败的提示信息
- data:返回的数据,查询成功后返回地点的详细信息

返回示例:
```
{
"code": 0,
"message": "查询成功",
"data": {
"id": 1,
"name": "New Location",
"description": "This is a new location"
}
}
```
13 changes: 5 additions & 8 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package main

import (
"strconv"

"github.com/gin-gonic/gin"
"github.com/google/uuid"
"gorm.io/driver/sqlite"
Expand Down Expand Up @@ -271,7 +269,7 @@ func main() {
r.POST("/reservation", func(c *gin.Context) {
var request struct {
Token string `json:"token"`
LocationID string `json:"location_id"`
LocationID int `json:"location_id"`
Date string `json:"date"`
}
if err := c.ShouldBindJSON(&request); err != nil {
Expand All @@ -287,11 +285,10 @@ func main() {

var record Record
record.UserID = tokenData.UserID
locationIDUint, err := strconv.ParseUint(request.LocationID, 10, 32)
if err != nil {
// Handle the error if the conversion fails
}
record.LocationID = uint(locationIDUint)
record.LocationID = uint(request.LocationID)
record.Date = request.Date

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

var user User
if err := db.Where("token = ?", request.Token).First(&user).Error; err != nil {
var tokenData Token
if err := db.Model(&tokenData).Where("token = ?", request.Token).First(&tokenData).Error; err != nil {
c.JSON(400, gin.H{"code": 1, "message": "身份验证失败"})
return
}
Expand Down

0 comments on commit 3898a20

Please sign in to comment.