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

refactor!: Use true/false for command parameters to be more consistent #782

Merged
merged 1 commit into from
Jan 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions clients/http/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ func (client *CommandClient) DeviceCoreCommandsByDeviceName(ctx context.Context,
}

// IssueGetCommandByName issues the specified read command referenced by the command name to the device/sensor that is also referenced by name.
func (client *CommandClient) IssueGetCommandByName(ctx context.Context, deviceName string, commandName string, dsPushEvent string, dsReturnEvent string) (res *responses.EventResponse, err errors.EdgeX) {
func (client *CommandClient) IssueGetCommandByName(ctx context.Context, deviceName string, commandName string, dsPushEvent bool, dsReturnEvent bool) (res *responses.EventResponse, err errors.EdgeX) {
requestParams := url.Values{}
requestParams.Set(common.PushEvent, dsPushEvent)
requestParams.Set(common.ReturnEvent, dsReturnEvent)
requestParams.Set(common.PushEvent, strconv.FormatBool(dsPushEvent))
requestParams.Set(common.ReturnEvent, strconv.FormatBool(dsReturnEvent))
requestPath := path.Join(common.ApiDeviceRoute, common.Name, deviceName, commandName)
err = utils.GetRequest(ctx, &res, client.baseUrl, requestPath, requestParams)
if err != nil {
Expand Down
7 changes: 6 additions & 1 deletion clients/http/command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"net/http"
"net/http/httptest"
"path"
"strconv"
"testing"

"github.com/edgexfoundry/go-mod-core-contracts/v3/common"
Expand Down Expand Up @@ -47,7 +48,11 @@ func TestIssueGetCommandByName(t *testing.T) {
ts := newTestServer(http.MethodGet, path, &responses.EventResponse{})
defer ts.Close()
client := NewCommandClient(ts.URL)
res, err := client.IssueGetCommandByName(context.Background(), deviceName, cmdName, common.ValueYes, common.ValueNo)
pushEvent, err := strconv.ParseBool(common.ValueTrue)
require.NoError(t, err)
notReturnEvent, err := strconv.ParseBool(common.ValueFalse)
require.NoError(t, err)
res, err := client.IssueGetCommandByName(context.Background(), deviceName, cmdName, pushEvent, notReturnEvent)
require.NoError(t, err)
require.IsType(t, &responses.EventResponse{}, res)
}
Expand Down
6 changes: 3 additions & 3 deletions clients/interfaces/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ type CommandClient interface {
// DeviceCoreCommandsByDeviceName returns all commands associated with the specified device name.
DeviceCoreCommandsByDeviceName(ctx context.Context, deviceName string) (responses.DeviceCoreCommandResponse, errors.EdgeX)
// IssueGetCommandByName issues the specified read command referenced by the command name to the device/sensor that is also referenced by name.
// dsPushEvent: If set to yes, a successful GET will result in an event being pushed to the EdgeX system. Default value is no.
// dsReturnEvent: If set to no, there will be no Event returned in the http response. Default value is yes.
IssueGetCommandByName(ctx context.Context, deviceName string, commandName string, dsPushEvent string, dsReturnEvent string) (*responses.EventResponse, errors.EdgeX)
// dsPushEvent: If set to true, a successful GET will result in an event being pushed to the EdgeX system. Default value is false.
// dsReturnEvent: If set to false, there will be no Event returned in the http response. Default value is true.
IssueGetCommandByName(ctx context.Context, deviceName string, commandName string, dsPushEvent bool, dsReturnEvent bool) (*responses.EventResponse, errors.EdgeX)
// IssueGetCommandByNameWithQueryParams issues the specified read command by deviceName and commandName with additional query parameters.
IssueGetCommandByNameWithQueryParams(ctx context.Context, deviceName string, commandName string, queryParams map[string]string) (*responses.EventResponse, errors.EdgeX)
// IssueSetCommandByName issues the specified write command referenced by the command name to the device/sensor that is also referenced by name.
Expand Down
2 changes: 0 additions & 2 deletions common/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,6 @@ const (
DefaultOffset = 0
DefaultLimit = 20
CommaSeparator = ","
ValueYes = "yes"
ValueNo = "no"
ValueTrue = "true"
ValueFalse = "false"
Comment on lines 193 to 194
Copy link
Member

Choose a reason for hiding this comment

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

Do we really need these constants for true and false`??

Suggested change
ValueTrue = "true"
ValueFalse = "false"
ValueTrue = true
ValueFalse = false

Copy link
Member

@cloudxxx8 cloudxxx8 Jan 3, 2023

Choose a reason for hiding this comment

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

yes, we still need them for the query parameter definition to validate the values

Copy link
Member

Choose a reason for hiding this comment

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

they should still be in string data type, because the REST query parameter only allows string value

Copy link
Member

Choose a reason for hiding this comment

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

Ok, can we then parse them to bool so that the IssueGetCommandByName func can use bool?

Copy link
Member

Choose a reason for hiding this comment

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

Sure, IssueGetCommandByName client can use bool directly, and ValueTrue/ValueFalse will be used in the core-command internal implementation.

)
Expand Down