diff --git a/pkg/apis/project.go b/pkg/apis/project.go index 58b85ee..de1f838 100644 --- a/pkg/apis/project.go +++ b/pkg/apis/project.go @@ -82,10 +82,13 @@ func CreateProjectRequest(projectName string, cred types.Credentials) (CreatePro } type listProjectResponse struct { - Data []struct { - ID string `json:"ProjectID"` - Name string `json:"Name"` - CreatedAt int64 `json:"CreatedAt"` + Data struct { + Projects []struct { + ID string `json:"projectID"` // Adjusted field name + Name string `json:"name"` + CreatedAt int64 `json:"createdAt"` + } `json:"projects"` + TotalNumberOfProjects int `json:"totalNumberOfProjects"` } `json:"data"` Errors []struct { Message string `json:"message"` @@ -104,7 +107,6 @@ func ListProject(cred types.Credentials) (listProjectResponse, error) { if err != nil { return listProjectResponse{}, err } - defer resp.Body.Close() if resp.StatusCode == http.StatusOK { @@ -112,6 +114,7 @@ func ListProject(cred types.Credentials) (listProjectResponse, error) { err = json.Unmarshal(bodyBytes, &data) if err != nil { return listProjectResponse{}, err + } if len(data.Errors) > 0 { diff --git a/pkg/cmd/get/projects.go b/pkg/cmd/get/projects.go index 6f98353..ecd528a 100644 --- a/pkg/cmd/get/projects.go +++ b/pkg/cmd/get/projects.go @@ -45,12 +45,12 @@ var projectsCmd = &cobra.Command{ utils.PrintInJsonFormat(projects.Data) case "yaml": - utils.PrintInYamlFormat(projects.Data) + utils.PrintInYamlFormat(projects.Data.Projects) case "": itemsPerPage := 5 page := 1 - totalProjects := len(projects.Data) + totalProjects := len(projects.Data.Projects) for { // calculating the start and end indices for the current page @@ -69,9 +69,9 @@ var projectsCmd = &cobra.Command{ // displaying the projects for the current page writer := tabwriter.NewWriter(os.Stdout, 8, 8, 8, '\t', tabwriter.AlignRight) utils.White_B.Fprintln(writer, "PROJECT ID\tPROJECT NAME\tCREATED AT") - for _, project := range projects.Data[start:end] { + for _, project := range projects.Data.Projects[start:end] { intTime := project.CreatedAt - humanTime := time.Unix(intTime, 0) + humanTime := time.Unix(intTime/1000, 0) // Convert milliseconds to second utils.White.Fprintln(writer, project.ID+"\t"+project.Name+"\t"+humanTime.String()+"\t") } writer.Flush()