From c31e53c2cb79a35957ca53bcd5b77dcafd0567f3 Mon Sep 17 00:00:00 2001 From: Aaron Longwell Date: Wed, 23 Aug 2017 14:17:27 -0700 Subject: [PATCH] Initial version of API.CreateProject(). --- project.go | 50 +++++++++++++++++++++++++++++-------------------- project_test.go | 17 +++++++++++++++++ 2 files changed, 47 insertions(+), 20 deletions(-) diff --git a/project.go b/project.go index e6b9656..00b0c13 100644 --- a/project.go +++ b/project.go @@ -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"` } @@ -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) +} diff --git a/project_test.go b/project_test.go index f31b9c8..a4965ce 100644 --- a/project_test.go +++ b/project_test.go @@ -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) + } +}