mirror of
https://github.com/rjNemo/rentease.git
synced 2026-06-06 02:36:49 +00:00
time pkg
This commit is contained in:
parent
a971aab58c
commit
5a1a7608f1
2 changed files with 53 additions and 7 deletions
|
|
@ -17,6 +17,7 @@ import (
|
|||
"github.com/rjNemo/rentease/constants"
|
||||
"github.com/rjNemo/rentease/internal/domains/booking"
|
||||
"github.com/rjNemo/rentease/internal/views"
|
||||
myTime "github.com/rjNemo/rentease/pkg/time"
|
||||
)
|
||||
|
||||
func (s Server) handleHomePage() echo.HandlerFunc {
|
||||
|
|
@ -73,9 +74,9 @@ func (s Server) handleCreateBooking() echo.HandlerFunc {
|
|||
return err
|
||||
}
|
||||
|
||||
ts, _ := parseTime(c.FormValue("from"))
|
||||
ts, _ := myTime.ParseFromForm(c.FormValue("from"))
|
||||
nb.From = ts
|
||||
ts, _ = parseTime(c.FormValue("to"))
|
||||
ts, _ = myTime.ParseFromForm(c.FormValue("to"))
|
||||
nb.To = ts
|
||||
|
||||
b := &booking.Booking{
|
||||
|
|
@ -141,10 +142,44 @@ func (s Server) handleCreateItem() echo.HandlerFunc {
|
|||
}
|
||||
}
|
||||
|
||||
func parseTime(src string) (time.Time, error) {
|
||||
ts, err := time.Parse("2006-01-02", src)
|
||||
if err != nil {
|
||||
return time.Time{}, err
|
||||
func (s Server) handleCreateInvoicePdf() echo.HandlerFunc {
|
||||
return func(c echo.Context) error {
|
||||
data := struct {
|
||||
Context map[string]any `json:"context"`
|
||||
Path string `json:"path"`
|
||||
ProjectId string `json:"projectId"`
|
||||
}{
|
||||
Context: map[string]interface{}{},
|
||||
Path: "index.html",
|
||||
ProjectId: os.Getenv("HTMLDOCS_PROJECT_ID"),
|
||||
}
|
||||
|
||||
payload, err := json.Marshal(data)
|
||||
if err != nil {
|
||||
fmt.Println("Error marshalling JSON:", err)
|
||||
return err
|
||||
}
|
||||
|
||||
req, err := http.NewRequest("POST", os.Getenv("HTMLDOCS_URL"), bytes.NewBuffer(payload))
|
||||
if err != nil {
|
||||
fmt.Println("Error creating request:", err)
|
||||
return err
|
||||
}
|
||||
|
||||
req.Header.Set("Authorization", "Bearer "+os.Getenv("HTMLDOCS_KEY"))
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
|
||||
client := &http.Client{}
|
||||
resp, err := client.Do(req)
|
||||
if err != nil {
|
||||
fmt.Println("Error sending request:", err)
|
||||
return err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
fmt.Println("Response Status:", resp.Status)
|
||||
fmt.Println("Response Status:", resp.Body)
|
||||
|
||||
return nil
|
||||
}
|
||||
return ts, nil
|
||||
}
|
||||
|
|
|
|||
11
pkg/time/time.go
Normal file
11
pkg/time/time.go
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
package time
|
||||
|
||||
import "time"
|
||||
|
||||
func ParseFromForm(src string) (time.Time, error) {
|
||||
ts, err := time.Parse("2006-01-02", src)
|
||||
if err != nil {
|
||||
return time.Time{}, err
|
||||
}
|
||||
return ts, nil
|
||||
}
|
||||
Loading…
Reference in a new issue