Skip to content
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

Merged
merged 25 commits into from
Dec 8, 2020
Merged

MF-1290 - Sort Things and Channels by name #1293

merged 25 commits into from
Dec 8, 2020

Conversation

manuio
Copy link
Contributor

@manuio manuio commented Nov 25, 2020

Signed-off-by: Manuel Imperiale manuel.imperiale@gmail.com

Resolves #1290

Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com>
@manuio manuio requested a review from a team as a code owner November 25, 2020 15:45
@codecov-io
Copy link

codecov-io commented Nov 25, 2020

Codecov Report

Merging #1293 (8e19f3b) into master (fbba7aa) will decrease coverage by 0.11%.
The diff coverage is 94.11%.

Impacted file tree graph

@@            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     
Impacted Files Coverage Δ
things/api/things/http/responses.go 96.22% <ø> (ø)
things/api/things/http/transport.go 89.19% <73.33%> (-0.84%) ⬇️
things/api/things/http/endpoint.go 98.45% <100.00%> (+0.02%) ⬆️
things/api/things/http/requests.go 87.80% <100.00%> (+0.96%) ⬆️
things/postgres/channels.go 80.68% <100.00%> (+0.91%) ⬆️
things/postgres/things.go 79.71% <100.00%> (+0.29%) ⬆️
things/redis/streams.go 85.59% <100.00%> (ø)
things/service.go 54.28% <100.00%> (ø)
authz/api/http/transport.go
authz/api/grpc/requests.go
... and 6 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update fbba7aa...f91f36d. Read the comment docs.

bbokun
bbokun previously approved these changes Nov 25, 2020
Copy link

@bbokun bbokun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@@ -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)
Copy link
Contributor

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?

Copy link
Contributor Author

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.

blokovi
blokovi previously approved these changes Dec 3, 2020
Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com>
Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com>
@manuio manuio dismissed stale reviews from blokovi and bbokun via d8a59f8 December 4, 2020 09:25
if name != "" {
nlog = fmt.Sprintf("with name %s ", name)
if pm.Name != "" {
nlog = fmt.Sprintf("with name %s ", pm.Name)
Copy link
Collaborator

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>
Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com>
@dborovcanin
Copy link
Collaborator

Please add order to the API response so that we can merge this one.

things/postgres/channels_test.go Outdated Show resolved Hide resolved
things/postgres/things_test.go Outdated Show resolved Hide resolved
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>
dborovcanin
dborovcanin previously approved these changes Dec 8, 2020
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>
schema:
type: string
default: id
format: byte
Copy link
Collaborator

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.

schema:
type: string
default: desc
format: byte
Copy link
Collaborator

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -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",
Copy link
Collaborator

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",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here.

},
size: nameMetaNum,
},
"retrieve channels sorted by ascendent name": {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

...ordered by name ascendent...

},
size: n,
},
"retrieve channels sorted by descendent name": {
Copy link
Collaborator

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>
@@ -642,15 +647,14 @@ components:
description: Unique channel identifier.
in: path
schema:
type: string
type: uuid
Copy link
Contributor

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.

manuio and others added 4 commits December 8, 2020 17:01
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>
@@ -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)
Copy link
Contributor

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.

@@ -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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here also

}

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 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here probably also

err: nil,
metadata: meta,
token: token,
pageMeta: things.PageMetadata{
Copy link
Contributor

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>
Copy link
Contributor

@drasko drasko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@drasko drasko dismissed darkodraskovic’s stale review December 8, 2020 20:30

Good remark. This was resolved.

@drasko drasko merged commit 3653e6b into absmach:master Dec 8, 2020
@manuio manuio deleted the order branch February 23, 2022 12:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Sort order of things, channels
7 participants