package booking import ( "log" "time" "gorm.io/gorm" "github.com/rjNemo/rentease/internal/config" "github.com/rjNemo/rentease/internal/driver/calendar" "github.com/rjNemo/rentease/internal/driver/pdf" ) type Service struct { store *PgStore calendar calendar.Client pdf pdf.Client } func NewService(db *gorm.DB, calendar calendar.Client, pdf pdf.Client) (*Service, error) { return &Service{ store: NewPgStore(db), calendar: calendar, pdf: pdf, }, nil } func (bs Service) All() []*Line { return bs.store.All() } func (bs Service) Search(value string) []*Line { return bs.store.Search(value) } // TODO: return the error func (bs Service) Create(From time.Time, To time.Time, Name, PhoneNumber, Email, Platform string, CustomerNumber int, PlatformFees float64, externalId *string, ) *Booking { b := &Booking{ Name: Name, PhoneNumber: PhoneNumber, CustomerNumber: CustomerNumber, Email: Email, From: From, To: To, Platform: Platform, PlatformFees: PlatformFees, ExternalId: externalId, } err := bs.store.Create(b) if err != nil { log.Println(err) } return b } func (bs Service) One(id int) *Booking { return bs.store.Get(id) } // TODO: return the error func (bs Service) Update(id int, From time.Time, To time.Time, Name string, PhoneNumber string, Email string, Platform string, CustomerNumber int, PlatformFees float64, externalId *string, ) *Booking { b := &Booking{ Id: id, Name: Name, PhoneNumber: PhoneNumber, CustomerNumber: CustomerNumber, Email: Email, From: From, To: To, Platform: Platform, PlatformFees: PlatformFees, ExternalId: externalId, } if err := bs.store.Update(b); err != nil { log.Println(err) } return b } // func (bs Service) CreateRequest(From time.Time, To time.Time, Name string, PhoneNumber string, Email string, Item string, CustomerNumber int) *BookingRequest { // b := &BookingRequest{ // CustomerName: Name, // PhoneNumber: &PhoneNumber, // CustomerNumber: CustomerNumber, // Email: &Email, // From: From, // To: To, // ItemType: Item, // } // _ = bs.db.Create(b) // return b // } func (bs Service) Cancel(id int) { err := bs.store.Cancel(id) if err != nil { log.Println(err) } } func (bs Service) BuildInvoice(b *Booking, hc *config.Host) error { return bs.pdf.BuildInvoice(b.Serialize(hc)) }