Enhance Notification and User Services with Improved Error Handling and Data Consistency
- Updated GetByID methods in user and customer services to return specific "not found" errors for better clarity in error responses. - Modified NotificationResponse structure to include a new Recipient field, allowing for more flexible recipient handling. - Changed CreatedAt and UpdatedAt fields in NotificationResponse to use Unix timestamps (int64) for consistency across the application. - Improved notification retrieval logic to handle potential nil values for user and customer lookups, ensuring robust data handling.
This commit is contained in:
@@ -245,6 +245,13 @@ func (s *userService) UpdateStatus(ctx context.Context, id string, form *UpdateU
|
||||
func (s *userService) GetUserByID(ctx context.Context, id string) (*UserResponse, error) {
|
||||
user, err := s.repository.GetByID(ctx, id)
|
||||
if err != nil {
|
||||
if err.Error() == "user not found" {
|
||||
return nil, errors.New("user not found")
|
||||
}
|
||||
s.logger.Error("Failed to get user by ID", map[string]interface{}{
|
||||
"error": err.Error(),
|
||||
"user_id": id,
|
||||
})
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user