forked from hngprojects/hng_boilerplate_csharp_web
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature(graphql):Implement Notification and newsletter query and muta…
…tion resolvers (hngprojects#385)
- Loading branch information
Showing
19 changed files
with
184 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
15 changes: 15 additions & 0 deletions
15
src/Hng.Graphql/Features/Mutations/Mutations.NewsLetter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using Hng.Application.Features.NewsLetterSubscription.Commands; | ||
using Hng.Application.Features.NewsLetterSubscription.Dtos; | ||
using MediatR; | ||
using Microsoft.AspNetCore.Mvc; | ||
|
||
namespace Hng.Graphql | ||
{ | ||
public partial class Mutations | ||
{ | ||
public async Task<NewsLetterSubscriptionDto> RegisterNewsLetterSubscriber(NewsLetterSubscriptionDto subscriber, [FromServices] IMediator mediator) | ||
{ | ||
return await mediator.Send(new AddSubscriberCommand(subscriber)); | ||
} | ||
} | ||
} |
69 changes: 69 additions & 0 deletions
69
src/Hng.Graphql/Features/Mutations/Mutations.Notification.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
using Hng.Application.Features.Notifications.Commands; | ||
using Hng.Application.Features.Notifications.Dtos; | ||
using HotChocolate.Authorization; | ||
using MediatR; | ||
using Microsoft.AspNetCore.Mvc; | ||
|
||
namespace Hng.Graphql.Features.Mutations | ||
{ | ||
public partial class Mutations | ||
{ | ||
/// <summary> | ||
/// Notification Settings - Create User notification | ||
/// </summary> | ||
[Authorize] | ||
public async Task<NotificationResult> CreateNotification(CreateNotificationDto command, [FromServices] IMediator mediator) | ||
{ | ||
var createCommand = new CreateNotificationCommand(command); | ||
return await mediator.Send(createCommand); | ||
} | ||
|
||
|
||
/// <summary> | ||
/// Mark a single notification as read | ||
/// </summary> | ||
/// <param name="notification_id">The ID of the notification</param> | ||
/// <param name="request">The request body containing is_read flag</param> | ||
/// <returns>Response indicating the result of the operation</returns> | ||
[Authorize] | ||
public async Task<NotificationDto> MarkNotificationAsRead(Guid notification_id, UpdateNotificationDto request, [FromServices] IMediator mediator) | ||
{ | ||
var command = new UpdateNotificationCommand(notification_id, request.IsRead); | ||
return await mediator.Send(command); | ||
} | ||
|
||
/// <summary> | ||
/// Mark all notification as read | ||
/// </summary> | ||
/// <param name="request">The request body containing is_read flag</param> | ||
/// <returns>Response indicating the result of the operation</returns> | ||
[Authorize] | ||
public async Task<List<NotificationDto>> MarkAllNotificationAsRead(UpdateNotificationDto request, [FromServices] IMediator mediator) | ||
{ | ||
var command = new MarkAllCommand(request.IsRead); | ||
return await mediator.Send(command); | ||
|
||
} | ||
|
||
/// <summary> | ||
/// Clear all user's notifications (Read or Unread) | ||
/// </summary> | ||
[Authorize] | ||
public async Task<bool> DeleteAllNotifications([FromServices] IMediator mediator) | ||
{ | ||
var command = new DeleteAllNotificationsCommand(); | ||
return await mediator.Send(command); | ||
|
||
} | ||
|
||
/// <summary> | ||
/// Clear notification (Read or Unread) | ||
/// </summary> | ||
[Authorize] | ||
public async Task<bool> DeleteNotificationById(Guid notification_id, [FromServices] IMediator mediator) | ||
{ | ||
var command = new DeleteNotificationByIdCommand(notification_id); | ||
return await mediator.Send(command); | ||
} | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
src/Hng.Graphql/Features/Mutations/Mutations.NotificationSettings.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using Hng.Application.Features.Notifications.Commands; | ||
using Hng.Application.Features.Notifications.Dtos; | ||
using HotChocolate.Authorization; | ||
using MediatR; | ||
using Microsoft.AspNetCore.Mvc; | ||
|
||
namespace Hng.Graphql | ||
{ | ||
public partial class Mutations | ||
{ | ||
/// <summary> | ||
/// Notification Settings - User notification settings | ||
/// </summary> | ||
[Authorize] | ||
public async Task<NotificationSettingsDto> CreateNotificationSettings([FromBody] CreateNotificationSettingsDto command, [FromServices] IMediator mediator) | ||
{ | ||
{ | ||
var createCommand = new CreateNotificationSettingsCommand(command); | ||
return await mediator.Send(createCommand); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 3 additions & 1 deletion
4
src/Hng.Graphql/Queries.Admin.cs → ...Graphql/Features/Queries/Queries.Admin.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
using Hng.Application.Features.Notifications.Dtos; | ||
using Hng.Application.Features.Notifications.Queries; | ||
using HotChocolate.Authorization; | ||
using MediatR; | ||
using Microsoft.AspNetCore.Mvc; | ||
|
||
namespace Hng.Graphql.Features.Queries | ||
{ | ||
public partial class Queries | ||
{ | ||
/// <summary> | ||
/// Retrieve user's notifications (Read + Unread) | ||
/// </summary> | ||
[Authorize] | ||
public async Task<GetNotificationsResponseDto> GetAllNotifications([FromServices] IMediator mediator) | ||
{ | ||
var query = new GetAllNotificationsQuery(); | ||
return await mediator.Send(query); | ||
} | ||
|
||
/// <summary> | ||
/// Retrieve user's notifications (Read or Unread) | ||
/// </summary> | ||
[Authorize] | ||
public async Task<GetNotificationsResponseDto> GetNotifications(bool? is_read, [FromServices] IMediator mediator) | ||
{ | ||
var query = new GetNotificationsQuery(is_read); | ||
return await mediator.Send(query); | ||
} | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
src/Hng.Graphql/Features/Queries/Queries.NotificationSetting.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
using Hng.Application.Features.Notifications.Dtos; | ||
using Hng.Application.Features.Notifications.Queries; | ||
using HotChocolate.Authorization; | ||
using MediatR; | ||
using Microsoft.AspNetCore.Mvc; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Hng.Graphql | ||
{ | ||
public partial class Queries | ||
{ | ||
/// <summary> | ||
/// Get Notification Settings by User ID | ||
/// </summary> | ||
[Authorize] | ||
public async Task<NotificationSettingsDto> GetNotificationSettings(Guid user_id, [FromServices] IMediator mediator) | ||
{ | ||
var query = new GetNotificationSettingsQuery(user_id); | ||
return await mediator.Send(query); | ||
|
||
} | ||
} | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters