You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by GitBox <gi...@apache.org> on 2021/01/18 14:59:49 UTC

[GitHub] [apisix-dashboard] imjoey commented on a change in pull request #1322: feat: Add returning value for HTTP PUT and PATCH methods

imjoey commented on a change in pull request #1322:
URL: https://github.com/apache/apisix-dashboard/pull/1322#discussion_r559624831



##########
File path: api/internal/handler/consumer/consumer.go
##########
@@ -147,11 +147,12 @@ func (h *Handler) Set(c droplet.Context) (interface{}, error) {
 	input.Consumer.ID = input.Consumer.Username
 	ensurePluginsDefValue(input.Plugins)
 
-	if err := h.consumerStore.Update(c.Context(), &input.Consumer, true); err != nil {
+	ret, err := h.consumerStore.Update(c.Context(), &input.Consumer, true)
+	if err != nil {
 		return handler.SpecCodeResponse(err), err
 	}
 
-	return nil, nil
+	return ret, nil

Review comment:
       @ShiningRush  Thanks for your reviewing. IMHO, directly returning the `&input.Consumer` would mix up the DTO and the DAO, which may be confusing to developer. Please allow me use the following case as an example:
   
   ```go
   type SetInput struct {
   	entity.Consumer
   	Username string `auto_read:"username,path"`
   }
   
   func (h *Handler) Set(c droplet.Context) (interface{}, error) {
   	input := c.Input().(*SetInput)
   	if input.ID != nil && utils.InterfaceToString(input.ID) != input.Username {
   		return &data.SpecCodeResponse{StatusCode: http.StatusBadRequest},
   			fmt.Errorf("consumer's id and username must be a same value")
   	}
   	if input.Username != "" {
   		input.Consumer.Username = input.Username
   	}
   	input.Consumer.ID = input.Consumer.Username
   	ensurePluginsDefValue(input.Plugins)
   
   	err := h.consumerStore.Update(c.Context(), &input.Consumer, true)
   	if err != nil {
   		return handler.SpecCodeResponse(err), err
   	}
   
           // Notice: Desensitize the response data  =======
           input.Consumer.Desc = "*******"
   
   	return &input.Consumer, nil
   }
   
   ```
   
   As the comment mentioned above, in order to do customization before sending back to client, we need to change input value for output, which seems some sort of werid.
   
   Looking forward to your insights. Thanks.
   




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org