Skip to content

Commit 154bc53

Browse files
Notifications categories (#125)
* Added enum * Changed event handlers * Changed enum * Changed enum, renamed NotificationsService.cs * Added new model * Changed NotificationsDomain.cs and UserDataDto.cs * Changed NotificationsController.cs * Changed model * Fixed formatting * Updated api * Changed * Minor changes * Added filterState * Changed handlers * Changed Profile.tsx * Changed * Added filterState changing * Changed NotificationViewModel * Added date and time convertion * Added getAll function, checkboxes, minor fixes * Added Accordion and checkAll * Changed default of showOnlyUnread * Removed user name and mail from Profile page * Renamed options * Renamed Profile.tsx and profile page * Removed Accordion * Changed margins * Changed margins * Removed INotificationsService.cs * Removed filter * Amended Notifications.tsx * Update hwproj.front/src/components/Notifications.tsx Co-authored-by: Alex Berezhnykh <[email protected]> * Update hwproj.front/src/components/Notifications.tsx Co-authored-by: Alex Berezhnykh <[email protected]> * Renamed isCheckAll * Added profile page * Moved methods * Fixed markAsSeen * cleanup Co-authored-by: Alex Berezhnykh <[email protected]>
1 parent 79b8cdf commit 154bc53

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+3295
-367
lines changed

HwProj.APIGateway/HwProj.APIGateway.API/Controllers/AccountController.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
using System.Threading.Tasks;
33
using HwProj.AuthService.Client;
44
using HwProj.Models.ApiGateway;
5-
using HwProj.Models.AuthService;
65
using HwProj.Models.AuthService.DTO;
76
using HwProj.Models.AuthService.ViewModels;
87
using HwProj.Models.NotificationsService;

HwProj.APIGateway/HwProj.APIGateway.API/Controllers/NotificationsController.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public NotificationsController(INotificationsServiceClient client)
1919
}
2020

2121
[HttpGet("get")]
22-
[ProducesResponseType(typeof(NotificationViewModel[]), (int)HttpStatusCode.OK)]
22+
[ProducesResponseType(typeof(CategorizedNotifications[]), (int) HttpStatusCode.OK)]
2323
public async Task<IActionResult> Get()
2424
{
2525
var userId = Request.GetUserId();
@@ -35,4 +35,4 @@ public async Task<IActionResult> MarkAsSeen([FromBody] long[] notificationIds)
3535
return Ok();
3636
}
3737
}
38-
}
38+
}

HwProj.Common/HwProj.Models/ApiGateway/UserDataDto.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ namespace HwProj.Models.ApiGateway
66
public class UserDataDto
77
{
88
public AccountDataDto UserData { get; set; }
9-
public NotificationViewModel[] Notifications { get; set; }
9+
public CategorizedNotifications[] Notifications { get; set; }
1010
}
1111
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace HwProj.Models.NotificationsService
2+
{
3+
public class CategorizedNotifications
4+
{
5+
public CategoryState Category { get; set; }
6+
public NotificationViewModel[] SeenNotifications { get; set; }
7+
public NotificationViewModel[] NotSeenNotifications { get; set; }
8+
}
9+
}

HwProj.Common/HwProj.Models/NotificationsService/Notification.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ public class Notification : IEntity<long>
1212

1313
//навесить индекс
1414
public string Owner { get; set; }
15-
public string Category { get; set; }
15+
public CategoryState Category { get; set; }
1616
public string Body { get; set; }
1717
public bool HasSeen { get; set; }
18-
public DateTime Date { get; set; }
18+
public DateTime Date { get ; set; }
1919
}
2020
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
namespace HwProj.Models.NotificationsService
2+
{
3+
public enum CategoryState
4+
{
5+
None,
6+
Profile,
7+
Courses,
8+
Homeworks
9+
}
10+
}

HwProj.Common/HwProj.Models/NotificationsService/NotificationFilter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ namespace HwProj.Models.NotificationsService
55
public class NotificationFilter
66
{
77
public string Sender { get; set; }
8-
public string Category { get; set; }
8+
public CategoryState Category { get; set; }
99
public int? MaxCount { get; set; }
1010
public int? Offset { get; set; }
1111
public int? LastNotificationsId { get; set; }
Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
1-
namespace HwProj.Models.NotificationsService
1+
using System;
2+
using System.Globalization;
3+
4+
namespace HwProj.Models.NotificationsService
25
{
36
public class NotificationViewModel
47
{
58
public long Id { get; set; }
69
public string Sender { get; set; }
710
public string Owner { get; set; }
8-
public string Category { get; set; }
11+
public CategoryState Category { get; set; }
912
public string Body { get; set; }
13+
1014
public bool HasSeen { get; set; }
15+
16+
// dd.mm.yy hh:mm
17+
public DateTime Date { get; set; }
1118
}
1219
}

HwProj.NotificationsService/HwProj.NotificationsService.API/Controllers/NotificationsController.cs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
using System.Net;
22
using System.Threading.Tasks;
3+
using AutoMapper;
34
using HwProj.Models.NotificationsService;
5+
using HwProj.NotificationsService.API.Repositories;
46
using HwProj.NotificationsService.API.Services;
57
using Microsoft.AspNetCore.Mvc;
68

@@ -10,25 +12,29 @@ namespace HwProj.NotificationsService.API.Controllers
1012
[ApiController]
1113
public class NotificationsController : ControllerBase
1214
{
13-
private readonly INotificationsService _notificationsService;
15+
private readonly INotificationsRepository _repository;
16+
private readonly IMapper _mapper;
1417

15-
public NotificationsController(INotificationsService notificationsService)
18+
public NotificationsController(INotificationsRepository repository, IMapper mapper)
1619
{
17-
_notificationsService = notificationsService;
20+
_repository = repository;
21+
_mapper = mapper;
1822
}
1923

2024
[HttpPost("get/{userId}")]
21-
[ProducesResponseType(typeof(NotificationViewModel[]), (int)HttpStatusCode.OK)]
22-
public async Task<IActionResult> Get(string userId, [FromBody] NotificationFilter filter)
25+
[ProducesResponseType(typeof(CategorizedNotifications[]), (int)HttpStatusCode.OK)]
26+
public async Task<IActionResult> Get(string userId)
2327
{
24-
var notifications = await _notificationsService.GetAsync(userId, filter);
25-
return Ok(notifications ?? new NotificationViewModel[] { });
28+
var notifications = await _repository.GetAllByUserAsync(userId);
29+
var notificationViewModels = _mapper.Map<NotificationViewModel[]>(notifications);
30+
var groupedNotifications = NotificationsDomain.Group(notificationViewModels);
31+
return Ok(groupedNotifications);
2632
}
2733

2834
[HttpPut("markAsSeen/{userId}")]
2935
public async Task<IActionResult> MarkNotifications([FromBody] long[] notificationIds, string userId)
3036
{
31-
await _notificationsService.MarkAsSeenAsync(userId, notificationIds);
37+
await _repository.MarkAsSeenAsync(userId, notificationIds);
3238
return Ok();
3339
}
3440
}

HwProj.NotificationsService/HwProj.NotificationsService.API/EventHandlers/InviteLecturerEventHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public async Task HandleAsync(InviteLecturerEvent @event)
2525
{
2626
Sender = "AuthService",
2727
Body = "Вас добавили в список лекторов.",
28-
Category = "AuthService",
28+
Category = CategoryState.Courses,
2929
Date = DateTime.UtcNow,
3030
Owner = @event.UserId
3131
};

0 commit comments

Comments
 (0)