-
Notifications
You must be signed in to change notification settings - Fork 64
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
Fix(Issue#202): counts in one request #225
base: master
Are you sure you want to change the base?
Changes from 5 commits
bdb189c
80d96b7
49f7ffc
e822f51
6624565
cd53a4b
2d27842
99b959c
046d508
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,6 +32,8 @@ type ListManager interface { | |
SendIssue(senderID, receiverID, message, description, postID string) (string, error) | ||
// GetIssueList gets the todos on listID for userID | ||
GetIssueList(userID, listID string) ([]*ExtendedIssue, error) | ||
// GetAllList get all issues | ||
GetAllList(userID string) (*ListsIssue, error) | ||
// CompleteIssue completes the todo issueID for userID, and returns the issue and the foreign ID if any | ||
CompleteIssue(userID, issueID string) (issue *Issue, foreignID string, listToUpdate string, err error) | ||
// AcceptIssue moves one the todo issueID of userID from inbox to myList, and returns the message and the foreignUserID if any | ||
|
@@ -116,6 +118,7 @@ func (p *Plugin) initializeAPI() { | |
|
||
p.router.HandleFunc("/add", p.checkAuth(p.handleAdd)).Methods(http.MethodPost) | ||
p.router.HandleFunc("/list", p.checkAuth(p.handleList)).Methods(http.MethodGet) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need this endpoint anymore? Or are we still calling this in some cases? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No need so i delete it but getIssueList is used by command |
||
p.router.HandleFunc("/lists", p.checkAuth(p.handleLists)).Methods(http.MethodGet) | ||
p.router.HandleFunc("/remove", p.checkAuth(p.handleRemove)).Methods(http.MethodPost) | ||
p.router.HandleFunc("/complete", p.checkAuth(p.handleComplete)).Methods(http.MethodPost) | ||
p.router.HandleFunc("/accept", p.checkAuth(p.handleAccept)).Methods(http.MethodPost) | ||
|
@@ -168,8 +171,9 @@ func (p *Plugin) handleTelemetry(w http.ResponseWriter, r *http.Request) { | |
|
||
telemetryRequest, err := GetTelemetryPayloadFromJSON(r.Body) | ||
if err != nil { | ||
p.API.LogError("Unable to get telemetry payload from JSON err=" + err.Error()) | ||
p.handleErrorWithCode(w, http.StatusBadRequest, "Unable to get telemetry payload from JSON.", err) | ||
msg := "Unable to get telemetry payload from JSON" | ||
p.API.LogError(msg, "err", err.Error()) | ||
p.handleErrorWithCode(w, http.StatusBadRequest, msg, err) | ||
Comment on lines
+181
to
+183
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry I was unclear about my request before. We shouldn't edit the log statements in functions unrelated to this PR's purpose. We can clean this up in a separate effort/PR There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry too. should I put everything back the way it was before? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes everything that is not related to the main feature/effort of the PR There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ideally we do change the logging back the way it was for places unrelated the purpose of the PR, but I don't want to drag this PR on for that reason |
||
return | ||
} | ||
|
||
|
@@ -188,8 +192,9 @@ func (p *Plugin) handleAdd(w http.ResponseWriter, r *http.Request) { | |
|
||
addRequest, err := GetAddIssuePayloadFromJSON(r.Body) | ||
if err != nil { | ||
p.API.LogError("Unable to get add issue payload from JSON err=" + err.Error()) | ||
p.handleErrorWithCode(w, http.StatusBadRequest, "Unable to get add issue payload from JSON.", err) | ||
msg := "Unable to get add issue payload from JSON" | ||
p.API.LogError(msg, "err", err.Error()) | ||
p.handleErrorWithCode(w, http.StatusBadRequest, msg, err) | ||
return | ||
} | ||
|
||
|
@@ -203,8 +208,9 @@ func (p *Plugin) handleAdd(w http.ResponseWriter, r *http.Request) { | |
if addRequest.SendTo == "" { | ||
_, err = p.listManager.AddIssue(userID, addRequest.Message, addRequest.Description, addRequest.PostID) | ||
if err != nil { | ||
p.API.LogError("Unable to add issue err=" + err.Error()) | ||
p.handleErrorWithCode(w, http.StatusInternalServerError, "Unable to add issue", err) | ||
msg := "Unable to add issue" | ||
p.API.LogError(msg, "err", err.Error()) | ||
p.handleErrorWithCode(w, http.StatusInternalServerError, msg, err) | ||
return | ||
} | ||
|
||
|
@@ -220,16 +226,18 @@ func (p *Plugin) handleAdd(w http.ResponseWriter, r *http.Request) { | |
|
||
receiver, appErr := p.API.GetUserByUsername(addRequest.SendTo) | ||
if appErr != nil { | ||
p.API.LogError("username not valid, err=" + appErr.Error()) | ||
p.handleErrorWithCode(w, http.StatusInternalServerError, "Unable to find user", appErr) | ||
msg := "Unable to find user" | ||
p.API.LogError(msg, "err", err.Error()) | ||
p.handleErrorWithCode(w, http.StatusInternalServerError, msg, err) | ||
return | ||
} | ||
|
||
if receiver.Id == userID { | ||
_, err = p.listManager.AddIssue(userID, addRequest.Message, addRequest.Description, addRequest.PostID) | ||
if err != nil { | ||
p.API.LogError("Unable to add issue err=" + err.Error()) | ||
p.handleErrorWithCode(w, http.StatusInternalServerError, "Unable to add issue", err) | ||
msg := "Unable to add issue" | ||
p.API.LogError(msg, "err", err.Error()) | ||
p.handleErrorWithCode(w, http.StatusInternalServerError, msg, err) | ||
return | ||
} | ||
|
||
|
@@ -255,8 +263,9 @@ func (p *Plugin) handleAdd(w http.ResponseWriter, r *http.Request) { | |
|
||
issueID, err := p.listManager.SendIssue(userID, receiver.Id, addRequest.Message, addRequest.Description, addRequest.PostID) | ||
if err != nil { | ||
p.API.LogError("Unable to send issue err=" + err.Error()) | ||
p.handleErrorWithCode(w, http.StatusInternalServerError, "Unable to send issue", err) | ||
msg := "Unable to send issue" | ||
p.API.LogError(msg, "err", err.Error()) | ||
p.handleErrorWithCode(w, http.StatusInternalServerError, msg, err) | ||
return | ||
} | ||
|
||
|
@@ -295,17 +304,19 @@ func (p *Plugin) handleList(w http.ResponseWriter, r *http.Request) { | |
|
||
issues, err := p.listManager.GetIssueList(userID, listID) | ||
if err != nil { | ||
p.API.LogError("Unable to get issues for user err=" + err.Error()) | ||
p.handleErrorWithCode(w, http.StatusInternalServerError, "Unable to get issues for user", err) | ||
msg := "Unable to get issues for user" | ||
p.API.LogError(msg, "err", err.Error()) | ||
p.handleErrorWithCode(w, http.StatusInternalServerError, msg, err) | ||
return | ||
} | ||
|
||
if len(issues) > 0 && r.URL.Query().Get("reminder") == "true" && p.getReminderPreference(userID) { | ||
var lastReminderAt int64 | ||
lastReminderAt, err = p.getLastReminderTimeForUser(userID) | ||
if err != nil { | ||
p.API.LogError("Unable to send reminder err=" + err.Error()) | ||
p.handleErrorWithCode(w, http.StatusInternalServerError, "Unable to send reminder", err) | ||
msg := "Unable to send reminder" | ||
p.API.LogError(msg, "err", err.Error()) | ||
p.handleErrorWithCode(w, http.StatusInternalServerError, msg, err) | ||
return | ||
} | ||
|
||
|
@@ -329,8 +340,9 @@ func (p *Plugin) handleList(w http.ResponseWriter, r *http.Request) { | |
|
||
issuesJSON, err := json.Marshal(issues) | ||
if err != nil { | ||
p.API.LogError("Unable marhsal issues list to json err=" + err.Error()) | ||
p.handleErrorWithCode(w, http.StatusInternalServerError, "Unable marhsal issues list to json", err) | ||
msg := "Unable marhsal count issue list to json" | ||
p.API.LogError(msg, "err", err.Error()) | ||
p.handleErrorWithCode(w, http.StatusInternalServerError, msg, err) | ||
return | ||
} | ||
|
||
|
@@ -340,13 +352,39 @@ func (p *Plugin) handleList(w http.ResponseWriter, r *http.Request) { | |
} | ||
} | ||
|
||
func (p *Plugin) handleLists(w http.ResponseWriter, r *http.Request) { | ||
userID := r.Header.Get("Mattermost-User-ID") | ||
|
||
allListIssue, err := p.listManager.GetAllList(userID) | ||
if err != nil { | ||
msg := "Unable to get issues for user" | ||
p.API.LogError(msg, "err", err.Error()) | ||
p.handleErrorWithCode(w, http.StatusInternalServerError, msg, err) | ||
return | ||
} | ||
|
||
allListIssueJSON, err := json.Marshal(allListIssue) | ||
if err != nil { | ||
msg := "Unable marhsal all lists issues to json" | ||
p.API.LogError(msg, "err", err.Error()) | ||
p.handleErrorWithCode(w, http.StatusInternalServerError, msg, err) | ||
return | ||
} | ||
|
||
_, err = w.Write(allListIssueJSON) | ||
if err != nil { | ||
p.API.LogError("Unable to write json response err=" + err.Error()) | ||
} | ||
} | ||
|
||
func (p *Plugin) handleEdit(w http.ResponseWriter, r *http.Request) { | ||
userID := r.Header.Get("Mattermost-User-ID") | ||
|
||
editRequest, err := GetEditIssuePayloadFromJSON(r.Body) | ||
if err != nil { | ||
p.API.LogError("Unable to get edit issue payload from JSON err=" + err.Error()) | ||
p.handleErrorWithCode(w, http.StatusBadRequest, "Unable to get edit issue payload from JSON.", err) | ||
msg := "Unable to get edit issue payload from JSON" | ||
p.API.LogError(msg, "err", err.Error()) | ||
p.handleErrorWithCode(w, http.StatusBadRequest, msg, err) | ||
return | ||
} | ||
|
||
|
@@ -357,8 +395,9 @@ func (p *Plugin) handleEdit(w http.ResponseWriter, r *http.Request) { | |
|
||
foreignUserID, list, oldMessage, err := p.listManager.EditIssue(userID, editRequest.ID, editRequest.Message, editRequest.Description) | ||
if err != nil { | ||
p.API.LogError("Unable to edit message: err=" + err.Error()) | ||
p.handleErrorWithCode(w, http.StatusInternalServerError, "Unable to edit issue", err) | ||
msg := "Unable to edit message" | ||
p.API.LogError(msg, "err", err.Error()) | ||
p.handleErrorWithCode(w, http.StatusInternalServerError, msg, err) | ||
return | ||
} | ||
|
||
|
@@ -385,8 +424,9 @@ func (p *Plugin) handleChangeAssignment(w http.ResponseWriter, r *http.Request) | |
|
||
changeRequest, err := GetChangeAssignmentPayloadFromJSON(r.Body) | ||
if err != nil { | ||
p.API.LogError("Unable to get change request payload from JSON err=" + err.Error()) | ||
p.handleErrorWithCode(w, http.StatusBadRequest, "Unable to get change request from JSON.", err) | ||
msg := "Unable to get change request payload from JSON" | ||
p.API.LogError(msg, "err", err.Error()) | ||
p.handleErrorWithCode(w, http.StatusBadRequest, msg, err) | ||
return | ||
} | ||
|
||
|
@@ -397,15 +437,17 @@ func (p *Plugin) handleChangeAssignment(w http.ResponseWriter, r *http.Request) | |
|
||
receiver, appErr := p.API.GetUserByUsername(changeRequest.SendTo) | ||
if appErr != nil { | ||
p.API.LogError("username not valid, err=" + appErr.Error()) | ||
p.handleErrorWithCode(w, http.StatusNotFound, "Unable to find user", appErr) | ||
msg := "username not valid" | ||
p.API.LogError(msg, "err", err.Error()) | ||
p.handleErrorWithCode(w, http.StatusNotFound, msg, err) | ||
return | ||
} | ||
|
||
issueMessage, oldOwner, err := p.listManager.ChangeAssignment(changeRequest.ID, userID, receiver.Id) | ||
if err != nil { | ||
p.API.LogError("Unable to change the assignment of an issue: err=" + err.Error()) | ||
p.handleErrorWithCode(w, http.StatusInternalServerError, "Unable to change the assignment", err) | ||
msg := "Unable to change the assignment of an issue" | ||
p.API.LogError(msg, "err", err.Error()) | ||
p.handleErrorWithCode(w, http.StatusInternalServerError, msg, err) | ||
return | ||
} | ||
|
||
|
@@ -431,8 +473,9 @@ func (p *Plugin) handleAccept(w http.ResponseWriter, r *http.Request) { | |
|
||
acceptRequest, err := GetAcceptRequestPayloadFromJSON(r.Body) | ||
if err != nil { | ||
p.API.LogError("Unable to get accept request payload from JSON err=" + err.Error()) | ||
p.handleErrorWithCode(w, http.StatusBadRequest, "Unable to get accept request from JSON.", err) | ||
msg := "Unable to get accept request payload from JSON" | ||
p.API.LogError(msg, "err", err.Error()) | ||
p.handleErrorWithCode(w, http.StatusBadRequest, msg, err) | ||
return | ||
} | ||
|
||
|
@@ -443,8 +486,9 @@ func (p *Plugin) handleAccept(w http.ResponseWriter, r *http.Request) { | |
|
||
todoMessage, sender, err := p.listManager.AcceptIssue(userID, acceptRequest.ID) | ||
if err != nil { | ||
p.API.LogError("Unable to accept issue err=" + err.Error()) | ||
p.handleErrorWithCode(w, http.StatusInternalServerError, "Unable to accept issue", err) | ||
msg := "Unable to accept issue" | ||
p.API.LogError(msg, "err", err.Error()) | ||
p.handleErrorWithCode(w, http.StatusInternalServerError, msg, err) | ||
return | ||
} | ||
|
||
|
@@ -463,8 +507,9 @@ func (p *Plugin) handleComplete(w http.ResponseWriter, r *http.Request) { | |
|
||
completeRequest, err := GetCompleteIssuePayloadFromJSON(r.Body) | ||
if err != nil { | ||
p.API.LogError("Unable to get complete issue request payload from JSON err=" + err.Error()) | ||
p.handleErrorWithCode(w, http.StatusBadRequest, "Unable to get complete issue request from JSON.", err) | ||
msg := "Unable to get complete issue request payload from JSON" | ||
p.API.LogError(msg, "err", err.Error()) | ||
p.handleErrorWithCode(w, http.StatusBadRequest, msg, err) | ||
return | ||
} | ||
|
||
|
@@ -475,8 +520,9 @@ func (p *Plugin) handleComplete(w http.ResponseWriter, r *http.Request) { | |
|
||
issue, foreignID, listToUpdate, err := p.listManager.CompleteIssue(userID, completeRequest.ID) | ||
if err != nil { | ||
p.API.LogError("Unable to complete issue err=" + err.Error()) | ||
p.handleErrorWithCode(w, http.StatusInternalServerError, "Unable to complete issue", err) | ||
msg := "Unable to complete issue" | ||
p.API.LogError(msg, "err", err.Error()) | ||
p.handleErrorWithCode(w, http.StatusInternalServerError, msg, err) | ||
return | ||
} | ||
|
||
|
@@ -503,8 +549,9 @@ func (p *Plugin) handleRemove(w http.ResponseWriter, r *http.Request) { | |
|
||
removeRequest, err := GetRemoveIssuePayloadFromJSON(r.Body) | ||
if err != nil { | ||
p.API.LogError("Unable to get remove issue request payload from JSON err=" + err.Error()) | ||
p.handleErrorWithCode(w, http.StatusBadRequest, "Unable to get remove issue request from JSON.", err) | ||
msg := "Unable to get remove issue request payload from JSON" | ||
p.API.LogError(msg, "err", err.Error()) | ||
p.handleErrorWithCode(w, http.StatusBadRequest, msg, err) | ||
return | ||
} | ||
|
||
|
@@ -515,8 +562,9 @@ func (p *Plugin) handleRemove(w http.ResponseWriter, r *http.Request) { | |
|
||
issue, foreignID, isSender, listToUpdate, err := p.listManager.RemoveIssue(userID, removeRequest.ID) | ||
if err != nil { | ||
p.API.LogError("Unable to remove issue, err=" + err.Error()) | ||
p.handleErrorWithCode(w, http.StatusInternalServerError, "Unable to remove issue", err) | ||
msg := "Unable to remove issue" | ||
p.API.LogError(msg, "err", err.Error()) | ||
p.handleErrorWithCode(w, http.StatusInternalServerError, msg, err) | ||
return | ||
} | ||
p.sendRefreshEvent(userID, []string{listToUpdate}) | ||
|
@@ -549,8 +597,9 @@ func (p *Plugin) handleBump(w http.ResponseWriter, r *http.Request) { | |
|
||
bumpRequest, err := GetBumpIssuePayloadFromJSON(r.Body) | ||
if err != nil { | ||
p.API.LogError("Unable to get bump issue request payload from JSON err=" + err.Error()) | ||
p.handleErrorWithCode(w, http.StatusBadRequest, "Unable to get bump issue request from JSON.", err) | ||
msg := "Unable to get bump issue request payload from JSON" | ||
p.API.LogError(msg, "err", err.Error()) | ||
p.handleErrorWithCode(w, http.StatusBadRequest, msg, err) | ||
return | ||
} | ||
|
||
|
@@ -561,8 +610,9 @@ func (p *Plugin) handleBump(w http.ResponseWriter, r *http.Request) { | |
|
||
todoMessage, foreignUser, foreignIssueID, err := p.listManager.BumpIssue(userID, bumpRequest.ID) | ||
if err != nil { | ||
p.API.LogError("Unable to bump issue, err=" + err.Error()) | ||
p.handleErrorWithCode(w, http.StatusInternalServerError, "Unable to bump issue", err) | ||
msg := "Unable to bump issue" | ||
p.API.LogError(msg, "err", err.Error()) | ||
p.handleErrorWithCode(w, http.StatusInternalServerError, msg, err) | ||
return | ||
} | ||
|
||
|
@@ -596,8 +646,9 @@ func (p *Plugin) handleConfig(w http.ResponseWriter, r *http.Request) { | |
|
||
configJSON, err := json.Marshal(clientConfig) | ||
if err != nil { | ||
p.API.LogError("Unable to marshal plugin configuration to json err=" + err.Error()) | ||
p.handleErrorWithCode(w, http.StatusInternalServerError, "Unable to marshal plugin configuration to json", err) | ||
msg := "Unable to marshal plugin configuration to json" | ||
p.API.LogError(msg, "err", err.Error()) | ||
p.handleErrorWithCode(w, http.StatusInternalServerError, msg, err) | ||
return | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,8 @@ export const REMOVE_ASSIGNEE = pluginId + '_remove_assignee'; | |
export const GET_ISSUES = pluginId + '_get_issues'; | ||
export const GET_OUT_ISSUES = pluginId + '_get_out_issues'; | ||
export const GET_IN_ISSUES = pluginId + '_get_in_issues'; | ||
export const GET_COUNT_ISSUES = pluginId + '_get_count_issues'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will also be removed There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
export const GET_ALL_ISSUES = pluginId + '_get_all_issues'; | ||
export const RECEIVED_SHOW_RHS_ACTION = pluginId + '_show_rhs'; | ||
export const UPDATE_RHS_STATE = pluginId + '_update_rhs_state'; | ||
export const SET_RHS_VISIBLE = pluginId + '_set_rhs_visible'; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't used anywhere anymore so we should remove this type definition