Skip to content

Commit

Permalink
Change code after code review
Browse files Browse the repository at this point in the history
  • Loading branch information
SoeunSona committed Dec 14, 2023
1 parent c850433 commit 9df4dde
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 33 deletions.
2 changes: 1 addition & 1 deletion customer_notes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func TestListNotes(t *testing.T) {
tested := &API{
ApiKey: "token",
}
params := &ListNotesParams{PaginationWithCursor: PaginationWithCursor{PerPage: 1}, CustomerUUID: "cus_00000000-0000-0000-0000-000000000000"}
params := &ListNotesParams{Cursor: Cursor{PerPage: 1}, CustomerUUID: "cus_00000000-0000-0000-0000-000000000000"}
customer_notes, err := tested.ListNotes(params)

if err != nil {
Expand Down
11 changes: 7 additions & 4 deletions customers.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,6 @@ const (
searchCustomersEndpoint = "customers/search"
mergeCustomersEndpoint = "customers/merges"
customerContactsEndpoint = "customers/:uuid/contacts"
customerNotesEndpoin = "customer_notes"
)

// CreateCustomer loads the customer to Chartmogul. New endpoint - with attributes.
Expand Down Expand Up @@ -265,17 +264,21 @@ func (api API) ListCustomerNotes(listCustomerNotesParams *ListNotesParams, custo
result := &Notes{}
query := make([]interface{}, 0, 1)
if listCustomerNotesParams != nil {
if listCustomerNotesParams.CustomerUUID == "" {
listCustomerNotesParams.CustomerUUID = customerUUID
}
query = append(query, *listCustomerNotesParams)
}
path := customerNotesEndpoint + "?customer_uuid=" + customerUUID
return result, api.list(path, result, query...)
return result, api.list(customerNotesEndpoint, result, query...)
}

// CreateCustomerNote
//
// See https://dev.chartmogul.com/reference/create-a-customer-note
func (api API) CreateCustomerNote(input *NewNote, customerUUID string) (*Note, error) {
result := &Note{}
input.CustomerUUID = customerUUID
if input.CustomerUUID == "" {
input.CustomerUUID = customerUUID
}
return result, api.create(customerNotesEndpoint, input, result)
}
2 changes: 1 addition & 1 deletion customers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ func TestListCustomerNotes(t *testing.T) {
ApiKey: "token",
}
uuid := "cus_00000000-0000-0000-0000-000000000000"
params := &ListNotesParams{PaginationWithCursor: PaginationWithCursor{PerPage: 1}}
params := &ListNotesParams{Cursor: Cursor{PerPage: 1}}
customer_notes, err := tested.ListCustomerNotes(params, uuid)

if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions integration_tests/customer_notes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func TestCustomerNotesIntegration(t *testing.T) {
}
allNotes, err := api.ListNotes(&cm.ListNotesParams{

Check failure on line 58 in integration_tests/customer_notes_test.go

View workflow job for this annotation

GitHub Actions / test (1.16)

api.ListNotes undefined (type *"github.com/chartmogul/chartmogul-go/v3".API has no field or method ListNotes)

Check failure on line 58 in integration_tests/customer_notes_test.go

View workflow job for this annotation

GitHub Actions / test (1.16)

undefined: "github.com/chartmogul/chartmogul-go/v3".ListNotesParams

Check failure on line 58 in integration_tests/customer_notes_test.go

View workflow job for this annotation

GitHub Actions / test (1.14)

api.ListNotes undefined (type *"github.com/chartmogul/chartmogul-go/v3".API has no field or method ListNotes)

Check failure on line 58 in integration_tests/customer_notes_test.go

View workflow job for this annotation

GitHub Actions / test (1.14)

undefined: "github.com/chartmogul/chartmogul-go/v3".ListNotesParams

Check failure on line 58 in integration_tests/customer_notes_test.go

View workflow job for this annotation

GitHub Actions / test (1.13)

api.ListNotes undefined (type *"github.com/chartmogul/chartmogul-go/v3".API has no field or method ListNotes)

Check failure on line 58 in integration_tests/customer_notes_test.go

View workflow job for this annotation

GitHub Actions / test (1.13)

undefined: "github.com/chartmogul/chartmogul-go/v3".ListNotesParams

Check failure on line 58 in integration_tests/customer_notes_test.go

View workflow job for this annotation

GitHub Actions / test (1.19)

api.ListNotes undefined (type *"github.com/chartmogul/chartmogul-go/v3".API has no field or method ListNotes)

Check failure on line 58 in integration_tests/customer_notes_test.go

View workflow job for this annotation

GitHub Actions / test (1.19)

undefined: chartmogul.ListNotesParams

Check failure on line 58 in integration_tests/customer_notes_test.go

View workflow job for this annotation

GitHub Actions / test (1.12)

api.ListNotes undefined (type *"github.com/chartmogul/chartmogul-go/v3".API has no field or method ListNotes)

Check failure on line 58 in integration_tests/customer_notes_test.go

View workflow job for this annotation

GitHub Actions / test (1.12)

undefined: "github.com/chartmogul/chartmogul-go/v3".ListNotesParams

Check failure on line 58 in integration_tests/customer_notes_test.go

View workflow job for this annotation

GitHub Actions / test (1.18)

api.ListNotes undefined (type *"github.com/chartmogul/chartmogul-go/v3".API has no field or method ListNotes)

Check failure on line 58 in integration_tests/customer_notes_test.go

View workflow job for this annotation

GitHub Actions / test (1.18)

undefined: chartmogul.ListNotesParams

Check failure on line 58 in integration_tests/customer_notes_test.go

View workflow job for this annotation

GitHub Actions / test (1.17)

api.ListNotes undefined (type *"github.com/chartmogul/chartmogul-go/v3".API has no field or method ListNotes)

Check failure on line 58 in integration_tests/customer_notes_test.go

View workflow job for this annotation

GitHub Actions / test (1.17)

undefined: "github.com/chartmogul/chartmogul-go/v3".ListNotesParams

Check failure on line 58 in integration_tests/customer_notes_test.go

View workflow job for this annotation

GitHub Actions / test (1.11)

api.ListNotes undefined (type *"github.com/chartmogul/chartmogul-go/v3".API has no field or method ListNotes)

Check failure on line 58 in integration_tests/customer_notes_test.go

View workflow job for this annotation

GitHub Actions / test (1.11)

undefined: "github.com/chartmogul/chartmogul-go/v3".ListNotesParams
CustomerUUID: cus1.UUID,
PaginationWithCursor: cm.PaginationWithCursor{PerPage: 10},
Cursor: cm.Cursor{PerPage: 10},
})
if err != nil {
t.Fatal(err)
Expand All @@ -72,7 +72,7 @@ func TestCustomerNotesIntegration(t *testing.T) {
if !reflect.DeepEqual(expectedAllNotes, expectedAllNotes) {
spew.Dump(allNotes)
spew.Dump(expectedAllNotes)
t.Fatal("All notes is not equal!")
t.Fatal("All notes are not equal!")
}

retrievedNote, err := api.RetrieveNote(newNote.UUID)

Check failure on line 78 in integration_tests/customer_notes_test.go

View workflow job for this annotation

GitHub Actions / test (1.16)

api.RetrieveNote undefined (type *"github.com/chartmogul/chartmogul-go/v3".API has no field or method RetrieveNote)

Check failure on line 78 in integration_tests/customer_notes_test.go

View workflow job for this annotation

GitHub Actions / test (1.14)

api.RetrieveNote undefined (type *"github.com/chartmogul/chartmogul-go/v3".API has no field or method RetrieveNote)

Check failure on line 78 in integration_tests/customer_notes_test.go

View workflow job for this annotation

GitHub Actions / test (1.13)

api.RetrieveNote undefined (type *"github.com/chartmogul/chartmogul-go/v3".API has no field or method RetrieveNote)

Check failure on line 78 in integration_tests/customer_notes_test.go

View workflow job for this annotation

GitHub Actions / test (1.19)

api.RetrieveNote undefined (type *"github.com/chartmogul/chartmogul-go/v3".API has no field or method RetrieveNote)

Check failure on line 78 in integration_tests/customer_notes_test.go

View workflow job for this annotation

GitHub Actions / test (1.12)

api.RetrieveNote undefined (type *"github.com/chartmogul/chartmogul-go/v3".API has no field or method RetrieveNote)

Check failure on line 78 in integration_tests/customer_notes_test.go

View workflow job for this annotation

GitHub Actions / test (1.18)

api.RetrieveNote undefined (type *"github.com/chartmogul/chartmogul-go/v3".API has no field or method RetrieveNote)

Check failure on line 78 in integration_tests/customer_notes_test.go

View workflow job for this annotation

GitHub Actions / test (1.17)

api.RetrieveNote undefined (type *"github.com/chartmogul/chartmogul-go/v3".API has no field or method RetrieveNote)

Check failure on line 78 in integration_tests/customer_notes_test.go

View workflow job for this annotation

GitHub Actions / test (1.11)

api.RetrieveNote undefined (type *"github.com/chartmogul/chartmogul-go/v3".API has no field or method RetrieveNote)
Expand Down
49 changes: 24 additions & 25 deletions notes.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,51 +2,50 @@ package chartmogul

// Note is the customer note as represented in the API.
type Note struct {
UUID string `json:"uuid,omitempty"`
UUID string `json:"uuid"`
// Basic info
CustomerUUID string `json:"customer_uuid,omitempty"`
Type string `json:"type,omitempty"`
Text string `json:"text,omitempty"`
Author string `json:"author,omitempty"`
CallDuration uint32 `json:"call_duration,omitempty"`
CreatedAt string `json:"created_at,omitempty"`
UpdatedAt string `json:"updated_at,omitempty"`
CustomerUUID string `json:"customer_uuid"`
Type string `json:"type"`
Text string `json:"text"`
Author string `json:"author"`
CallDuration uint32 `json:"call_duration"`
CreatedAt string `json:"created_at"`
UpdatedAt string `json:"updated_at"`
}

// UpdateNote allows updating note on the update endpoint.
type UpdateNote struct {
Text string `json:"text,omitempty"`
AuthorEmail string `json:"author_email,omitempty"`
CallDuration uint32 `json:"call_duration,omitempty"`
CreatedAt string `json:"create_at,omitempty"`
UpdatedAt string `json:"updated_at,omitempty"`
Text string `json:"text"`
AuthorEmail string `json:"author_email"`
CallDuration uint32 `json:"call_duration"`
CreatedAt string `json:"create_at"`
UpdatedAt string `json:"updated_at"`
}

// NewNote allows creating note on a new endpoint.
type NewNote struct {
// Obligatory
CustomerUUID string `json:"customer_uuid,omitempty"`
Type string `json:"type,omitempty"`
CustomerUUID string `json:"customer_uuid"`
Type string `json:"type"`

//Optional
AuthorEmail string `json:"author_email,omitempty"`
Text string `json:"text,omitempty"`
CallDuration uint32 `json:"call_duration,omitempty"`
CreatedAt string `json:"created_at,omitempty"`
UpdatedAt string `json:"updated_at,omitempty"`
AuthorEmail string `json:"author_email"`
Text string `json:"text"`
CallDuration uint32 `json:"call_duration"`
CreatedAt string `json:"created_at"`
UpdatedAt string `json:"updated_at"`
}

// ListNoteParams = parameters for listing customer notes in API.
type ListNotesParams struct {
CustomerUUID string `json:"customer_uuid,omitempty"`
PaginationWithCursor
CustomerUUID string `json:"customer_uuid"`
Cursor
}

// Notes is result of listing customer notes in API.
type Notes struct {
Entries []*Note `json:"entries,omitempty"`
Cursor string `json:"cursor,omitempty"`
HasMore bool `json:"has_more,omitempty"`
Entries []*Note `json:"entries"`
Pagination
}

const (
Expand Down

0 comments on commit 9df4dde

Please sign in to comment.