Skip to content

Commit

Permalink
include email for registration
Browse files Browse the repository at this point in the history
  • Loading branch information
sean-david-welch committed Jun 16, 2024
1 parent 0c4c8ad commit d879275
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 6 deletions.
51 changes: 48 additions & 3 deletions server/services/registrationService.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package services

import (
"github.com/sean-david-welch/farmec-v2/server/lib"
"github.com/sean-david-welch/farmec-v2/server/stores"
"github.com/sean-david-welch/farmec-v2/server/types"
"net/smtp"
)

type RegistrationService interface {
Expand All @@ -14,11 +16,12 @@ type RegistrationService interface {
}

type RegistrationServiceImpl struct {
store stores.RegistrationStore
smtpClient lib.SMTPClient
store stores.RegistrationStore
}

func NewRegistrationService(store stores.RegistrationStore) *RegistrationServiceImpl {
return &RegistrationServiceImpl{store: store}
func NewRegistrationService(store stores.RegistrationStore, smtpClient lib.SMTPClient) *RegistrationServiceImpl {
return &RegistrationServiceImpl{store: store, smtpClient: smtpClient}
}

func (service *RegistrationServiceImpl) GetRegistrations() ([]types.MachineRegistration, error) {
Expand All @@ -44,6 +47,27 @@ func (service *RegistrationServiceImpl) CreateRegistration(registration *types.M
return err
}

client, err := service.smtpClient.SetupSMTPClient()
if err != nil {
return err
}
defer func(client *smtp.Client) {
err := client.Close()
if err != nil {
return
}
}(client)

data := &types.EmailData{
Name: registration.OwnerName,
Email: registration.DealerName,
Message: registration.MachineModel,
}

if err := service.smtpClient.SendFormNotification(client, data, "Machine Registration"); err != nil {
return err
}

return nil
}

Expand All @@ -52,6 +76,27 @@ func (service *RegistrationServiceImpl) UpdateRegistration(id string, registrati
return err
}

client, err := service.smtpClient.SetupSMTPClient()
if err != nil {
return err
}
defer func(client *smtp.Client) {
err := client.Close()
if err != nil {
return
}
}(client)

data := &types.EmailData{
Name: registration.OwnerName,
Email: registration.DealerName,
Message: registration.MachineModel,
}

if err := service.smtpClient.SendFormNotification(client, data, "Machine Registration"); err != nil {
return err
}

return nil
}

Expand Down
5 changes: 2 additions & 3 deletions server/services/warrantyService.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,12 @@ type WarrantyService interface {
}

type WarrantyServiceImpl struct {
secrets *lib.Secrets
smtpClient lib.SMTPClient
store stores.WarrantyStore
}

func NewWarrantyService(store stores.WarrantyStore, smtpClient lib.SMTPClient, secrets *lib.Secrets) *WarrantyServiceImpl {
return &WarrantyServiceImpl{store: store, smtpClient: smtpClient, secrets: secrets}
func NewWarrantyService(store stores.WarrantyStore, smtpClient lib.SMTPClient) *WarrantyServiceImpl {
return &WarrantyServiceImpl{store: store, smtpClient: smtpClient}
}

func (service *WarrantyServiceImpl) GetWarranties() ([]types.DealerOwnerInfo, error) {
Expand Down

0 comments on commit d879275

Please sign in to comment.