generated from Brightscout/mattermost-plugin-starter-template
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[MI-1948] Add API to create task (#5)
* [MI-1846]: Added nvmrc file * Modular folder structure * Modular folder structure * [MI-1846]: Base setup * [MI-1846]: Refactored server base setup * [MI-1854]: Implement OAuth to access Azure DevOps services * [MI-1931] Add API to get projects and get tasks * [MI-1931] Self review fixes * [MI-1931] Review fixes 1 * [MI-1931] Self review fix * [MI-1945] Add function to make protected routes * [MI-1846]: Review fixes * [MI-1931] Review fixes 2 * [MI-1948] Add API to create task * [MI-1931] Add json error handling * [MI-1948] Add error in json format * [MI-1931] Add comment to the code * [MI-1931] Add error check * [MI-1945] Review fix * [MI-1948] Review fixes 1 * [MI-1846]: Review fixes * [MI-1854]: Review fixes * [MI-1854]: Removed unused config * [MI-1854]: Added logic to verify state * [MI-1931] Run fmt * [MI-1945] Review fix 2 * [MI-1948] Self review fix * [MI-1854]: Removed unused configs * [MI-1854]: Review fixes * [MI-1948] Return status code from client * [MI-1931] Remove unused code * [MI-1931] Correct spelling error * [MI-1948] Add wrapper for application/json-patch+json content type * [MI-1948] Correct error handling * [MI-1948] Correct serializer name and add a method * [MI-1948] Correct constants Co-authored-by: Abhishek Verma <abhishek.verma@joshtechnologygroup.com> Co-authored-by: Abhishek Verma <abhishek.verma@brightscout.com>
- Loading branch information
1 parent
42f9cf1
commit d22b29b
Showing
6 changed files
with
196 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package serializers | ||
|
||
import ( | ||
"encoding/json" | ||
"errors" | ||
"io" | ||
"time" | ||
|
||
"github.com/Brightscout/mattermost-plugin-azure-devops/server/constants" | ||
) | ||
|
||
type TaskValue struct { | ||
ID int `json:"id"` | ||
Fields TaskFieldValue `json:"fields"` | ||
} | ||
|
||
type TaskFieldValue struct { | ||
Title string `json:"System.Title"` | ||
Project string `json:"System.TeamProject"` | ||
Type string `json:"System.WorkItemType"` | ||
State string `json:"System.State"` | ||
Reason string `json:"System.Reason"` | ||
AssignedTo TaskUserDetails `json:"System.AssignedTo"` | ||
CreatedAt time.Time `json:"System.CreatedDate"` | ||
CreatedBy TaskUserDetails `json:"System.CreatedBy"` | ||
UpdatedAt time.Time `json:"System.ChangedDate"` | ||
UpdatedBy TaskUserDetails `json:"System.ChangedBy"` | ||
Description string `json:"System.Description"` | ||
} | ||
|
||
type TaskUserDetails struct { | ||
ID string `json:"id"` | ||
DisplayName string `json:"displayName"` | ||
UniqueName string `json:"uniqueName"` | ||
} | ||
|
||
type CreateTaskRequestPayload struct { | ||
Organization string `json:"organization"` | ||
Project string `json:"project"` | ||
Type string `json:"type"` | ||
Fields CreateTaskFieldValue `json:"fields"` | ||
} | ||
|
||
type CreateTaskFieldValue struct { | ||
Title string `json:"title"` | ||
Description string `json:"description"` | ||
} | ||
|
||
type CreateTaskBodyPayload struct { | ||
Operation string `json:"op"` | ||
Path string `json:"path"` | ||
From string `json:"from"` | ||
Value string `json:"value"` | ||
} | ||
|
||
// IsValid function to validate request payload. | ||
func (t *CreateTaskRequestPayload) IsValid() error { | ||
if t.Organization == "" { | ||
return errors.New(constants.OrganizationRequired) | ||
} | ||
if t.Project == "" { | ||
return errors.New(constants.ProjectRequired) | ||
} | ||
if t.Type == "" { | ||
return errors.New(constants.TaskTypeRequired) | ||
} | ||
if t.Fields.Title == "" { | ||
return errors.New(constants.TaskTitleRequired) | ||
} | ||
return nil | ||
} | ||
|
||
func CreateTaskRequestPayloadFromJSON(data io.Reader) (*CreateTaskRequestPayload, error) { | ||
var body *CreateTaskRequestPayload | ||
if err := json.NewDecoder(data).Decode(&body); err != nil { | ||
return nil, err | ||
} | ||
return body, nil | ||
} |