@@ -57,21 +57,23 @@ public async Task<List<NotificationDto>> GetUserNotifications(int userId, int pa
5757 return notificationDtos ;
5858 }
5959
60- public async Task < NotificationTypeResponse > GetNotificationsByType ( int userId , string category , int pageNumber = 1 , int pageSize = 10 )
60+ public async Task < List < NotificationDto > > GetNotificationsByType ( int userId , string category , int pageNumber = 1 , int pageSize = 10 )
6161 {
62- // first we have to convert category to upper case and match it with enum
63- if ( ! Enum . TryParse < NotificationStatus > ( category , true , out var notificationType ) )
62+ // Convert category to uppercase and match with enum
63+ if ( ! Enum . TryParse < NotificationStatus > ( category . ToUpper ( ) , out var notificationType ) )
6464 throw new ArgumentException ( $ "Invalid notification category: { category } ") ;
6565
6666 var ( notifications , totalCount ) = await _notificationRepository . GetNotificationsByType ( userId , notificationType , pageNumber , pageSize ) ;
67-
67+
68+ var totalPages = ( int ) Math . Ceiling ( ( double ) totalCount / pageSize ) ;
69+
6870 var notificationDtos = new List < NotificationDto > ( ) ;
6971
7072 foreach ( var notification in notifications )
7173 {
7274 var actorUser = await _notificationRepository . GetActorUserByResourceId ( notification . ResourceId , notification . Type ) ;
7375 notificationDtos . Add ( new NotificationDto
74- {
76+ {
7577 Id = notification . Id ,
7678 UserId = notification . UserId ,
7779 Type = notification . Type . ToString ( ) ,
@@ -84,27 +86,20 @@ public async Task<NotificationTypeResponse> GetNotificationsByType(int userId, s
8486 Id = actorUser . Id ,
8587 Username = actorUser ? . UserName ?? "Unknown" ,
8688 AvatarPath = actorUser ? . AvatarPath ?? String . Empty
89+ } ,
90+ Pagination = new PaginationDto
91+ {
92+ CurrentPage = pageNumber ,
93+ TotalPages = totalPages ,
94+ TotalCount = totalCount ,
95+ HasNext = pageNumber < totalPages ,
96+ HasPrevious = pageNumber > 1
8797 }
8898 } ) ;
8999 }
90100
91- var totalPages = ( int ) Math . Ceiling ( ( double ) totalCount / pageSize ) ;
92-
93- return new NotificationTypeResponse
94- {
95- Type = category . ToUpper ( ) ,
96- Notifications = notificationDtos ,
97- Pagination = new PaginationDto
98- {
99- CurrentPage = pageNumber ,
100- TotalPages = totalPages ,
101- TotalCount = totalCount ,
102- HasNext = pageNumber < totalPages ,
103- HasPrevious = pageNumber > 1
104- }
105- } ;
101+ return notificationDtos ;
106102 }
107-
108103 public async Task < string > MarkNotificationAsRead ( int notificationId )
109104 {
110105 await _notificationRepository . MarkNotificationAsRead ( notificationId ) ;
0 commit comments