Skip to content

Commit

Permalink
Merge pull request #7 from doneill/feature/jdo-24-structure-user-resp…
Browse files Browse the repository at this point in the history
…onse

Structure user response
  • Loading branch information
doneill authored Nov 29, 2023
2 parents 3fed8d0 + 06e0fb8 commit 5338641
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 31 deletions.
28 changes: 7 additions & 21 deletions api/apiuser.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,31 +14,17 @@ import (

type UserResponse struct {
Data struct {
Username string `json:"username"`
Email string `json:"email"`
FirstName string `json:"first_name"`
LastName string `json:"last_name"`
Role string `json:"role"`
IsStaff bool `json:"is_staff"`
IsSuperUser bool `json:"is_superuser"`
DateJoined string `json:"date_joined"`
ID string `json:"id"`
IsActive bool `json:"is_active"`
LastLogin string `json:"last_login"`
Pin string `json:"pin"`
Subject struct {
Username string `json:"username"`
Email string `json:"email"`
FirstName string `json:"first_name"`
LastName string `json:"last_name"`
ID string `json:"id"`
Pin string `json:"pin"`
Subject struct {
ID string `json:"id"`
} `json:"subject"`
Permissions struct {
Patrol []string `json:"patrol"`
MobileTests []string `json:"mobile_tests"`
} `json:"permissions"`
} `json:"data"`
ErrorDescription string `json:"error_description"`
Status struct {
Code int `json:"code"`
Message string `json:"message"`
} `json:"status"`
}

// ----------------------------------------------
Expand Down
21 changes: 11 additions & 10 deletions cmd/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"os"

"github.com/doneill/er-cli-go/api"
"github.com/olekukonko/tablewriter"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -33,23 +34,23 @@ func user() {
}

if userResponse != nil {
formattedResponse := fmt.Sprintf("username: %s\nemail: %s\nfirst name: %s\nlast name: %s\nrole: %s\nis staff: %t\nis superuser: %t\ndate joined: %s\nid: %s\nisactive: %t\nlast login: %s\npin: %s\nsubject id: %s\npermissions:\n patrol: %v\nmobile tests: %v",
data := []string{
userResponse.Data.Username,
userResponse.Data.Email,
userResponse.Data.FirstName,
userResponse.Data.LastName,
userResponse.Data.Role,
userResponse.Data.IsStaff,
userResponse.Data.IsSuperUser,
userResponse.Data.DateJoined,
userResponse.Data.ID,
userResponse.Data.IsActive,
userResponse.Data.LastLogin,
userResponse.Data.Pin,
userResponse.Data.Subject.ID,
userResponse.Data.Permissions.Patrol,
userResponse.Data.Permissions.MobileTests)
fmt.Println(formattedResponse)
}

table := tablewriter.NewWriter(os.Stdout)
table.SetHeader([]string{"Username", "Email", "First Name", "Last Name", "ID", "Pin", "Subject ID"})
table.SetBorders(tablewriter.Border{Left: true, Top: false, Right: true, Bottom: false})
table.SetCenterSeparator("|")
table.Append(data)

table.Render()
}
}

Expand Down
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,15 @@ require (
github.com/spf13/viper v1.17.0
)

require github.com/mattn/go-runewidth v0.0.9 // indirect

require (
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/olekukonko/tablewriter v0.0.5
github.com/pelletier/go-toml/v2 v2.1.0 // indirect
github.com/sagikazarmark/locafero v0.3.0 // indirect
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,12 @@ github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/magiconair/properties v1.8.7 h1:IeQXZAiQcpL9mgcAe1Nu6cX9LLw6ExEHKjN0VQdvPDY=
github.com/magiconair/properties v1.8.7/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0=
github.com/mattn/go-runewidth v0.0.9 h1:Lm995f3rfxdpd6TSmuVCHVb/QhupuXlYr8sCI/QdE+0=
github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY=
github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec=
github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY=
github.com/pelletier/go-toml/v2 v2.1.0 h1:FnwAJ4oYMvbT/34k9zzHuZNrhlz48GB3/s6at6/MHO4=
github.com/pelletier/go-toml/v2 v2.1.0/go.mod h1:tJU2Z3ZkXwnxa4DPO899bsyIoywizdUvyaeZurnPPDc=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
Expand Down

0 comments on commit 5338641

Please sign in to comment.