add: contactController,tests & refactored tests
This commit is contained in:
@@ -13,13 +13,12 @@ import (
|
||||
)
|
||||
|
||||
type EmailService struct {
|
||||
dialer *gomail.Dialer
|
||||
adminEmail string
|
||||
dialer *gomail.Dialer
|
||||
}
|
||||
|
||||
func NewEmailService(host string, port int, username, password, adminEmail string) *EmailService {
|
||||
func NewEmailService(host string, port int, username string, password string) *EmailService {
|
||||
dialer := gomail.NewDialer(host, port, username, password)
|
||||
return &EmailService{dialer: dialer, adminEmail: adminEmail}
|
||||
return &EmailService{dialer: dialer}
|
||||
}
|
||||
|
||||
func (s *EmailService) SendEmail(to string, subject string, body string) error {
|
||||
@@ -87,10 +86,10 @@ func (s *EmailService) SendWelcomeEmail(user *models.User) error {
|
||||
Company string
|
||||
FirstName string
|
||||
MembershipModel string
|
||||
BASEURL string
|
||||
MembershipID int64
|
||||
MembershipFee float32
|
||||
RentalFee float32
|
||||
BASEURL string
|
||||
}{
|
||||
Company: user.Company,
|
||||
FirstName: user.FirstName,
|
||||
@@ -110,24 +109,24 @@ func (s *EmailService) SendWelcomeEmail(user *models.User) error {
|
||||
return s.SendEmail(user.Email, subject, body)
|
||||
}
|
||||
|
||||
func (s *EmailService) NotifyAdminOfNewUser(user *models.User) error {
|
||||
func (s *EmailService) SendRegistrationNotification(user *models.User) error {
|
||||
// Prepare data to be injected into the template
|
||||
data := struct {
|
||||
City string
|
||||
Email string
|
||||
FirstName string
|
||||
DateOfBirth string
|
||||
LastName string
|
||||
MembershipModel string
|
||||
Address string
|
||||
IBAN string
|
||||
FirstName string
|
||||
Email string
|
||||
Phone string
|
||||
DateOfBirth string
|
||||
City string
|
||||
Company string
|
||||
ZipCode string
|
||||
BASEURL string
|
||||
MembershipID int64
|
||||
RentalFee float32
|
||||
MembershipFee float32
|
||||
BASEURL string
|
||||
}{
|
||||
Company: user.Company,
|
||||
FirstName: user.FirstName,
|
||||
@@ -152,7 +151,7 @@ func (s *EmailService) NotifyAdminOfNewUser(user *models.User) error {
|
||||
logger.Error.Print("Couldn't send admin notification mail")
|
||||
return err
|
||||
}
|
||||
return s.SendEmail(config.SMTP.AdminEmail, subject, body)
|
||||
return s.SendEmail(config.Recipients.UserRegistration, subject, body)
|
||||
}
|
||||
|
||||
func (s *EmailService) RelayContactFormMessage(sender string, name string, message string) error {
|
||||
@@ -171,5 +170,5 @@ func (s *EmailService) RelayContactFormMessage(sender string, name string, messa
|
||||
logger.Error.Print("Couldn't send contact form message mail")
|
||||
return err
|
||||
}
|
||||
return s.SendEmail(config.SMTP.AdminEmail, subject, body)
|
||||
return s.SendEmail(config.Recipients.ContactForm, subject, body)
|
||||
}
|
||||
|
||||
@@ -1,11 +1,15 @@
|
||||
package services
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"slices"
|
||||
"time"
|
||||
|
||||
"github.com/go-playground/validator/v10"
|
||||
|
||||
"GoMembership/internal/models"
|
||||
"GoMembership/internal/repositories"
|
||||
"GoMembership/pkg/errors"
|
||||
"slices"
|
||||
"time"
|
||||
)
|
||||
|
||||
type MembershipServiceInterface interface {
|
||||
@@ -14,6 +18,7 @@ type MembershipServiceInterface interface {
|
||||
RegisterSubscription(subscription *models.SubscriptionModel) (int64, error)
|
||||
GetMembershipModelNames() ([]string, error)
|
||||
GetModelByName(modelname *string) (*models.SubscriptionModel, error)
|
||||
GetSubscriptions(where map[string]interface{}) (*[]models.SubscriptionModel, error)
|
||||
}
|
||||
|
||||
type MembershipService struct {
|
||||
@@ -32,6 +37,9 @@ func (service *MembershipService) FindMembershipByUserID(userID int64) (*models.
|
||||
|
||||
// Membership_Subscriptions
|
||||
func (service *MembershipService) RegisterSubscription(subscription *models.SubscriptionModel) (int64, error) {
|
||||
if err := validateSubscriptionData(subscription); err != nil {
|
||||
return http.StatusNotAcceptable, err
|
||||
}
|
||||
return service.SubscriptionRepo.CreateSubscriptionModel(subscription)
|
||||
}
|
||||
|
||||
@@ -50,3 +58,15 @@ func (service *MembershipService) GetModelByName(modelname *string) (*models.Sub
|
||||
}
|
||||
return service.SubscriptionRepo.GetModelByName(modelname)
|
||||
}
|
||||
|
||||
func (service *MembershipService) GetSubscriptions(where map[string]interface{}) (*[]models.SubscriptionModel, error) {
|
||||
return service.SubscriptionRepo.GetSubscriptions(where)
|
||||
}
|
||||
|
||||
func validateSubscriptionData(subscription *models.SubscriptionModel) error {
|
||||
validate := validator.New()
|
||||
|
||||
validate.RegisterValidation("subscriptionModel", func(fl validator.FieldLevel) bool { return true })
|
||||
validate.RegisterValidation("membershipField", func(fl validator.FieldLevel) bool { return true })
|
||||
return validate.Struct(subscription)
|
||||
}
|
||||
|
||||
@@ -34,8 +34,7 @@ func (service *UserService) RegisterUser(user *models.User) (int64, string, erro
|
||||
}
|
||||
user.Salt = base64.StdEncoding.EncodeToString(salt)
|
||||
*/
|
||||
err := validateRegistrationData(user)
|
||||
if err != nil {
|
||||
if err := validateRegistrationData(user); err != nil {
|
||||
return http.StatusNotAcceptable, "", err
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user