Skip to content

Commit

Permalink
Fix for new schema changes (#253)
Browse files Browse the repository at this point in the history
* get-project:fix for new schema

Signed-off-by: shivam <[email protected]>

* remove comments and unnecessary code

Signed-off-by: shivam <[email protected]>

* gofmt fix

Signed-off-by: shivam <[email protected]>

---------

Signed-off-by: shivam <[email protected]>
  • Loading branch information
shivam-Purohit committed Sep 10, 2024
1 parent 327ffaa commit 5b4f3cd
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
13 changes: 8 additions & 5 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,14 +107,14 @@ 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 {
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 5b4f3cd

Please sign in to comment.