-
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 2 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) | ||||||||||||
// CountIssues get counter all issues | ||||||||||||
raghavaggarwal2308 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||
CountIssues(userID string) (*CountIssue, 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("/count", p.checkAuth(p.handleCount)).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) | ||||||||||||
|
@@ -340,6 +343,30 @@ func (p *Plugin) handleList(w http.ResponseWriter, r *http.Request) { | |||||||||||
} | ||||||||||||
} | ||||||||||||
|
||||||||||||
func (p *Plugin) handleCount(w http.ResponseWriter, r *http.Request) { | ||||||||||||
userID := r.Header.Get("Mattermost-User-ID") | ||||||||||||
|
||||||||||||
countIssues, err := p.listManager.CountIssues(userID) | ||||||||||||
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) | ||||||||||||
return | ||||||||||||
} | ||||||||||||
|
||||||||||||
countIssuesJSON, err := json.Marshal(countIssues) | ||||||||||||
if err != nil { | ||||||||||||
p.API.LogError("Unable marhsal count issue list to json err=" + err.Error()) | ||||||||||||
p.handleErrorWithCode(w, http.StatusInternalServerError, "Unable marhsal count issue list to json", err) | ||||||||||||
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. Nit: to de-duplicate some string creation here. Same with the block above this one
Suggested change
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. I see now that this is copied from the function above. I'm still thinking we can make this change here 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. I just modified all the error messages the same way 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. @mickmister What are your opinions on moving the log statement inside the "handleErrorWithCode" function instead? 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. @raghavaggarwal2308 That sounds fine but we would want to change every call to |
||||||||||||
return | ||||||||||||
} | ||||||||||||
|
||||||||||||
_, err = w.Write(countIssuesJSON) | ||||||||||||
if err != nil { | ||||||||||||
p.API.LogError("Unable to write json response err=" + err.Error()) | ||||||||||||
} | ||||||||||||
|
||||||||||||
} | ||||||||||||
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. Nit: extra newline at the end of this function and |
||||||||||||
|
||||||||||||
func (p *Plugin) handleEdit(w http.ResponseWriter, r *http.Request) { | ||||||||||||
userID := r.Header.Get("Mattermost-User-ID") | ||||||||||||
|
||||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -327,6 +327,28 @@ func (l *listStore) getList(userID, listID string) ([]*IssueRef, []byte, error) | |
return list, originalJSONList, nil | ||
} | ||
|
||
func (l *listStore) CountIssues(userID string) (*CountIssue, error) { | ||
myList, err := l.GetList(userID, MyListKey) | ||
if err != nil { | ||
return nil, err | ||
} | ||
inList, err := l.GetList(userID, InListKey) | ||
if err != nil { | ||
return nil, err | ||
} | ||
outList, err := l.GetList(userID, OutListKey) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return &CountIssue{ | ||
In: len(inList), | ||
My: len(myList), | ||
Out: len(outList), | ||
}, nil | ||
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. Might as well just return the actual lists right? Then the frontend doesn't need to do any other requests |
||
|
||
} | ||
|
||
func (l *listStore) saveList(userID, listID string, list []*IssueRef, originalJSONList []byte) (bool, error) { | ||
newJSONList, jsonErr := json.Marshal(list) | ||
if jsonErr != nil { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ 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 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'; | ||
|
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -27,6 +27,7 @@ export const getMessage = (state) => { | |||||||||||||
export const getIssues = (state) => getPluginState(state).issues; | ||||||||||||||
export const getInIssues = (state) => getPluginState(state).inIssues; | ||||||||||||||
export const getOutIssues = (state) => getPluginState(state).outIssues; | ||||||||||||||
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. These selectors should probably be doing this now:
Suggested change
|
||||||||||||||
export const getCountIssues = (state) => getPluginState(state).countIssues; | ||||||||||||||
export const getCurrentTeamRoute = (state) => { | ||||||||||||||
const basePath = getSiteURL(state); | ||||||||||||||
const teamName = state.entities.teams.teams[state.entities.teams.currentTeamId].name; | ||||||||||||||
|
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