Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for new schema changes #253

Merged
merged 3 commits into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions pkg/apis/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand All @@ -104,20 +107,20 @@ 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 {
return listProjectResponse{}, err

}

if len(data.Errors) > 0 {
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
Loading