Changeset 73b69b2 for ChapterX.API/Controllers/NotificationsController.cs
- Timestamp:
- 03/24/26 22:13:36 (3 months ago)
- Branches:
- main
- Children:
- 7fbb91c
- Parents:
- acf690c
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
ChapterX.API/Controllers/NotificationsController.cs
racf690c r73b69b2 1 1 using ChapterX.Application.Notification.Commands; 2 2 using ChapterX.Application.Notification.Queries; 3 using ChapterX.Domain.Repositories; 3 4 using MediatR; 4 5 using Microsoft.AspNetCore.Authorization; … … 13 14 { 14 15 private readonly IMediator _mediator; 16 private readonly INotificationRepository _notificationRepository; 15 17 private readonly ILogger<NotificationsController> _logger; 16 18 17 public NotificationsController(IMediator mediator, I Logger<NotificationsController> logger)19 public NotificationsController(IMediator mediator, INotificationRepository notificationRepository, ILogger<NotificationsController> logger) 18 20 { 19 21 _mediator = mediator; 22 _notificationRepository = notificationRepository; 20 23 _logger = logger; 24 } 25 26 [HttpGet("user/{userId:int}")] 27 [Authorize] 28 public async Task<ActionResult> GetByUser(int userId) 29 { 30 var notifications = await _notificationRepository.GetByUserIdAsync(userId); 31 var result = notifications.Select(n => new 32 { 33 id = n.Id, 34 content = n.Content, 35 isRead = n.IsRead, 36 createdAt = n.CreatedAt, 37 type = n.Type ?? "info", 38 link = n.Link, 39 }); 40 return Ok(result); 41 } 42 43 [HttpPut("{id:int}/read")] 44 [Authorize] 45 public async Task<ActionResult> MarkRead(int id) 46 { 47 var notification = await _notificationRepository.GetByIdAsync(id); 48 if (notification == null) return NotFound(); 49 notification.IsRead = true; 50 await _notificationRepository.UpdateAsync(notification); 51 return Ok(); 21 52 } 22 53
Note:
See TracChangeset
for help on using the changeset viewer.
