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:
n.nakhostin
2025-09-27 11:40:17 +03:30
parent 7110e55cf5
commit ac7eb0385d
4 changed files with 57 additions and 13 deletions
+7
View File
@@ -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
}