orders #58

Merged
goc_daniel merged 13 commits from orders into main 2026-04-14 11:20:06 +00:00
4 changed files with 65 additions and 1 deletions
Showing only changes of commit d4d55e2757 - Show all commits

View File

@@ -117,6 +117,18 @@ func (s *EmailService) SendNewUserAdminNotification(userEmail, userName, baseURL
return s.SendEmail(s.config.AdminEmail, subject, body)
}
// SendNewOrderPlacedNotification sends an email to admin when new order is placed
func (s *EmailService) SendNewOrderPlacedNotification(userID uint) error {
if s.config.AdminEmail == "" {
return nil // No admin email configured
}
subject := "New Order Created"
body := s.newOrderPlacedTemplate(userID)
return s.SendEmail(s.config.AdminEmail, subject, body)
}
// verificationEmailTemplate returns the HTML template for email verification
func (s *EmailService) verificationEmailTemplate(name, verificationURL string, langID uint) string {
buf := bytes.Buffer{}
@@ -137,3 +149,10 @@ func (s *EmailService) newUserAdminNotificationTemplate(userEmail, userName, bas
emails.EmailAdminNotificationWrapper(view.EmailLayout[view.EmailAdminNotificationData]{LangID: constdata.ADMIN_NOTIFICATION_LANGUAGE, Data: view.EmailAdminNotificationData{UserEmail: userEmail, UserName: userName, BaseURL: baseURL}}).Render(context.Background(), &buf)
return buf.String()
}
// newUserAdminNotificationTemplate returns the HTML template for admin notification
func (s *EmailService) newOrderPlacedTemplate(userID uint) string {
buf := bytes.Buffer{}
emails.EmailNewOrderPlacedWrapper(view.EmailLayout[view.EmailNewOrderPlacedData]{LangID: constdata.ADMIN_NOTIFICATION_LANGUAGE, Data: view.EmailNewOrderPlacedData{UserID: userID}}).Render(context.Background(), &buf)
return buf.String()
}

View File

@@ -9,6 +9,7 @@ import (
"git.ma-al.com/goc_daniel/b2b/app/repos/cartsRepo"
"git.ma-al.com/goc_daniel/b2b/app/repos/ordersRepo"
"git.ma-al.com/goc_daniel/b2b/app/service/addressesService"
"git.ma-al.com/goc_daniel/b2b/app/service/emailService"
"git.ma-al.com/goc_daniel/b2b/app/utils/query/filters"
"git.ma-al.com/goc_daniel/b2b/app/utils/query/find"
"git.ma-al.com/goc_daniel/b2b/app/utils/responseErrors"
@@ -18,6 +19,7 @@ type OrderService struct {
ordersRepo ordersRepo.UIOrdersRepo
cartsRepo cartsRepo.UICartsRepo
addressesService *addressesService.AddressesService
emailService *emailService.EmailService
}
func New() *OrderService {
@@ -25,6 +27,7 @@ func New() *OrderService {
ordersRepo: ordersRepo.New(),
cartsRepo: cartsRepo.New(),
addressesService: addressesService.New(),
emailService: emailService.NewEmailService(),
}
}
@@ -80,7 +83,19 @@ func (s *OrderService) PlaceNewOrder(user_id uint, cart_id uint, name string, co
}
// all checks passed
return s.ordersRepo.PlaceNewOrder(cart, name, country_id, address_info)
err = s.ordersRepo.PlaceNewOrder(cart, name, country_id, address_info)
if err != nil {
return err
}
goc_daniel marked this conversation as resolved Outdated

after successful order placement we should either delete or deactivate the cart that is leftover

after successful order placement we should either delete or deactivate the cart that is leftover
// send email to admin
err = s.emailService.SendNewOrderPlacedNotification(user_id)
goc_daniel marked this conversation as resolved Outdated

should be a goroutine to not stall the user from getting response from the server

should be a goroutine to not stall the user from getting response from the server
if err != nil {
// Log error but don't fail placing order???
_ = err
}
return nil
}
func (s *OrderService) ChangeOrderAddress(user *model.Customer, order_id uint, country_id uint, address_info string) error {

View File

@@ -0,0 +1,26 @@
package emails
import (
"git.ma-al.com/goc_daniel/b2b/app/templ/layout"
"git.ma-al.com/goc_daniel/b2b/app/view"
"git.ma-al.com/goc_daniel/b2b/app/utils/i18n"
)
templ EmailNewOrderPlacedWrapper(data view.EmailLayout[view.EmailNewOrderPlacedData]) {
@layout.Base( i18n.T___(data.LangID, "email.email_new_order_placed_notification_title")) {
<div class="container">
<div class="email-wrapper">
<div class="email-header">
<h1>New Order Placed</h1>
</div>
<div class="email-body">
<p>Hello Administrator,</p>
<p>User with id { data.Data.UserID } has placed a new order. </p>
</div>
<div class="email-footer">
<p>&copy; 2024 Gitea Manager. All rights reserved.</p>
</div>
</div>
</div>
}
}

View File

@@ -18,3 +18,7 @@ type EmailAdminNotificationData struct {
type EmailPasswordResetData struct {
ResetURL string
}
type EmailNewOrderPlacedData struct {
UserID uint
}