29 lines
928 B
C#
29 lines
928 B
C#
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using QMax.Api.Contracts;
|
|
using QMax.Api.Infrastructure.Max;
|
|
|
|
namespace QMax.Api.Controllers;
|
|
|
|
[ApiController]
|
|
[Authorize]
|
|
[Route("api/contacts")]
|
|
public sealed class ContactsController(IMaxBridgeClient maxBridge) : ControllerBase
|
|
{
|
|
[HttpGet]
|
|
public async Task<ActionResult<IReadOnlyList<ContactDto>>> GetContacts(CancellationToken cancellationToken)
|
|
{
|
|
var contacts = await maxBridge.FetchContactsAsync(cancellationToken);
|
|
return contacts
|
|
.Select(contact => new ContactDto(
|
|
contact.UserId,
|
|
contact.ExternalChatId,
|
|
contact.DisplayName,
|
|
contact.AvatarUrl,
|
|
contact.PhoneNumber,
|
|
contact.Status))
|
|
.OrderBy(contact => contact.DisplayName, StringComparer.CurrentCultureIgnoreCase)
|
|
.ToArray();
|
|
}
|
|
}
|