flatten paging links

pull/10616/head
zhulongcheng 2018-12-12 23:22:24 +08:00
parent ae073ce21d
commit 6d27a08208
5 changed files with 29 additions and 69 deletions

View File

@ -70,15 +70,9 @@ func TestService_handleGetBuckets(t *testing.T) {
body: `
{
"links": {
"prev": {
"prev": ""
},
"self": {
"self": "/api/v2/buckets?descending=false&limit=1&offset=0"
},
"next": {
"next": "/api/v2/buckets?descending=false&limit=1&offset=1"
}
"prev": "",
"self": "/api/v2/buckets?descending=false&limit=1&offset=0",
"next": "/api/v2/buckets?descending=false&limit=1&offset=1"
},
"buckets": [
{
@ -128,15 +122,9 @@ func TestService_handleGetBuckets(t *testing.T) {
body: `
{
"links": {
"prev": {
"prev": ""
},
"self": {
"self": "/api/v2/buckets?descending=false&limit=1&offset=0"
},
"next": {
"next": ""
}
"prev": "",
"self": "/api/v2/buckets?descending=false&limit=1&offset=0",
"next": ""
},
"buckets": []
}`,

View File

@ -102,15 +102,9 @@ func newPagingLinks(basePath string, opts platform.FindOptions, f platform.Pagin
}
links := &platform.PagingLinks{
Self: map[string]string{
"self": self,
},
Prev: map[string]string{
"prev": prev,
},
Next: map[string]string{
"next": next,
},
Prev: prev,
Self: self,
Next: next,
}
return links

View File

@ -121,15 +121,9 @@ func TestPaging_newPagingLinks(t *testing.T) {
},
wants: wants{
links: platform.PagingLinks{
Prev: map[string]string{
"prev": "/api/v2/buckets?descending=true&limit=10&name=name&offset=0&type=type1&type=type2",
},
Self: map[string]string{
"self": "/api/v2/buckets?descending=true&limit=10&name=name&offset=10&type=type1&type=type2",
},
Next: map[string]string{
"next": "/api/v2/buckets?descending=true&limit=10&name=name&offset=20&type=type1&type=type2",
},
Prev: "/api/v2/buckets?descending=true&limit=10&name=name&offset=0&type=type1&type=type2",
Self: "/api/v2/buckets?descending=true&limit=10&name=name&offset=10&type=type1&type=type2",
Next: "/api/v2/buckets?descending=true&limit=10&name=name&offset=20&type=type1&type=type2",
},
},
},
@ -150,15 +144,9 @@ func TestPaging_newPagingLinks(t *testing.T) {
},
wants: wants{
links: platform.PagingLinks{
Prev: map[string]string{
"prev": "",
},
Self: map[string]string{
"self": "/api/v2/buckets?descending=true&limit=10&name=name&offset=0&type=type1&type=type2",
},
Next: map[string]string{
"next": "/api/v2/buckets?descending=true&limit=10&name=name&offset=10&type=type1&type=type2",
},
Prev: "",
Self: "/api/v2/buckets?descending=true&limit=10&name=name&offset=0&type=type1&type=type2",
Next: "/api/v2/buckets?descending=true&limit=10&name=name&offset=10&type=type1&type=type2",
},
},
},
@ -179,15 +167,9 @@ func TestPaging_newPagingLinks(t *testing.T) {
},
wants: wants{
links: platform.PagingLinks{
Prev: map[string]string{
"prev": "/api/v2/buckets?descending=true&limit=10&name=name&offset=0&type=type1&type=type2",
},
Self: map[string]string{
"self": "/api/v2/buckets?descending=true&limit=10&name=name&offset=10&type=type1&type=type2",
},
Next: map[string]string{
"next": "",
},
Prev: "/api/v2/buckets?descending=true&limit=10&name=name&offset=0&type=type1&type=type2",
Self: "/api/v2/buckets?descending=true&limit=10&name=name&offset=10&type=type1&type=type2",
Next: "",
},
},
},
@ -197,16 +179,16 @@ func TestPaging_newPagingLinks(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
links := newPagingLinks(tt.args.basePath, tt.args.opts, tt.args.filter, tt.args.num)
if links.Prev["prev"] != tt.wants.links.Prev["prev"] {
t.Errorf("%q. newPagingLinks() = %v, want %v", tt.name, links.Prev["prev"], tt.wants.links.Prev["prev"])
if links.Prev != tt.wants.links.Prev {
t.Errorf("%q. newPagingLinks() = %v, want %v", tt.name, links.Prev, tt.wants.links.Prev)
}
if links.Self["self"] != tt.wants.links.Self["self"] {
t.Errorf("%q. newPagingLinks() = %v, want %v", tt.name, links.Self["self"], tt.wants.links.Self["self"])
if links.Self != tt.wants.links.Self {
t.Errorf("%q. newPagingLinks() = %v, want %v", tt.name, links.Self, tt.wants.links.Self)
}
if links.Next["next"] != tt.wants.links.Next["next"] {
t.Errorf("%q. newPagingLinks() = %v, want %v", tt.name, links.Next["next"], tt.wants.links.Next["next"])
if links.Next != tt.wants.links.Next {
t.Errorf("%q. newPagingLinks() = %v, want %v", tt.name, links.Next, tt.wants.links.Next)
}
})
}

View File

@ -3809,14 +3809,10 @@ components:
items:
$ref: "#/components/schemas/Bucket"
Link:
type: object
type: string
readOnly: true
format: uri
description: URI of resource.
properties:
href:
type: string
format: uri
required: [href]
Links:
type: object
properties:

View File

@ -17,9 +17,9 @@ type PagingFilter interface {
// PagingLinks represents paging links.
type PagingLinks struct {
Prev map[string]string `json:"prev"`
Self map[string]string `json:"self"`
Next map[string]string `json:"next"`
Prev string `json:"prev"`
Self string `json:"self"`
Next string `json:"next"`
}
// FindOptions represents options passed to all find methods with multiple results.