Skip to content

Commit

Permalink
应用层通知注释
Browse files Browse the repository at this point in the history
  • Loading branch information
boydg123 committed Jul 17, 2017
1 parent 2c5e485 commit 2d4f05a
Show file tree
Hide file tree
Showing 8 changed files with 121 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,18 @@

namespace Derrick.Notifications.Dto
{
/// <summary>
/// 获取通知设置Output
/// </summary>
public class GetNotificationSettingsOutput
{
/// <summary>
/// 是否收到通知
/// </summary>
public bool ReceiveNotifications { get; set; }

/// <summary>
/// 通知列表
/// </summary>
public List<NotificationSubscriptionWithDisplayNameDto> Notifications { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,21 @@

namespace Derrick.Notifications.Dto
{
/// <summary>
/// 获取通知Output
/// </summary>
public class GetNotificationsOutput : PagedResultDto<UserNotification>
{
/// <summary>
/// 未读数量
/// </summary>
public int UnreadCount { get; set; }

/// <summary>
/// 构造函数
/// </summary>
/// <param name="totalCount">总数量</param>
/// <param name="unreadCount">未读数量</param>
/// <param name="notifications">通知列表</param>
public GetNotificationsOutput(int totalCount, int unreadCount, List<UserNotification> notifications)
:base(totalCount, notifications)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,14 @@

namespace Derrick.Notifications.Dto
{
/// <summary>
/// 获取用户通知Input
/// </summary>
public class GetUserNotificationsInput : PagedInputDto
{
/// <summary>
/// 用户通知状态
/// </summary>
public UserNotificationState? State { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,20 @@

namespace Derrick.Notifications.Dto
{
/// <summary>
/// 订阅通知Dto
/// </summary>
public class NotificationSubscriptionDto
{
/// <summary>
/// Name
/// </summary>
[Required]
[MaxLength(NotificationInfo.MaxNotificationNameLength)]
public string Name { get; set; }

/// <summary>
/// 是否订阅
/// </summary>
public bool IsSubscribed { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,19 @@

namespace Derrick.Notifications.Dto
{
/// <summary>
/// 带显示名的订阅通知Dto
/// </summary>
[AutoMapFrom(typeof(NotificationDefinition))]
public class NotificationSubscriptionWithDisplayNameDto : NotificationSubscriptionDto
{
/// <summary>
/// 显示名
/// </summary>
public string DisplayName { get; set; }

/// <summary>
/// 描述
/// </summary>
public string Description { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,18 @@

namespace Derrick.Notifications.Dto
{
/// <summary>
/// 更新通知设置Input
/// </summary>
public class UpdateNotificationSettingsInput
{
/// <summary>
/// 是否收到通知
/// </summary>
public bool ReceiveNotifications { get; set; }

/// <summary>
/// 订阅通知列表
/// </summary>
public List<NotificationSubscriptionDto> Notifications { get; set; }
}
}
30 changes: 26 additions & 4 deletions zero/Derrick.Application/Notifications/INotificationAppService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,38 @@

namespace Derrick.Notifications
{
/// <summary>
/// 通知服务
/// </summary>
public interface INotificationAppService : IApplicationService
{
/// <summary>
/// 获取用户通知列表
/// </summary>
/// <param name="input">用户用户通知Input</param>
/// <returns></returns>
Task<GetNotificationsOutput> GetUserNotifications(GetUserNotificationsInput input);

/// <summary>
/// 设置所有通知为已读
/// </summary>
/// <returns></returns>
Task SetAllNotificationsAsRead();

/// <summary>
/// 设置通知为已读
/// </summary>
/// <param name="input">实体Dto</param>
/// <returns></returns>
Task SetNotificationAsRead(EntityDto<Guid> input);

/// <summary>
/// 获取通知设置列表
/// </summary>
/// <returns></returns>
Task<GetNotificationSettingsOutput> GetNotificationSettings();

/// <summary>
/// 更新通知设置Input
/// </summary>
/// <param name="input">更新通知设置Input</param>
/// <returns></returns>
Task UpdateNotificationSettings(UpdateNotificationSettingsInput input);
}
}
46 changes: 41 additions & 5 deletions zero/Derrick.Application/Notifications/NotificationAppService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,31 @@

namespace Derrick.Notifications
{
/// <summary>
/// 通知服务实现
/// </summary>
[AbpAuthorize]
public class NotificationAppService : AbpZeroTemplateAppServiceBase, INotificationAppService
{
/// <summary>
/// 通知定义管理器
/// </summary>
private readonly INotificationDefinitionManager _notificationDefinitionManager;
/// <summary>
/// 用户通知管理器
/// </summary>
private readonly IUserNotificationManager _userNotificationManager;
/// <summary>
/// 订阅通知管理器
/// </summary>
private readonly INotificationSubscriptionManager _notificationSubscriptionManager;

/// <summary>
/// 构造函数
/// </summary>
/// <param name="notificationDefinitionManager">通知定义管理</param>
/// <param name="userNotificationManager">用户通知管理</param>
/// <param name="notificationSubscriptionManager">订阅通知管理</param>
public NotificationAppService(
INotificationDefinitionManager notificationDefinitionManager,
IUserNotificationManager userNotificationManager,
Expand All @@ -29,7 +47,11 @@ public NotificationAppService(
_userNotificationManager = userNotificationManager;
_notificationSubscriptionManager = notificationSubscriptionManager;
}

/// <summary>
/// 获取用户通知列表
/// </summary>
/// <param name="input">用户用户通知Input</param>
/// <returns></returns>
[DisableAuditing]
public async Task<GetNotificationsOutput> GetUserNotifications(GetUserNotificationsInput input)
{
Expand All @@ -47,12 +69,19 @@ public async Task<GetNotificationsOutput> GetUserNotifications(GetUserNotificati

return new GetNotificationsOutput(totalCount, unreadCount, notifications);
}

/// <summary>
/// 设置所有通知为已读
/// </summary>
/// <returns></returns>
public async Task SetAllNotificationsAsRead()
{
await _userNotificationManager.UpdateAllUserNotificationStatesAsync(AbpSession.ToUserIdentifier(), UserNotificationState.Read);
}

/// <summary>
/// 设置通知为已读
/// </summary>
/// <param name="input">实体Dto</param>
/// <returns></returns>
public async Task SetNotificationAsRead(EntityDto<Guid> input)
{
var userNotification = await _userNotificationManager.GetUserNotificationAsync(AbpSession.TenantId, input.Id);
Expand All @@ -63,7 +92,10 @@ public async Task SetNotificationAsRead(EntityDto<Guid> input)

await _userNotificationManager.UpdateUserNotificationStateAsync(AbpSession.TenantId, input.Id, UserNotificationState.Read);
}

/// <summary>
/// 获取通知设置列表
/// </summary>
/// <returns></returns>
public async Task<GetNotificationSettingsOutput> GetNotificationSettings()
{
var output = new GetNotificationSettingsOutput();
Expand All @@ -84,7 +116,11 @@ public async Task<GetNotificationSettingsOutput> GetNotificationSettings()

return output;
}

/// <summary>
/// 更新通知设置Input
/// </summary>
/// <param name="input">更新通知设置Input</param>
/// <returns></returns>
public async Task UpdateNotificationSettings(UpdateNotificationSettingsInput input)
{
await SettingManager.ChangeSettingForUserAsync(AbpSession.ToUserIdentifier(), NotificationSettingNames.ReceiveNotifications, input.ReceiveNotifications.ToString());
Expand Down

0 comments on commit 2d4f05a

Please sign in to comment.