|
|
@ -5,6 +5,7 @@ import ( |
|
|
"log" |
|
|
"log" |
|
|
"marmic/servicetrade-toolbox/internal/api" |
|
|
"marmic/servicetrade-toolbox/internal/api" |
|
|
"net/http" |
|
|
"net/http" |
|
|
|
|
|
"strings" |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
func InvoicesHandler(w http.ResponseWriter, r *http.Request) { |
|
|
func InvoicesHandler(w http.ResponseWriter, r *http.Request) { |
|
|
@ -30,14 +31,15 @@ func InvoicesHandler(w http.ResponseWriter, r *http.Request) { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func handleInvoiceSearch(w http.ResponseWriter, r *http.Request, session *api.Session) { |
|
|
func handleInvoiceSearch(w http.ResponseWriter, r *http.Request, session *api.Session) { |
|
|
invoiceIdentifier := r.URL.Query().Get("search") |
|
|
searchTerm := strings.TrimSpace(r.URL.Query().Get("search")) |
|
|
|
|
|
|
|
|
if invoiceIdentifier == "" { |
|
|
if searchTerm == "" { |
|
|
w.Write([]byte("")) |
|
|
log.Println("Empty search term, returning empty response") |
|
|
|
|
|
w.WriteHeader(http.StatusOK) |
|
|
return |
|
|
return |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
invoice, err := session.GetInvoice(invoiceIdentifier) |
|
|
invoice, err := session.GetInvoice(searchTerm) |
|
|
if err != nil { |
|
|
if err != nil { |
|
|
log.Printf("Error fetching invoice: %v", err) |
|
|
log.Printf("Error fetching invoice: %v", err) |
|
|
w.WriteHeader(http.StatusInternalServerError) |
|
|
w.WriteHeader(http.StatusInternalServerError) |
|
|
|