Ignore:
Timestamp:
03/24/26 22:13:36 (3 months ago)
Author:
kikisrbinoska <srbinoskakristina07@…>
Branches:
main
Children:
7fbb91c
Parents:
acf690c
Message:

Fixed reading lists,comments and likes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • ChapterX.API/Controllers/NotificationsController.cs

    racf690c r73b69b2  
    11using ChapterX.Application.Notification.Commands;
    22using ChapterX.Application.Notification.Queries;
     3using ChapterX.Domain.Repositories;
    34using MediatR;
    45using Microsoft.AspNetCore.Authorization;
     
    1314    {
    1415        private readonly IMediator _mediator;
     16        private readonly INotificationRepository _notificationRepository;
    1517        private readonly ILogger<NotificationsController> _logger;
    1618
    17         public NotificationsController(IMediator mediator, ILogger<NotificationsController> logger)
     19        public NotificationsController(IMediator mediator, INotificationRepository notificationRepository, ILogger<NotificationsController> logger)
    1820        {
    1921            _mediator = mediator;
     22            _notificationRepository = notificationRepository;
    2023            _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();
    2152        }
    2253
Note: See TracChangeset for help on using the changeset viewer.