feat(api): 404 on no siutable issues
This commit is contained in:
@@ -29,13 +29,19 @@ func (s Service) createInvoice(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
invoice, err := s.invoice.Generate(req.Creditor, req.Debtor, time.Duration(req.DurationThreshold), req.HourlyRate, repos)
|
||||
invoice, report, err := s.invoice.Generate(req.Creditor, req.Debtor, time.Duration(req.DurationThreshold), req.HourlyRate, repos)
|
||||
if err != nil {
|
||||
log.Println("error while processing invoice:", err)
|
||||
fmt.Fprint(w, "internal server error")
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
// if no time has to be billed aka if bill for 0 CHF
|
||||
if report.Total() <= time.Duration(0) {
|
||||
s.sendErr(w, http.StatusNotFound, "no suitable issues to be billed")
|
||||
return
|
||||
}
|
||||
|
||||
w.Header().Set("Content-type", "application/pdf")
|
||||
w.Header().Set(
|
||||
"Content-Disposition",
|
||||
@@ -51,7 +57,6 @@ func (s Service) createInvoice(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
func (s Service) sendInvoice(w http.ResponseWriter, r *http.Request) {
|
||||
var req sendReq
|
||||
|
||||
err := json.NewDecoder(r.Body).Decode(&req)
|
||||
if err != nil {
|
||||
s.sendErrf(w, http.StatusBadRequest, "cannot read body: %v", err)
|
||||
@@ -63,11 +68,16 @@ func (s Service) sendInvoice(w http.ResponseWriter, r *http.Request) {
|
||||
s.sendErr(w, 500, err.Error())
|
||||
return
|
||||
}
|
||||
invoice, err := s.invoice.Generate(req.Invoice.Creditor, req.Invoice.Debtor, time.Duration(req.Invoice.DurationThreshold), req.Invoice.HourlyRate, repos)
|
||||
invoice, report, err := s.invoice.Generate(req.Invoice.Creditor, req.Invoice.Debtor, time.Duration(req.Invoice.DurationThreshold), req.Invoice.HourlyRate, repos)
|
||||
if err != nil {
|
||||
s.sendErr(w, http.StatusInternalServerError, "error while processing invoice:", err)
|
||||
return
|
||||
}
|
||||
// if no time has to be billed aka if bill for 0 CHF
|
||||
if report.Total() <= time.Duration(0) {
|
||||
s.sendErr(w, http.StatusNotFound, "no suitable issues to be billed")
|
||||
return
|
||||
}
|
||||
|
||||
invoiceData, err := io.ReadAll(invoice)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user