Skip to content

Commit

Permalink
Initial version of API.CreateProject().
Browse files Browse the repository at this point in the history
  • Loading branch information
adlio committed Aug 23, 2017
1 parent 451b625 commit c31e53c
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 20 deletions.
50 changes: 30 additions & 20 deletions project.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,35 +5,39 @@ import (
"time"
)

type ProjectRequest struct {
Project *Project `json:"project"`
}

type ProjectResponse struct {
Project *Project `json:"project"`
}

type Project struct {
ID int64 `json:"id"`
ClientID int64 `json:"client_id"`
Name string `json:"name"`
Code string `json:"code"`
ID int64 `json:"id,omitempty"`
ClientID int64 `json:"client_id,omitempty"`
Name string `json:"name,omitempty"`
Code string `json:"code,omitempty"`
Active bool `json:"active"`
Billable bool `json:"billable"`
BillBy string `json:"bill_by"`
HourlyRate *float64 `json:"hourly_rate"`
BudgetBy string `json:"budget_by"`
Budget *float64 `json:"budget"`
BillBy string `json:"bill_by,omitempty"`
HourlyRate *float64 `json:"hourly_rate,omitempty"`
BudgetBy string `json:"budget_by,omitempty"`
Budget *float64 `json:"budget,omitempty"`
NotifyWhenOverBudget bool `json:"notify_when_over_budget"`
OverBudgetNotificationPercentage float64 `json:"over_budget_notification_percentage"`
OverBudgetNotifiedAt *Date `json:"over_budget_notified_at"`
OverBudgetNotificationPercentage float64 `json:"over_budget_notification_percentage,omitempty"`
OverBudgetNotifiedAt *Date `json:"over_budget_notified_at,omitempty"`
ShowBudgetToAll bool `json:"show_budget_to_all"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
StartsOn Date `json:"starts_on"`
EndsOn Date `json:"ends_on"`
Estimate *float64 `json:"estimate"`
EstimateBy string `json:"estimate_by"`
HintEarliestRecordAt Date `json:"hint_earliest_record_at"`
HintLatestRecordAt Date `json:"hint_latest_record_at"`
Notes string `json:"notes"`
CostBudget *float64 `json:"cost_budget"`
CreatedAt time.Time `json:"created_at,omitempty"`
UpdatedAt time.Time `json:"updated_at,omitempty"`
StartsOn Date `json:"starts_on,omitempty"`
EndsOn Date `json:"ends_on,omitempty"`
Estimate *float64 `json:"estimate,omitempty"`
EstimateBy string `json:"estimate_by,omitempty"`
HintEarliestRecordAt Date `json:"hint_earliest_record_at,omitempty"`
HintLatestRecordAt Date `json:"hint_latest_record_at,omitempty"`
Notes string `json:"notes,omitempty"`
CostBudget *float64 `json:"cost_budget,omitempty"`
CostBudgetIncludeExpenses bool `json:"cost_budget_include_expenses"`
}

Expand All @@ -54,3 +58,9 @@ func (a *API) GetProjects(args Arguments) (projects []*Project, err error) {
}
return projects, err
}

func (a *API) CreateProject(p *Project, args Arguments) error {
projectRequest := ProjectRequest{Project: p}
response := ""
return a.Post("/projects", args, &projectRequest, &response)
}
17 changes: 17 additions & 0 deletions project_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,3 +112,20 @@ func TestGetProjectWithStartEndDates(t *testing.T) {
t.Errorf("Expected '120.00', got '%0.2f'", *project.HourlyRate)
}
}

func TestCreateProject(t *testing.T) {
a := testAPI()
emptyResponse := mockResponse("common/empty")
a.BaseURL = emptyResponse.URL

p := Project{
Name: "New Name",
Active: true,
ClientID: 12345,
}

err := a.CreateProject(&p, Defaults())
if err != nil {
t.Fatal(err)
}
}

0 comments on commit c31e53c

Please sign in to comment.