show newest invoice first, show datetime
All checks were successful
Go / build (push) Successful in 13m34s

This commit is contained in:
2025-07-02 11:09:33 +02:00
parent db3dc9ecd1
commit 249cccd240
3 changed files with 22 additions and 4 deletions

View File

@@ -11,8 +11,11 @@ import (
type InvoiceRepository interface {
Create(models.Invoice) (models.Invoice, error)
GetAll() ([]models.Invoice, error)
GetAllSorted(string) ([]models.Invoice, error)
GetAllNewestFirst() ([]models.Invoice, error)
GetAllNewestLast() ([]models.Invoice, error)
GetById(string) (models.Invoice, error)
//GetByShopItemId(string) (models.Invoice, error)
//GetByInvoiceId(string) (models.Invoice, error)
Update(models.Invoice) (models.Invoice, error)
DeleteById(string) error
}
@@ -44,6 +47,21 @@ func (t *GORMInvoiceRepository) GetAll() ([]models.Invoice, error) {
return invoice, result.Error
}
func (t *GORMInvoiceRepository) GetAllSorted(sortString string) ([]models.Invoice, error) {
var invoices []models.Invoice
result := t.DB.Preload("PrintJobs.ShopItem").Preload("PrintJobs.Variant").Preload("PrintJobs.PaperType").Preload("PrintJobs.CoverPaperType").Preload("PrintJobs").Order(sortString).Find(&invoices)
return invoices, result.Error
}
func (r *GORMInvoiceRepository) GetAllNewestFirst() ([]models.Invoice, error) {
return r.GetAllSorted("created_at desc")
}
func (r *GORMInvoiceRepository) GetAllNewestLast() ([]models.Invoice, error) {
return r.GetAllSorted("created_at asc")
}
func (t *GORMInvoiceRepository) GetById(id string) (models.Invoice, error) {
invoiceId, err := strconv.Atoi(id)