From ac140b34276bef2d4c14fb6866544c4ed33cc0d8 Mon Sep 17 00:00:00 2001 From: Sergiusz Bazanski Date: Wed, 1 May 2019 17:11:47 +0200 Subject: [PATCH] go/svc/invoice: statusz cleanups - Remove internal ID - Sort by time --- go/svc/invoice/statusz.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/go/svc/invoice/statusz.go b/go/svc/invoice/statusz.go index f0762994..525d61ee 100644 --- a/go/svc/invoice/statusz.go +++ b/go/svc/invoice/statusz.go @@ -4,6 +4,8 @@ import ( "context" "fmt" "net/http" + "sort" + "time" "code.hackerspace.pl/hscloud/go/mirko" "code.hackerspace.pl/hscloud/go/statusz" @@ -31,8 +33,8 @@ const invoicesFragment = ` {{ .Msg }} - + @@ -43,8 +45,8 @@ const invoicesFragment = ` {{ else }} {{ end }} - +
Internal ID NumberCreated/Issued Customer Amount (net) Actions
{{ .Uid }} {{ .FinalUid }}{{ .DatePretty.Format "2006/01/02 15:04:05" }} {{ index .Data.CustomerBilling 0 }} {{ .TotalNetPretty }} @@ -59,6 +61,7 @@ const invoicesFragment = ` type templateInvoice struct { *pb.Invoice TotalNetPretty string + DatePretty time.Time } func (s *service) setupStatusz(m *mirko.Mirko) { @@ -73,6 +76,7 @@ func (s *service) setupStatusz(m *mirko.Mirko) { res.Invoices[i] = templateInvoice{ Invoice: inv, TotalNetPretty: fmt.Sprintf("%.2f %s", float64(inv.TotalNet)/100, inv.Unit), + DatePretty: time.Unix(0, inv.Date), } } @@ -80,6 +84,8 @@ func (s *service) setupStatusz(m *mirko.Mirko) { glog.Errorf("Could not get invoices for statusz: %v", err) res.Msg = fmt.Sprintf("Could not get invoices: %v", err) } + + sort.Slice(res.Invoices, func(i, j int) bool { return res.Invoices[i].Date > res.Invoices[j].Date }) return res })