Skip to content
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

[MI-3218]: Fixed review comments for PR#213 'Add Crud Operations' #2

Merged
merged 1 commit into from
Jun 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions server/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func (h *Handler) setLink(w http.ResponseWriter, r *http.Request) {
found := false
changed := false
for i := range links {
if links[i].Name == newLink.Name || links[i].Pattern == newLink.Pattern {
if links[i].Name == newLink.Name {
if !links[i].Equals(newLink) {
links[i] = newLink
changed = true
Expand Down Expand Up @@ -137,7 +137,7 @@ func (h *Handler) deleteLink(w http.ResponseWriter, r *http.Request) {
links := h.store.GetLinks()
found := false
for i := 0; i < len(links); i++ {
if links[i].Name == autolinkName || links[i].Pattern == autolinkName {
if links[i].Name == autolinkName {
links = append(links[:i], links[i+1:]...)
found = true
}
Expand Down Expand Up @@ -167,14 +167,14 @@ func (h *Handler) getLinks(w http.ResponseWriter, r *http.Request) {
found := false
var autolinks []autolink.Autolink
for _, link := range links {
if link.Name == autolinkName || link.Pattern == autolinkName {
if link.Name == autolinkName {
autolinks = append(autolinks, link)
found = true
}
}

if !found {
h.handleError(w, errors.Errorf("no autolink found with name or pattern %s", autolinkName))
h.handleError(w, errors.Errorf("no autolink found with name %s", autolinkName))
return
}

Expand Down
17 changes: 8 additions & 9 deletions server/autolinkclient/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func (c *Client) Add(links ...autolink.Autolink) error {

if resp.StatusCode != http.StatusOK {
respBody, _ := ioutil.ReadAll(resp.Body)
return fmt.Errorf("unable to install autolink. Error: %v, %v", resp.StatusCode, string(respBody))
return fmt.Errorf("unable to add the link %s. Error: %v, %v", link.Name, resp.StatusCode, string(respBody))
}
}

Expand All @@ -76,7 +76,7 @@ func (c *Client) Delete(links ...string) error {

if resp.StatusCode != http.StatusOK {
respBody, _ := ioutil.ReadAll(resp.Body)
return fmt.Errorf("unable to install autolink. Error: %v, %v", resp.StatusCode, string(respBody))
return fmt.Errorf("unable to delete the link %s. Error: %v, %v", link, resp.StatusCode, string(respBody))
}
}

Expand All @@ -93,13 +93,13 @@ func (c *Client) Get(autolinkName string) ([]*autolink.Autolink, error) {
return nil, err
}

respBody, err := ioutil.ReadAll(resp.Body)
if err != nil {
return nil, err
}

var respBody []byte
if resp.StatusCode != http.StatusOK {
return nil, fmt.Errorf("unable to install autolink. Error: %v, %v", resp.StatusCode, string(respBody))
respBody, err := ioutil.ReadAll(resp.Body)
if err != nil {
return nil, err
}
return nil, fmt.Errorf("unable to get the link %s. Error: %v, %v", autolinkName, resp.StatusCode, string(respBody))
}

var response []*autolink.Autolink
Expand All @@ -122,7 +122,6 @@ func (c *Client) call(url, method string, body []byte, queryParams url.Values) (
if err != nil {
return nil, err
}
defer resp.Body.Close()

return resp, nil
}