Enhance Customer Service with Notification Response Structures

- Introduced CustomerNotificationResponse struct to provide a detailed response format for customer notifications, improving the clarity of notification data.
- Updated the Customer service interface to include methods for searching and retrieving customers with notification-specific responses, enhancing the flexibility of customer data retrieval.
- Modified the Login method to accept a device token, allowing for better tracking of customer devices during login.
- Refactored existing methods to utilize the new notification response structure, ensuring consistency across customer-related API responses.
- Enhanced error handling and logging in the service layer for improved traceability during customer searches and logins.
This commit is contained in:
n.nakhostin
2025-09-22 11:47:31 +03:30
parent 733d726df6
commit ddf4d9abc4
4 changed files with 72 additions and 46 deletions
+8 -2
View File
@@ -3,6 +3,7 @@ package customer
import (
"context"
"errors"
"slices"
"time"
"tm/pkg/logger"
orm "tm/pkg/mongo"
@@ -13,7 +14,7 @@ import (
// Repository defines the interface for customer data operations
type Repository interface {
Login(ctx context.Context, id string) error
Login(ctx context.Context, id, deviceToken string) error
Register(ctx context.Context, customer *Customer) error
Update(ctx context.Context, customer *Customer) error
UpdateStatus(ctx context.Context, id string, status CustomerStatus) error
@@ -90,13 +91,18 @@ func (r *customerRepository) Register(ctx context.Context, customer *Customer) e
}
// Login updates the last login timestamp
func (r *customerRepository) Login(ctx context.Context, id string) error {
func (r *customerRepository) Login(ctx context.Context, id, deviceToken string) error {
// Get customer first
customer, err := r.GetByID(ctx, id)
if err != nil {
return err
}
// append device token to customer if not exists
if !slices.Contains(customer.DeviceToken, deviceToken) {
customer.DeviceToken = append(customer.DeviceToken, deviceToken)
}
// Update last login timestamp
customer.LastLoginAt = &[]int64{time.Now().Unix()}[0]
customer.SetUpdatedAt(time.Now().Unix())