mirror of
https://github.com/rjNemo/rentease.git
synced 2026-06-06 02:36:49 +00:00
refactor
This commit is contained in:
parent
3f6c5b6c99
commit
72d0212316
3 changed files with 12 additions and 7 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -24,5 +24,6 @@ Network Trash Folder
|
|||
Temporary Items
|
||||
.apdisk
|
||||
tmp
|
||||
tmp.pdf
|
||||
.env
|
||||
*templ.txt
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ Manage your holiday rental
|
|||
- [x] Create a booking
|
||||
- [x] Add line items
|
||||
- [x] Read from the database
|
||||
- [ ] Build the pdf invoice
|
||||
- [x] Build the pdf invoice
|
||||
- [ ] Refactor the env variable calls to a Config struct with proper defaults
|
||||
- [ ] Refactor handlers to call their dependencies instead of taking them from the Server struct
|
||||
|
||||
|
|
@ -17,4 +17,4 @@ Manage your holiday rental
|
|||
- Htmx
|
||||
- Templ
|
||||
- PostgreSQL
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ package server
|
|||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
|
|
@ -307,20 +308,24 @@ func (s Server) handleCreateInvoicePdf() echo.HandlerFunc {
|
|||
defer resp.Body.Close()
|
||||
|
||||
log.Warnf("Response Status:", resp.Status)
|
||||
type response struct {
|
||||
res := new(struct {
|
||||
Url string `json:"url"`
|
||||
Error string `json:"error"`
|
||||
}
|
||||
res := new(response)
|
||||
})
|
||||
body, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = json.Unmarshal(body, res)
|
||||
if err != nil {
|
||||
log.Warnf("error decoding response: %s", err)
|
||||
return err
|
||||
}
|
||||
log.Warnf("Response body:", res)
|
||||
|
||||
if res.Error != "" {
|
||||
log.Warnf("error building pdf file %s", err)
|
||||
return errors.New(res.Error)
|
||||
}
|
||||
|
||||
resp, err = http.Get(res.Url)
|
||||
if err != nil {
|
||||
|
|
@ -329,7 +334,6 @@ func (s Server) handleCreateInvoicePdf() echo.HandlerFunc {
|
|||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
// Copy the file content to the response writer
|
||||
file, err := os.Create("tmp.pdf")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
|
|
|
|||
Loading…
Reference in a new issue