feat: 添加精确查询

master
ZGGSONG 3 years ago
parent cdc20eeb00
commit aa8a25ef43

@ -1,4 +1,4 @@
## TODO
- [ ] 添加按Key名查找接口
- [x] 添加按Key名查找接口
- [ ] 添加模糊查询接口

@ -8,7 +8,7 @@ import (
"zggsong.cn/sandstone/server/util"
)
func ListAttachments(ctx *gin.Context) {
func Test(ctx *gin.Context) {
var datas []response.Data
var data response.Data
var arrayData = dao.ListAttach()

@ -0,0 +1,36 @@
package api
import (
"github.com/gin-gonic/gin"
"net/http"
"zggsong.cn/sandstone/server/dao"
"zggsong.cn/sandstone/server/response"
"zggsong.cn/sandstone/server/util"
)
func GetRecord(ctx *gin.Context) {
keyName := ctx.GetHeader("keyName")
record := dao.GetRecord(keyName)
if record.KeyName == "" {
ctx.JSON(http.StatusOK, response.Response{
Code: http.StatusOK,
Message: "没有数据",
Data: nil,
})
return
}
var data response.Data
data.KeyName = record.KeyName
data.Size = record.Size
data.CreateTime = record.CreateTime
data.UploadTime = record.UploadTime
data.Line = record.Line
data.Machine = record.Machine
data.Url = util.GetUrl(record.KeyName)
data.Tags = util.GetTags(record.KeyName)
ctx.JSON(http.StatusOK, response.GetResponse{
Code: 200,
Message: "success",
Data: data,
})
}

@ -3,12 +3,11 @@ package dao
import (
"context"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
"log"
"zggsong.cn/sandstone/server/global"
"zggsong.cn/sandstone/server/models"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
)
const (
@ -103,3 +102,10 @@ func Find(limit, page int64) (data []models.Record, total int64, err error) {
}
return
}
//GetRecord 精确查询单条记录
func GetRecord(KeyName string) (record models.Record) {
filter := bson.D{{"keyname", KeyName}}
_ = global.GLO_COLLECTION.FindOne(context.TODO(), filter).Decode(&record)
return
}

@ -7,7 +7,15 @@ type Response struct {
Total int64 `json:"total"`
Page int64 `json:"page"`
}
type GetResponse struct {
Code int `json:"code"`
Message string `json:"message"`
Data interface{} `json:"data"`
}
type Data struct {
Size string `json:"size"`
KeyName string `json:"keyName"`
Line string `json:"line"`
Machine string `json:"machine"`
@ -15,7 +23,6 @@ type Data struct {
UploadTime string `json:"uploadTime"`
Url string `json:"url"`
Size string `json:"size"`
Tags []Tag `json:"tags"`
}
type Tag struct {

@ -6,7 +6,8 @@ import (
)
func CollectRoute(r *gin.Engine) *gin.Engine {
//r.GET("/api/v1/listAll", api.ListAttachments)
r.GET("/api/v1/records", api.ListRecords)
r.GET("/test", api.Test)
r.GET("/v1/records", api.ListRecords)
r.GET("/v1/record", api.GetRecord)
return r
}

@ -28,11 +28,6 @@ func getClient() *s3.Client {
cfg, err := config.LoadDefaultConfig(
context.TODO(),
config.WithCredentialsProvider(credentials.NewStaticCredentialsProvider(accessKey, secretKey, "")),
// 已弃用
// config.WithEndpointResolver(
// aws.EndpointResolverFunc(func(service, region string) (aws.Endpoint, error) {
// return aws.Endpoint{URL: endpoint}, nil
// })),
config.WithEndpointResolverWithOptions(
aws.EndpointResolverWithOptionsFunc(func(service, region string, options ...interface{}) (aws.Endpoint, error) {
return aws.Endpoint{URL: endPoint}, nil

Loading…
Cancel
Save