Skip to content

Commit

Permalink
refactor!: Use bool types for command parameters to be more consistent
Browse files Browse the repository at this point in the history
BREAKING CHANGE: ds-pushevent and ds-returnevent to use bool true/false instead of yes/no

related: edgexfoundry/go-mod-core-contracts#782

Signed-off-by: Ginny Guan <[email protected]>
  • Loading branch information
jinlinGuan committed Jan 12, 2023
1 parent 9123da5 commit de02595
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 13 deletions.
12 changes: 6 additions & 6 deletions internal/core/command/controller/http/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,13 @@ func (cc *CommandController) CommandsByDeviceName(w http.ResponseWriter, r *http
}

func validateGetCommandParameters(r *http.Request) (err errors.EdgeX) {
dsReturnEvent := utils.ParseQueryStringToString(r, common.ReturnEvent, common.ValueYes)
dsPushEvent := utils.ParseQueryStringToString(r, common.PushEvent, common.ValueNo)
if dsReturnEvent != common.ValueYes && dsReturnEvent != common.ValueNo {
return errors.NewCommonEdgeX(errors.KindContractInvalid, fmt.Sprintf("invalid query parameter, %s has to be %s or %s", dsReturnEvent, common.ValueYes, common.ValueNo), nil)
dsReturnEvent := utils.ParseQueryStringToString(r, common.ReturnEvent, common.ValueTrue)
dsPushEvent := utils.ParseQueryStringToString(r, common.PushEvent, common.ValueFalse)
if dsReturnEvent != common.ValueTrue && dsReturnEvent != common.ValueFalse {
return errors.NewCommonEdgeX(errors.KindContractInvalid, fmt.Sprintf("invalid query parameter, %s has to be %s or %s", dsReturnEvent, common.ValueTrue, common.ValueFalse), nil)
}
if dsPushEvent != common.ValueYes && dsPushEvent != common.ValueNo {
return errors.NewCommonEdgeX(errors.KindContractInvalid, fmt.Sprintf("invalid query parameter, %s has to be %s or %s", dsPushEvent, common.ValueYes, common.ValueNo), nil)
if dsPushEvent != common.ValueTrue && dsPushEvent != common.ValueFalse {
return errors.NewCommonEdgeX(errors.KindContractInvalid, fmt.Sprintf("invalid query parameter, %s has to be %s or %s", dsPushEvent, common.ValueTrue, common.ValueFalse), nil)
}
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion internal/core/command/controller/http/command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const (
testDeviceServiceName = "testDeviceService"
testCommandName = "testCommand"
testBaseAddress = "http://localhost:49990"
testQueryStrings = "a=1&b=2&ds-pushevent=no"
testQueryStrings = "a=1&b=2&ds-pushevent=false"
)

// NewMockDIC function returns a mock bootstrap di Container
Expand Down
4 changes: 2 additions & 2 deletions internal/core/command/controller/messaging/external_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -392,8 +392,8 @@ func testCommandQueryPayload() types.MessageEnvelope {

func testCommandRequestPayload() types.MessageEnvelope {
payload := types.NewMessageEnvelopeForRequest(nil, map[string]string{
"ds-pushevent": "yes",
"ds-returnevent": "yes",
"ds-pushevent": common.ValueTrue,
"ds-returnevent": common.ValueTrue,
})

return payload
Expand Down
8 changes: 4 additions & 4 deletions internal/core/command/controller/messaging/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,13 @@ func validateRequestTopic(prefix string, deviceName string, commandName string,
// validateGetCommandQueryParameters validates the value is valid for device service's reserved query parameters
func validateGetCommandQueryParameters(queryParams map[string]string) error {
if dsReturnEvent, ok := queryParams[common.ReturnEvent]; ok {
if dsReturnEvent != common.ValueYes && dsReturnEvent != common.ValueNo {
return fmt.Errorf("invalid query parameter, %s has to be '%s' or '%s'", common.ReturnEvent, common.ValueYes, common.ValueNo)
if dsReturnEvent != common.ValueTrue && dsReturnEvent != common.ValueFalse {
return fmt.Errorf("invalid query parameter, %s has to be '%s' or '%s'", common.ReturnEvent, common.ValueTrue, common.ValueFalse)
}
}
if dsPushEvent, ok := queryParams[common.PushEvent]; ok {
if dsPushEvent != common.ValueYes && dsPushEvent != common.ValueNo {
return fmt.Errorf("invalid query parameter, %s has to be '%s' or '%s'", common.PushEvent, common.ValueYes, common.ValueNo)
if dsPushEvent != common.ValueTrue && dsPushEvent != common.ValueFalse {
return fmt.Errorf("invalid query parameter, %s has to be '%s' or '%s'", common.PushEvent, common.ValueTrue, common.ValueFalse)
}
}

Expand Down

0 comments on commit de02595

Please sign in to comment.