Files
Govor/Govor.API/Controllers/InviteController.cs
Artemy 2e9d7e625e Add primitive groups and required channel
Adds server-side group and channel management, private invitations, member moderation, avatar handling, and required-channel configuration. This change also introduces SignalR group profile/member notifications, updates registration to atomically join required channels, and adds EF migration and test coverage for group membership, permissions, and invitation expiry rules.
2026-10-04 10:35:07 +07:00

34 lines
1.3 KiB
C#

using AutoMapper;
using Govor.API.Common.Extensions;
using Govor.API.Hubs.Infrastructure;
using Govor.Application.Groups;
using Govor.Application.Infrastructure.Extensions;
using Govor.Contracts.Responses;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
namespace Govor.API.Controllers;
[ApiController]
[Authorize(Roles = "Admin,User")]
[Route("api/group-invites")]
public class InviteController(IGroupManagementService groups, ICurrentUserService currentUser, IMapper mapper,
IChatNotificationService notifier) : ControllerBase
{
// GET only previews: link scanners/prefetch must not join an account to a group.
[HttpGet("{code}")]
[HttpGet("/invite/{code}")]
public async Task<IActionResult> Preview(string code) => (await groups.PreviewInvitationAsync(currentUser.GetCurrentUserId(), code))
.Map(g => mapper.Map<GroupResponse>(g)).ToActionResult();
[HttpPost("{code}/join")]
[HttpPost("/invite/{code}/join")]
public async Task<IActionResult> Join(string code)
{
var actorId = currentUser.GetCurrentUserId();
var result = await groups.JoinByInvitationAsync(actorId, code);
if (result.IsSuccess) await notifier.NotifyGroupMemberChangedAsync(result.Value.Group.Id, actorId);
return result.Map(g => mapper.Map<GroupResponse>(g)).ToActionResult();
}
}