-
Notifications
You must be signed in to change notification settings - Fork 674
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MF-1290 - Sort Things and Channels by name #1293
Conversation
Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com>
Codecov Report
@@ Coverage Diff @@
## master #1293 +/- ##
==========================================
- Coverage 64.57% 64.45% -0.12%
==========================================
Files 117 109 -8
Lines 7994 7858 -136
==========================================
- Hits 5162 5065 -97
+ Misses 2379 2352 -27
+ Partials 453 441 -12
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
things/postgres/channels.go
Outdated
@@ -128,7 +128,7 @@ func (cr channelRepository) RetrieveAll(ctx context.Context, owner string, offse | |||
} | |||
|
|||
q := fmt.Sprintf(`SELECT id, name, metadata FROM channels | |||
WHERE owner = :owner %s%s ORDER BY id LIMIT :limit OFFSET :offset;`, mq, nq) | |||
WHERE owner = :owner %s%s ORDER BY name LIMIT :limit OFFSET :offset;`, mq, nq) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am really not sure about this one... Is name
even mandatory in our Thing entity?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Name is not mandatory but sorting works for empty strings.
Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com>
Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com>
Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com>
things/api/logging.go
Outdated
if name != "" { | ||
nlog = fmt.Sprintf("with name %s ", name) | ||
if pm.Name != "" { | ||
nlog = fmt.Sprintf("with name %s ", pm.Name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not related to this PR, but can you, please, fix the formatting: nlog = fmt.Sprintf("with name %s", pm.Name)
(no space after) and later message := fmt.Sprintf("Method list_things %s for token %s took %s to complete", nlog, token, time.Since(begin))
(%s
surrounded with spaces)? Same for the ListChannels
.
Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com>
Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com>
Please add |
Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com>
Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com>
Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com>
Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com>
Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com>
Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com>
Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com>
things/openapi.yml
Outdated
schema: | ||
type: string | ||
default: id | ||
format: byte |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Byte format indicates base64-encoded binary. You can simply remove it.
things/openapi.yml
Outdated
schema: | ||
type: string | ||
default: desc | ||
format: byte |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here.
Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com>
@@ -654,8 +654,7 @@ components: | |||
description: Unique thing identifier. | |||
in: path | |||
schema: | |||
type: integer | |||
minimum: 1 | |||
type: string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add here format: uuid
according to https://swagger.io/docs/specification/data-models/data-types/
@@ -663,6 +663,13 @@ func TestListThings(t *testing.T) { | |||
url: fmt.Sprintf("%s?offset=%d&limit=%d", thingURL, 0, 5), | |||
res: data[0:5], | |||
}, | |||
{ | |||
desc: "get a list of things ordered by ascendent name", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
order by name ascendent
Also, this seems to be descendnet.
@@ -1425,6 +1432,13 @@ func TestListChannels(t *testing.T) { | |||
url: fmt.Sprintf("%s?offset=%d&limit=%d", channelURL, 0, 6), | |||
res: channels[0:6], | |||
}, | |||
{ | |||
desc: "get a list of channels ordered by ascendent name", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here.
things/postgres/channels_test.go
Outdated
}, | ||
size: nameMetaNum, | ||
}, | ||
"retrieve channels sorted by ascendent name": { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
...ordered by name ascendent...
things/postgres/channels_test.go
Outdated
}, | ||
size: n, | ||
}, | ||
"retrieve channels sorted by descendent name": { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
...ordered by name descendent...
Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com>
things/openapi.yml
Outdated
@@ -642,15 +647,14 @@ components: | |||
description: Unique channel identifier. | |||
in: path | |||
schema: | |||
type: string | |||
type: uuid |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is wrong. Not type: uuid
, but format: uuid
and keep type: string
.
Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com>
Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com>
Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com>
things/api/things/http/endpoint.go
Outdated
@@ -151,7 +151,7 @@ func listThingsEndpoint(svc things.Service) endpoint.Endpoint { | |||
return nil, err | |||
} | |||
|
|||
page, err := svc.ListThings(ctx, req.token, req.offset, req.limit, req.name, req.metadata) | |||
page, err := svc.ListThings(ctx, req.token, req.pageMeta) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do not like the fact that previously it was called pageMetadata
. I think we should stay consistent. I would advise putting pageMetadata
here as well.
things/api/things/http/endpoint.go
Outdated
@@ -355,7 +357,7 @@ func listChannelsEndpoint(svc things.Service) endpoint.Endpoint { | |||
return nil, err | |||
} | |||
|
|||
page, err := svc.ListChannels(ctx, req.token, req.offset, req.limit, req.name, req.metadata) | |||
page, err := svc.ListChannels(ctx, req.token, req.pageMeta) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here also
things/api/things/http/requests.go
Outdated
} | ||
|
||
func (req *listResourcesReq) validate() error { | ||
if req.token == "" { | ||
return things.ErrUnauthorizedAccess | ||
} | ||
|
||
if req.limit == 0 || req.limit > maxLimitSize { | ||
if req.pageMeta.Limit == 0 || req.pageMeta.Limit > maxLimitSize { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here probably also
things/service_test.go
Outdated
err: nil, | ||
metadata: meta, | ||
token: token, | ||
pageMeta: things.PageMetadata{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pageMetadata
probably?
Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Good remark. This was resolved.
Signed-off-by: Manuel Imperiale manuel.imperiale@gmail.com
Resolves #1290