1+ using CCE . Api . Common . Extensions ;
12using CCE . Application . Common . Interfaces ;
23using CCE . Application . Notifications . Public . Commands . MarkAllNotificationsRead ;
34using CCE . Application . Notifications . Public . Commands . MarkNotificationRead ;
5+ using CCE . Application . Notifications . Public . Commands . UpdateMyNotificationSettings ;
6+ using CCE . Application . Notifications . Public . Queries . GetMyNotificationSettings ;
47using CCE . Application . Notifications . Public . Queries . GetMyUnreadCount ;
58using CCE . Application . Notifications . Public . Queries . ListMyNotifications ;
69using CCE . Domain . Notifications ;
@@ -28,7 +31,7 @@ public static IEndpointRouteBuilder MapNotificationsEndpoints(this IEndpointRout
2831 if ( userId == System . Guid . Empty ) return Results . Unauthorized ( ) ;
2932 var query = new ListMyNotificationsQuery ( userId , page ?? 1 , pageSize ?? 20 , status ) ;
3033 var result = await mediator . Send ( query , ct ) . ConfigureAwait ( false ) ;
31- return Results . Ok ( result ) ;
34+ return result . ToHttpResult ( ) ;
3235 } ) . WithName ( "ListMyNotifications" ) ;
3336
3437 notif . MapGet ( "/unread-count" , async (
@@ -37,8 +40,8 @@ public static IEndpointRouteBuilder MapNotificationsEndpoints(this IEndpointRout
3740 {
3841 var userId = currentUser . GetUserId ( ) ?? System . Guid . Empty ;
3942 if ( userId == System . Guid . Empty ) return Results . Unauthorized ( ) ;
40- var count = await mediator . Send ( new GetMyUnreadCountQuery ( userId ) , ct ) . ConfigureAwait ( false ) ;
41- return Results . Ok ( new { count } ) ;
43+ var result = await mediator . Send ( new GetMyUnreadCountQuery ( userId ) , ct ) . ConfigureAwait ( false ) ;
44+ return result . ToHttpResult ( ) ;
4245 } ) . WithName ( "GetMyUnreadNotificationCount" ) ;
4346
4447 notif . MapPost ( "/{id:guid}/mark-read" , async (
@@ -48,8 +51,8 @@ public static IEndpointRouteBuilder MapNotificationsEndpoints(this IEndpointRout
4851 {
4952 var userId = currentUser . GetUserId ( ) ?? System . Guid . Empty ;
5053 if ( userId == System . Guid . Empty ) return Results . Unauthorized ( ) ;
51- await mediator . Send ( new MarkNotificationReadCommand ( id , userId ) , ct ) . ConfigureAwait ( false ) ;
52- return Results . NoContent ( ) ;
54+ var result = await mediator . Send ( new MarkNotificationReadCommand ( id , userId ) , ct ) . ConfigureAwait ( false ) ;
55+ return result . ToHttpResult ( ) ;
5356 } ) . WithName ( "MarkNotificationRead" ) ;
5457
5558 notif . MapPost ( "/mark-all-read" , async (
@@ -58,10 +61,36 @@ public static IEndpointRouteBuilder MapNotificationsEndpoints(this IEndpointRout
5861 {
5962 var userId = currentUser . GetUserId ( ) ?? System . Guid . Empty ;
6063 if ( userId == System . Guid . Empty ) return Results . Unauthorized ( ) ;
61- var marked = await mediator . Send ( new MarkAllNotificationsReadCommand ( userId ) , ct ) . ConfigureAwait ( false ) ;
62- return Results . Ok ( new { marked } ) ;
64+ var result = await mediator . Send ( new MarkAllNotificationsReadCommand ( userId ) , ct ) . ConfigureAwait ( false ) ;
65+ return result . ToHttpResult ( ) ;
6366 } ) . WithName ( "MarkAllNotificationsRead" ) ;
6467
68+ notif . MapGet ( "/settings" , async (
69+ ICurrentUserAccessor currentUser ,
70+ IMediator mediator , CancellationToken ct ) =>
71+ {
72+ var userId = currentUser . GetUserId ( ) ?? System . Guid . Empty ;
73+ if ( userId == System . Guid . Empty ) return Results . Unauthorized ( ) ;
74+ var result = await mediator . Send ( new GetMyNotificationSettingsQuery ( userId ) , ct ) . ConfigureAwait ( false ) ;
75+ return result . ToHttpResult ( ) ;
76+ } ) . WithName ( "GetMyNotificationSettings" ) ;
77+
78+ notif . MapPut ( "/settings" , async (
79+ UpdateMyNotificationSettingsRequest body ,
80+ ICurrentUserAccessor currentUser ,
81+ IMediator mediator , CancellationToken ct ) =>
82+ {
83+ var userId = currentUser . GetUserId ( ) ?? System . Guid . Empty ;
84+ if ( userId == System . Guid . Empty ) return Results . Unauthorized ( ) ;
85+ var command = new UpdateMyNotificationSettingsCommand (
86+ userId ,
87+ body . Channel ,
88+ body . IsEnabled ,
89+ body . EventCode ) ;
90+ var result = await mediator . Send ( command , ct ) . ConfigureAwait ( false ) ;
91+ return result . ToHttpResult ( ) ;
92+ } ) . WithName ( "UpdateMyNotificationSettings" ) ;
93+
6594 return app ;
6695 }
6796}
0 commit comments