Skip to content

Commit

Permalink
move AppResume to types
Browse files Browse the repository at this point in the history
  • Loading branch information
wpjunior committed Apr 9, 2024
1 parent 00d13da commit afc8a81
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 22 deletions.
25 changes: 3 additions & 22 deletions api/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,34 +181,15 @@ func appDelete(w http.ResponseWriter, r *http.Request, t auth.Token) (err error)
return app.Delete(ctx, &a, evt, requestIDHeader(r))
}

// miniApp is a minimal representation of the app, created to make appList
// faster and transmit less data.
type miniApp struct {
Name string `json:"name"`
Pool string `json:"pool"`
TeamOwner string `json:"teamowner"`
Plan appTypes.Plan `json:"plan"`
Units []provTypes.Unit `json:"units"`
CName []string `json:"cname"`
IP string `json:"ip"`
Routers []appTypes.AppRouter `json:"routers"`
Lock appTypes.AppLock `json:"lock"`
Tags []string `json:"tags"`
Error string `json:"error,omitempty"`
Platform string `json:"platform,omitempty"`
Description string `json:"description,omitempty"`
Metadata appTypes.Metadata `json:"metadata,omitempty"`
}

func minifyApp(app app.App, unitData app.AppUnitsResponse, extended bool) (miniApp, error) {
func minifyApp(app app.App, unitData app.AppUnitsResponse, extended bool) (appTypes.AppResume, error) {
var errorStr string
if unitData.Err != nil {
errorStr = unitData.Err.Error()
}
if unitData.Units == nil {
unitData.Units = []provTypes.Unit{}
}
ma := miniApp{
ma := appTypes.AppResume{
Name: app.Name,
Pool: app.Pool,
Plan: app.Plan,
Expand Down Expand Up @@ -306,7 +287,7 @@ func appList(w http.ResponseWriter, r *http.Request, t auth.Token) error {
simple, _ := strconv.ParseBool(r.URL.Query().Get("simplified"))
extended, _ := strconv.ParseBool(r.URL.Query().Get("extended"))
w.Header().Set("Content-Type", "application/json")
miniApps := make([]miniApp, len(apps))
miniApps := make([]appTypes.AppResume, len(apps))
if simple {
for i, ap := range apps {
ur := app.AppUnitsResponse{Units: nil, Err: nil}
Expand Down
19 changes: 19 additions & 0 deletions types/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,22 @@ type AppInternalAddress struct {
Version string
Process string
}

// AppResume is a minimal representation of the app, created to make appList
// faster and transmit less data.
type AppResume struct {
Name string `json:"name"`
Pool string `json:"pool"`
TeamOwner string `json:"teamowner"`
Plan Plan `json:"plan"`
Units []provision.Unit `json:"units"`
CName []string `json:"cname"`
IP string `json:"ip"`
Routers []AppRouter `json:"routers"`
Lock AppLock `json:"lock"`
Tags []string `json:"tags"`
Error string `json:"error,omitempty"`
Platform string `json:"platform,omitempty"`
Description string `json:"description,omitempty"`
Metadata Metadata `json:"metadata,omitempty"`
}

0 comments on commit afc8a81

Please sign in to comment.