Skip to content

Commit fda6755

Browse files
committed
Remove NotificationResponseType that's because the frontend already sent the type of notification
1 parent b2dca6d commit fda6755

3 files changed

Lines changed: 17 additions & 30 deletions

File tree

AskFm/AskFm.BLL/DTO/NotificationTypeResponse.cs

Lines changed: 0 additions & 8 deletions
This file was deleted.

AskFm/AskFm.BLL/Services/INotificationService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ namespace AskFm.BLL.Services;
66
public interface INotificationService
77
{
88
Task<List<NotificationDto>> GetUserNotifications(int userId, int pageNumber = 1, int pageSize = 10);
9-
Task<NotificationTypeResponse> GetNotificationsByType(int userId, string category, int pageNumber = 1, int pageSize = 10);
9+
Task<List<NotificationDto>> GetNotificationsByType(int userId, string category, int pageNumber = 1, int pageSize = 10);
1010
Task<string> MarkNotificationAsRead(int notificationId);
1111
Task<string> MarkAllNotificationsAsRead(int userId);
1212
Task CreateNotification(int userId, NotificationStatus type, int resourceId, string message);

AskFm/AskFm.BLL/Services/NotificationService.cs

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)