Rename mustGetInvoiceEntries to mustCollectInvoiceEntries
I have seen that pgx has the CollectRows function to do the same job as that function. I can not use CollectRows because it uses generics and requires Go 1.18, but i have adopted the same nomenclature they use.
This commit is contained in:
parent
e94e3f6ebc
commit
989c1717e5
|
@ -28,23 +28,19 @@ type InvoicesIndexPage struct {
|
||||||
|
|
||||||
func IndexInvoices(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
|
func IndexInvoices(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
|
||||||
page := &InvoicesIndexPage{
|
page := &InvoicesIndexPage{
|
||||||
Invoices: mustGetInvoiceEntries(r.Context(), getConn(r), mustGetCompany(r), getLocale(r)),
|
Invoices: mustCollectInvoiceEntries(r.Context(), getConn(r), mustGetCompany(r), getLocale(r)),
|
||||||
}
|
}
|
||||||
mustRenderAppTemplate(w, r, "invoices/index.gohtml", page)
|
mustRenderAppTemplate(w, r, "invoices/index.gohtml", page)
|
||||||
}
|
}
|
||||||
|
|
||||||
func mustGetInvoiceEntries(ctx context.Context, conn *Conn, company *Company, locale *Locale) []*InvoiceEntry {
|
func mustCollectInvoiceEntries(ctx context.Context, conn *Conn, company *Company, locale *Locale) []*InvoiceEntry {
|
||||||
rows, err := conn.Query(ctx, "select invoice.slug, invoice_date, invoice_number, contact.business_name, contact.slug, invoice.invoice_status, isi18n.name from invoice join contact using (contact_id) join invoice_status_i18n isi18n on invoice.invoice_status = isi18n.invoice_status and isi18n.lang_tag = $2 where invoice.company_id = $1 order by invoice_date, invoice_number", company.Id, locale.Language.String())
|
rows := conn.MustQuery(ctx, "select invoice.slug, invoice_date, invoice_number, contact.business_name, contact.slug, invoice.invoice_status, isi18n.name from invoice join contact using (contact_id) join invoice_status_i18n isi18n on invoice.invoice_status = isi18n.invoice_status and isi18n.lang_tag = $2 where invoice.company_id = $1 order by invoice_date, invoice_number", company.Id, locale.Language.String())
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
defer rows.Close()
|
defer rows.Close()
|
||||||
|
|
||||||
var entries []*InvoiceEntry
|
var entries []*InvoiceEntry
|
||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
entry := &InvoiceEntry{}
|
entry := &InvoiceEntry{}
|
||||||
err = rows.Scan(&entry.Slug, &entry.Date, &entry.Number, &entry.CustomerName, &entry.CustomerSlug, &entry.Status, &entry.StatusLabel)
|
if err := rows.Scan(&entry.Slug, &entry.Date, &entry.Number, &entry.CustomerName, &entry.CustomerSlug, &entry.Status, &entry.StatusLabel); err != nil {
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
entries = append(entries, entry)
|
entries = append(entries, entry)
|
||||||
|
|
Loading…
Reference in New Issue