Skip to content

Commit ad255bd

Browse files
committed
Fix api call and content type
1 parent 5cfcf73 commit ad255bd

File tree

4 files changed

+14
-7
lines changed

4 files changed

+14
-7
lines changed

cli/template/list.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,5 +49,5 @@ func runTemplateListCommand() error {
4949
if err != nil {
5050
return fmt.Errorf("retrieving credentials: %w", err)
5151
}
52-
return template.ListustomTemplate(cred)
52+
return template.ListCustomTemplates(cred)
5353
}

command/template/list.go

+8-3
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,21 @@ import (
2323
storageapi "github.com/arduino/arduino-cloud-cli/internal/storage-api"
2424
)
2525

26-
func ListustomTemplate(cred *config.Credentials) error {
26+
func ListCustomTemplates(cred *config.Credentials) error {
2727

2828
apiclient := storageapi.NewClient(cred)
2929

30-
templates, err := apiclient.ListCustomTemplate()
30+
templates, err := apiclient.ListCustomTemplates()
3131
if err != nil {
3232
return err
3333
}
3434

35-
feedback.PrintResult(templates)
35+
if templates == nil {
36+
feedback.Print("No templates found")
37+
} else {
38+
feedback.PrintResult(templates)
39+
}
40+
3641

3742
return nil
3843
}

internal/storage-api/client.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ func (c *StorageApiClient) performBinaryPostRequest(endpoint, token string, body
131131
return nil, err
132132
}
133133
req.Header.Add("Authorization", "Bearer "+token)
134+
req.Header.Set("Content-Type", "application/json")
134135
if c.organization != "" {
135136
req.Header.Add("X-Organization", c.organization)
136137
}
@@ -294,7 +295,7 @@ type listPostRequest struct {
294295
Sort string `json:"sort"`
295296
}
296297

297-
func (c *StorageApiClient) ListCustomTemplate() (*TemplatesListResponse, error) {
298+
func (c *StorageApiClient) ListCustomTemplates() (*TemplatesListResponse, error) {
298299
userRequestToken, err := c.src.Token()
299300
if err != nil {
300301
if strings.Contains(err.Error(), "401") {

internal/storage-api/dto.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ type (
3333
TemplateId string `json:"template_id"`
3434
Name string `json:"name"`
3535
CreatedAt string `json:"created_at"`
36+
UpdatedAt string `json:"updated_at"`
3637
}
3738
TemplatesListResponse struct {
3839
Templates []TemplateEntry `json:"templates"`
@@ -48,11 +49,11 @@ func (r *TemplatesListResponse) String() string {
4849
return ""
4950
}
5051
t := table.New()
51-
t.SetHeader("Template ID", "Name", "Created At")
52+
t.SetHeader("Template ID", "Name", "Created At", "Updated At")
5253

5354
// Now print the table
5455
for _, tem := range r.Templates {
55-
line := []any{tem.TemplateId, tem.Name, formatHumanReadableTs(tem.CreatedAt)}
56+
line := []any{tem.TemplateId, tem.Name, formatHumanReadableTs(tem.CreatedAt), formatHumanReadableTs(tem.UpdatedAt)}
5657
t.AddRow(line...)
5758
}
5859

0 commit comments

Comments
 (0)