You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@devlake.apache.org by GitBox <gi...@apache.org> on 2022/11/23 12:13:27 UTC

[GitHub] [incubator-devlake] klesh commented on a diff in pull request #3797: refactor: add transformation_rule_id to _tool_jira_boards

klesh commented on code in PR #3797:
URL: https://github.com/apache/incubator-devlake/pull/3797#discussion_r1030369176


##########
plugins/jira/api/scope.go:
##########
@@ -24,52 +24,66 @@ import (
 	"github.com/apache/incubator-devlake/errors"
 	"github.com/apache/incubator-devlake/plugins/core"
 	"github.com/apache/incubator-devlake/plugins/core/dal"
+	"github.com/apache/incubator-devlake/plugins/helper"
 	"github.com/apache/incubator-devlake/plugins/jira/models"
 	"github.com/mitchellh/mapstructure"
 )
 
-type putBoardRequest struct {
-	ProjectId uint   `json:"projectId"`
-	Name      string `json:"name"`
-	Self      string `json:"self"`
-	Type      string `json:"type"`
-}
-
 // PutScope create or update jira board
 // @Summary create or update jira board
 // @Description Create or update Jira board
 // @Tags plugins/jira
 // @Accept application/json
 // @Param connectionId path int false "connection ID"
 // @Param boardId path int false "board ID"
-// @Param scope body putBoardRequest true "json"
+// @Param scope body models.JiraBoard true "json"
 // @Success 200  {object} models.JiraBoard
 // @Failure 400  {object} shared.ApiBody "Bad Request"
 // @Failure 500  {object} shared.ApiBody "Internal Error"
 // @Router /plugins/jira/connections/{connectionId}/scopes/{boardId} [PUT]
 func PutScope(input *core.ApiResourceInput) (*core.ApiResourceOutput, errors.Error) {
-	connectionId, boardId := extractParam(input.Params)
-	if connectionId*boardId == 0 {
-		return nil, errors.BadInput.New("invalid path params")
+	board, err := extractBoard(input)
+	if err != nil {
+		return nil, err
 	}
-	var req putBoardRequest
-	err := mapstructure.Decode(input.Body, &req)
+	err = basicRes.GetDal().CreateOrUpdate(board)
 	if err != nil {
-		return nil, errors.Default.Wrap(err, "error decoding map into putBoardRequest")
+		return nil, errors.Default.Wrap(err, "error on saving JiraBoard")
 	}
-	board := &models.JiraBoard{
-		ConnectionId: connectionId,
-		BoardId:      boardId,
-		ProjectId:    req.ProjectId,
-		Name:         req.Name,
-		Self:         req.Self,
-		Type:         req.Type,
+	return &core.ApiResourceOutput{Body: board, Status: http.StatusOK}, nil
+}
+
+// UpdateScope patch to jira board
+// @Summary patch to jira board
+// @Description patch to jira board
+// @Tags plugins/jira
+// @Accept application/json
+// @Param connectionId path int false "connection ID"
+// @Param boardId path int false "board ID"
+// @Param scope body models.JiraBoard true "json"
+// @Success 200  {object} models.JiraBoard
+// @Failure 400  {object} shared.ApiBody "Bad Request"
+// @Failure 500  {object} shared.ApiBody "Internal Error"
+// @Router /plugins/jira/connections/{connectionId}/scopes/{boardId} [PATCH]
+func UpdateScope(input *core.ApiResourceInput) (*core.ApiResourceOutput, errors.Error) {
+	board, err := extractBoard(input)

Review Comment:
   This is not needed. What we need to do:
   1. load the board from db
   2. DecodeMapStruct from input.body to the board (this is essentially a patch operation)
   3. verify and save



-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@devlake.apache.org

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