Skip to content

Commit

Permalink
get-project:fix for new schema
Browse files Browse the repository at this point in the history
Signed-off-by: shivam <[email protected]>
  • Loading branch information
shivam-Purohit committed Sep 10, 2024
1 parent 327ffaa commit 93fae02
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 11 deletions.
31 changes: 24 additions & 7 deletions pkg/apis/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,26 @@ 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"`
// } `json:"data"`
// Errors []struct {
// Message string `json:"message"`
// Path []string `json:"path"`
// } `json:"errors"`
// }

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"`
Expand All @@ -104,20 +119,22 @@ func ListProject(cred types.Credentials) (listProjectResponse, error) {
if err != nil {
return listProjectResponse{}, err
}

defer resp.Body.Close()

if resp.StatusCode == http.StatusOK {
var data listProjectResponse
err = json.Unmarshal(bodyBytes, &data)
if err != nil {
utils.Red.Println("here1")
return listProjectResponse{}, err

}

if len(data.Errors) > 0 {
utils.Red.Println("here12")
return listProjectResponse{}, errors.New(data.Errors[0].Message)
}

return data, nil
} else {
return listProjectResponse{}, errors.New("Unmatched status code:" + string(bodyBytes))
Expand Down
8 changes: 4 additions & 4 deletions pkg/cmd/get/projects.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
Expand Down

0 comments on commit 93fae02

Please sign in to comment.