using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using StickyBoard.Api.Common; using StickyBoard.Core.DTOs.Common; using StickyBoard.Core.DTOs.SocialAndMessaging; using StickyBoard.Core.Services.SocialAndMessaging; using StickyBoard.Core.Services.SocialAndMessaging.Contracts; namespace StickyBoard.Api.Controllers; [ApiController] [Route("api/[controller]")] [Authorize] public sealed class InboxController : ControllerBase { private readonly IInboxMessageService _inbox; public InboxController(InboxMessageService inbox) { _inbox = inbox; } // ------------------------------------------------------------ // SEND DIRECT MESSAGE // ------------------------------------------------------------ [HttpPost] public async Task>> Send( InboxMessageCreateDto dto, CancellationToken ct) { var userId = User.GetUserId(); if (userId == Guid.Empty) return Unauthorized(ApiResponseDto.Fail("Invalid or missing token.")); var msg = await _inbox.SendAsync(userId, dto, ct); return Ok(ApiResponseDto.Ok(msg)); } // ------------------------------------------------------------ // GET MY INBOX // ------------------------------------------------------------ [HttpGet] public async Task>>> GetMyInbox(CancellationToken ct) { var userId = User.GetUserId(); if (userId == Guid.Empty) return Unauthorized(ApiResponseDto>.Fail("Invalid or missing token.")); var list = await _inbox.GetForUserAsync(userId, ct); return Ok(ApiResponseDto>.Ok(list)); } // ------------------------------------------------------------ // MARK AS READ // ------------------------------------------------------------ [HttpPut("{id:guid}/read")] public async Task>> MarkAsRead(Guid id, CancellationToken ct) { var ok = await _inbox.MarkAsReadAsync(id, ct); return ok ? Ok(ApiResponseDto.Ok(new { success = true })) : NotFound(ApiResponseDto.Fail("Message not found or already read.")); } }