mirror of
https://github.com/rjNemo/rentease.git
synced 2026-06-12 13:46:51 +00:00
add calendars as we use them
This commit is contained in:
parent
3983de237f
commit
fefbbc2ae9
5 changed files with 31 additions and 23 deletions
|
|
@ -17,6 +17,7 @@ type Host struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type HostItem struct {
|
type HostItem struct {
|
||||||
|
Name string
|
||||||
CalendarId string
|
CalendarId string
|
||||||
// Price is the daily price in EUR
|
// Price is the daily price in EUR
|
||||||
Price float64
|
Price float64
|
||||||
|
|
@ -41,6 +42,7 @@ func NewHost() *Host {
|
||||||
Platforms: []string{"Booking", "AirBnb", "TripAdvisor", "Other"}, // TODO: add to DB
|
Platforms: []string{"Booking", "AirBnb", "TripAdvisor", "Other"}, // TODO: add to DB
|
||||||
Items: map[string]HostItem{ // TODO: move to DB
|
Items: map[string]HostItem{ // TODO: move to DB
|
||||||
"T2": {
|
"T2": {
|
||||||
|
Name: "T2",
|
||||||
Price: 59.0,
|
Price: 59.0,
|
||||||
CalendarId: os.Getenv("CALENDAR_ID_T2"),
|
CalendarId: os.Getenv("CALENDAR_ID_T2"),
|
||||||
MustSyncCalendar: true,
|
MustSyncCalendar: true,
|
||||||
|
|
@ -49,6 +51,7 @@ func NewHost() *Host {
|
||||||
},
|
},
|
||||||
|
|
||||||
"T3": {
|
"T3": {
|
||||||
|
Name: "T3",
|
||||||
Price: 80.0,
|
Price: 80.0,
|
||||||
CalendarId: os.Getenv("CALENDAR_ID_T3"),
|
CalendarId: os.Getenv("CALENDAR_ID_T3"),
|
||||||
MustSyncCalendar: true,
|
MustSyncCalendar: true,
|
||||||
|
|
@ -56,15 +59,19 @@ func NewHost() *Host {
|
||||||
Taxable: true,
|
Taxable: true,
|
||||||
},
|
},
|
||||||
"Airport": {
|
"Airport": {
|
||||||
|
Name: "Airport",
|
||||||
Price: 25.0,
|
Price: 25.0,
|
||||||
},
|
},
|
||||||
"Port": {
|
"Port": {
|
||||||
|
Name: "Port",
|
||||||
Price: 20.0,
|
Price: 20.0,
|
||||||
},
|
},
|
||||||
"Transport": {
|
"Transport": {
|
||||||
|
Name: "Transport",
|
||||||
Price: 20.0,
|
Price: 20.0,
|
||||||
},
|
},
|
||||||
"Taxes": { // TODO: remove after auto creation enabled
|
"Taxes": { // TODO: remove after auto creation enabled
|
||||||
|
Name: "Taxes",
|
||||||
Price: 1.5,
|
Price: 1.5,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -1,18 +1,3 @@
|
||||||
package calendar
|
package calendar
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
)
|
|
||||||
|
|
||||||
type Option func(*Service) error
|
type Option func(*Service) error
|
||||||
|
|
||||||
func WithCalendar(key string, calendarId string) Option {
|
|
||||||
return func(s *Service) error {
|
|
||||||
_, err := s.CalendarList.Get(calendarId).Do()
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("cannot find calendar entry with id %q: %w", calendarId, err)
|
|
||||||
}
|
|
||||||
s.calIds[key] = calendarId
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@ import (
|
||||||
const tokFile = "token.json"
|
const tokFile = "token.json"
|
||||||
|
|
||||||
type Service struct {
|
type Service struct {
|
||||||
calIds map[string]string
|
calIds map[string]struct{}
|
||||||
*calendar.Service
|
*calendar.Service
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -39,7 +39,7 @@ func NewService(ctx context.Context, credJson string, opts ...Option) (*Service,
|
||||||
|
|
||||||
s := &Service{
|
s := &Service{
|
||||||
Service: srv,
|
Service: srv,
|
||||||
calIds: make(map[string]string),
|
calIds: make(map[string]struct{}),
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, opt := range opts {
|
for _, opt := range opts {
|
||||||
|
|
@ -53,6 +53,16 @@ func NewService(ctx context.Context, credJson string, opts ...Option) (*Service,
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Service) Create(calendarId, name, description string, from, to time.Time) error {
|
func (s *Service) Create(calendarId, name, description string, from, to time.Time) error {
|
||||||
|
// add calendarId to list of known calendars
|
||||||
|
_, ok := s.calIds[calendarId]
|
||||||
|
if !ok {
|
||||||
|
_, err := s.CalendarList.Get(calendarId).Do()
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("cannot find calendar entry with id %q: %w", calendarId, err)
|
||||||
|
}
|
||||||
|
s.calIds[calendarId] = struct{}{}
|
||||||
|
}
|
||||||
|
|
||||||
ne, err := s.Events.Insert(calendarId, &calendar.Event{
|
ne, err := s.Events.Insert(calendarId, &calendar.Event{
|
||||||
Description: name,
|
Description: name,
|
||||||
End: &calendar.EventDateTime{
|
End: &calendar.EventDateTime{
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,6 @@ package server
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
@ -130,7 +129,14 @@ func handleBookingPage(bs *booking.Service, hc *config.Host) echo.HandlerFunc {
|
||||||
return sum + i.Price*float64(i.Quantity)
|
return sum + i.Price*float64(i.Quantity)
|
||||||
}, 0.0), 'f', 2, 64),
|
}, 0.0), 'f', 2, 64),
|
||||||
Platforms: hc.Platforms,
|
Platforms: hc.Platforms,
|
||||||
ItemList: u.Map(hc.Items, func(i config.HostItem) string { return i.Name }),
|
ItemList: u.OrderBy(func(items map[string]config.HostItem) (out []string) {
|
||||||
|
for _, item := range items {
|
||||||
|
out = append(out, item.Name)
|
||||||
|
}
|
||||||
|
return out
|
||||||
|
}(hc.Items),
|
||||||
|
func(l, r string) bool { return l < r },
|
||||||
|
),
|
||||||
PaymentMethods: hc.PaymentMethods,
|
PaymentMethods: hc.PaymentMethods,
|
||||||
}
|
}
|
||||||
return renderTempl(c, http.StatusOK, view.BookingById(bvm))
|
return renderTempl(c, http.StatusOK, view.BookingById(bvm))
|
||||||
|
|
@ -142,11 +148,11 @@ func handleBookingUpdate(bs *booking.Service, hc *config.Host) echo.HandlerFunc
|
||||||
type UpdateBooking struct {
|
type UpdateBooking struct {
|
||||||
From time.Time `json:"from"`
|
From time.Time `json:"from"`
|
||||||
To time.Time `json:"to"`
|
To time.Time `json:"to"`
|
||||||
|
ExternalId *string `form:"external_id"`
|
||||||
Name string `form:"name"`
|
Name string `form:"name"`
|
||||||
PhoneNumber string `form:"phone_number"`
|
PhoneNumber string `form:"phone_number"`
|
||||||
Email string `form:"email"`
|
Email string `form:"email"`
|
||||||
Platform string `form:"platform"`
|
Platform string `form:"platform"`
|
||||||
ExternalId *string `form:"external_id"`
|
|
||||||
Id int `param:"id"`
|
Id int `param:"id"`
|
||||||
CustomerNumber int `form:"customer_number"`
|
CustomerNumber int `form:"customer_number"`
|
||||||
PlatformFees float64 `form:"platform_fees"`
|
PlatformFees float64 `form:"platform_fees"`
|
||||||
|
|
@ -238,7 +244,7 @@ func handleCreateItem(bs *booking.Service, cs *calendar.Service, hc *config.Host
|
||||||
|
|
||||||
itm, ok := hc.Items[ni.Item]
|
itm, ok := hc.Items[ni.Item]
|
||||||
if !ok {
|
if !ok {
|
||||||
return errors.New(fmt.Sprintf("invalid item name %q", ni.Item))
|
return fmt.Errorf("invalid item name %q", ni.Item)
|
||||||
}
|
}
|
||||||
|
|
||||||
i := bs.CreateItem(b.Id, ni.Item, ni.Quantity, ni.Price, ni.PaymentMethod)
|
i := bs.CreateItem(b.Id, ni.Item, ni.Quantity, ni.Price, ni.PaymentMethod)
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,7 @@ func (s Server) MountHandlers() {
|
||||||
g.GET("/bookings/:id", handleBookingPage(s.bs, s.hc))
|
g.GET("/bookings/:id", handleBookingPage(s.bs, s.hc))
|
||||||
g.PUT("/bookings/:id", handleBookingUpdate(s.bs, s.hc))
|
g.PUT("/bookings/:id", handleBookingUpdate(s.bs, s.hc))
|
||||||
g.PATCH("/bookings/:id/cancel", handleBookingCancel(s.bs))
|
g.PATCH("/bookings/:id/cancel", handleBookingCancel(s.bs))
|
||||||
g.POST("/bookings/:id/items", handleCreateItem(s.bs))
|
g.POST("/bookings/:id/items", handleCreateItem(s.bs, s.cs, s.hc))
|
||||||
g.POST("/items/:id", handleItemPay(s.bs))
|
g.POST("/items/:id", handleItemPay(s.bs))
|
||||||
g.PUT("/items/:id", handleItemUpdate(s.bs))
|
g.PUT("/items/:id", handleItemUpdate(s.bs))
|
||||||
g.GET("/items/:id", handleLineItemForm(s.bs))
|
g.GET("/items/:id", handleLineItemForm(s.bs))
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue