Skip to content

Commit

Permalink
Refactor client
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniils Petrovs committed Jul 8, 2022
1 parent 5740abb commit a4cc156
Showing 1 changed file with 11 additions and 33 deletions.
44 changes: 11 additions & 33 deletions zube/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,7 @@ func (client *Client) FetchCurrentPerson() models.CurrentPerson {

body, err := client.performAPIRequestURLNoBody(http.MethodGet, &url)

if err != nil {
log.Fatal("Failed to fetch current person info!")
}
Check(err, "failed to fetch current person info!")

json.Unmarshal(body, &currentPerson)
return currentPerson
Expand All @@ -159,9 +157,7 @@ func (client *Client) FetchCards(query *Query) []models.Card {
// TODO: Support pagination
body, err := client.performAPIRequestURLNoBody(http.MethodGet, &url)

if err != nil {
log.Fatal("Failed to fetch list of cards")
}
Check(err, "failed to fetch cards!")

json.Unmarshal(body, &response)
return response.Data
Expand All @@ -174,9 +170,7 @@ func (client *Client) FetchCardComments(cardId int) []models.Comment {

body, err := client.performAPIRequestURLNoBody(http.MethodGet, &url)

if err != nil {
log.Fatalf("Failed to fetch comments for card with Id: %d", cardId)
}
Check(err, fmt.Sprintf("failed to fetch comments for card with Id: %d", cardId))

json.Unmarshal(body, &response)
return response.Data
Expand All @@ -188,9 +182,7 @@ func (client *Client) CreateCard(card *models.Card) models.Card {
data, _ := json.Marshal(card)
resp, err := client.performAPIRequestURL(http.MethodPost, &url, bytes.NewBuffer(data))

if err != nil {
log.Fatalf("failed to create card!")
}
Check(err, "failed to create card!")

json.Unmarshal(resp, &respCard)

Expand All @@ -203,9 +195,7 @@ func (client *Client) FetchWorkspaces(query *Query) []models.Workspace {
url := zubeURL("/api/workspaces", *query)
body, err := client.performAPIRequestURLNoBody(http.MethodGet, &url)

if err != nil {
log.Fatal("Failed to fetch list of workspaces")
}
Check(err, "failed to fetch workspaces!")

json.Unmarshal(body, &response)
return response.Data
Expand All @@ -218,9 +208,7 @@ func (client *Client) FetchEpics(projectId int) []models.Epic {
url := zubeURL(fmt.Sprintf("/api/projects/%d/epics", projectId), Query{})
body, err := client.performAPIRequestURLNoBody(http.MethodGet, &url)

if err != nil {
log.Fatalf("Failed to fetch cards for project with Id: %d", projectId)
}
Check(err, fmt.Sprintf("failed to fetch card for project with Id: %d", projectId))

json.Unmarshal(body, &response)
return response.Data
Expand All @@ -234,9 +222,7 @@ func (client *Client) FetchAccounts(query *Query) []models.Account {

body, err := client.performAPIRequestURLNoBody(http.MethodGet, &url)

if err != nil {
log.Fatal("Failed to fetch list of accounts")
}
Check(err, "failed to fetch accounts")

json.Unmarshal(body, &response)
return response.Data
Expand All @@ -263,9 +249,7 @@ func (client *Client) FetchProjects(query *Query) []models.Project {

body, err := client.performAPIRequestURLNoBody(http.MethodGet, &url)

if err != nil {
log.Fatal("Failed to fetch list of projects")
}
Check(err, "failed to fetch projects")

json.Unmarshal(body, &response)
return response.Data
Expand All @@ -279,9 +263,7 @@ func (client *Client) FetchProjectCards(projectId int, query *Query) []models.Ca

body, err := client.performAPIRequestURLNoBody(http.MethodGet, &url)

if err != nil {
log.Fatalf("Failed to fetch cards for project with Id: %d", projectId)
}
Check(err, fmt.Sprintf("failed to fetch cards for project with Id: %d", projectId))

json.Unmarshal(body, &response)
return response.Data
Expand All @@ -294,9 +276,7 @@ func (client *Client) FetchProjectMembers(projectId int) []models.Member {

body, err := client.performAPIRequestURLNoBody(http.MethodGet, &url)

if err != nil {
log.Fatalf("Failed to fetch cards for project with Id: %d", projectId)
}
Check(err, fmt.Sprintf("failed to fetch project members for project with Id: %d", projectId))

json.Unmarshal(body, &response)
return response.Data
Expand All @@ -310,9 +290,7 @@ func (client *Client) FetchLabels(projectId int) []models.Label {

body, err := client.performAPIRequestURLNoBody(http.MethodGet, &url)

if err != nil {
log.Fatalf("Failed to fetch labels for project with Id: %d", projectId)
}
Check(err, fmt.Sprintf("failed to fetch labels for project with Id: %d", projectId))

json.Unmarshal(body, &response)
return response.Data
Expand Down

0 comments on commit a4cc156

Please sign in to comment.