too many changes
This commit is contained in:
@@ -1,15 +1,12 @@
|
||||
using MediatR;
|
||||
using MemeVault.Api.Auth;
|
||||
using MemeVault.Application.Commands.CloneCollection;
|
||||
using MemeVault.Application.Commands.CreateCollection;
|
||||
using MemeVault.Application.Commands.CreateCollectionInvite;
|
||||
using MemeVault.Application.Commands.DeleteCollection;
|
||||
using MemeVault.Application.Commands.RevokeCollectionInvite;
|
||||
using MemeVault.Application.Commands.CloneCollection;
|
||||
using MemeVault.Application.Commands.RegenerateShareLink;
|
||||
using MemeVault.Application.Commands.JoinPublicCollection;
|
||||
using MemeVault.Application.Commands.SetCollectionInbox;
|
||||
using MemeVault.Application.Commands.SetCollectionNsfw;
|
||||
using MemeVault.Application.Commands.ShareCollection;
|
||||
using MemeVault.Application.Commands.RegenerateShareLink;
|
||||
using MemeVault.Application.Commands.RevokeCollectionInvite;
|
||||
using MemeVault.Application.Commands.UpdateCollection;
|
||||
using MemeVault.Application.Queries.GetCollectionInvites;
|
||||
using MemeVault.Application.Queries.GetCollectionItems;
|
||||
@@ -47,17 +44,27 @@ public sealed class CollectionsController(IMediator mediator, CurrentUser curren
|
||||
}
|
||||
|
||||
// PATCH /api/collections/{id}
|
||||
// Обновляет имя, описание, nsfw-флаг, видимость.
|
||||
// Всегда возвращает { shareToken } — null, если коллекция Private.
|
||||
[HttpPatch("{id:guid}")]
|
||||
[ProducesResponseType(typeof(UpdateCollectionResponse), StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
||||
public async Task<IActionResult> Update(
|
||||
Guid id,
|
||||
[FromBody] UpdateCollectionRequest request,
|
||||
CancellationToken ct)
|
||||
{
|
||||
var ok = await mediator.Send(
|
||||
new UpdateCollectionCommand(id, currentUser.TelegramId, request.Name, request.Description),
|
||||
var result = await mediator.Send(
|
||||
new UpdateCollectionCommand(
|
||||
id,
|
||||
currentUser.TelegramId,
|
||||
request.Name,
|
||||
request.Description,
|
||||
request.IsNsfw,
|
||||
request.Visibility),
|
||||
ct);
|
||||
|
||||
return ok ? NoContent() : NotFound();
|
||||
return result is null ? NotFound() : Ok(new UpdateCollectionResponse(result.ShareToken));
|
||||
}
|
||||
|
||||
// DELETE /api/collections/{id}
|
||||
@@ -140,28 +147,6 @@ public sealed class CollectionsController(IMediator mediator, CurrentUser curren
|
||||
return ok ? NoContent() : NotFound();
|
||||
}
|
||||
|
||||
// PUT /api/collections/{id}/inbox
|
||||
[HttpPut("{id:guid}/inbox")]
|
||||
public async Task<IActionResult> SetInbox(Guid id, CancellationToken ct)
|
||||
{
|
||||
var ok = await mediator.Send(new SetCollectionInboxCommand(id, currentUser.TelegramId), ct);
|
||||
return ok ? NoContent() : NotFound();
|
||||
}
|
||||
|
||||
// PUT /api/collections/{id}/nsfw
|
||||
[HttpPut("{id:guid}/nsfw")]
|
||||
public async Task<IActionResult> SetNsfw(
|
||||
Guid id,
|
||||
[FromBody] SetNsfwRequest request,
|
||||
CancellationToken ct)
|
||||
{
|
||||
var ok = await mediator.Send(
|
||||
new SetCollectionNsfwCommand(id, currentUser.TelegramId, request.IsNsfw),
|
||||
ct);
|
||||
|
||||
return ok ? NoContent() : NotFound();
|
||||
}
|
||||
|
||||
// POST /api/collections/{id}/share-link/regenerate
|
||||
[HttpPost("{id:guid}/share-link/regenerate")]
|
||||
[ProducesResponseType(typeof(object), StatusCodes.Status200OK)]
|
||||
@@ -173,24 +158,16 @@ public sealed class CollectionsController(IMediator mediator, CurrentUser curren
|
||||
|
||||
return token is null ? NotFound() : Ok(new { shareToken = token });
|
||||
}
|
||||
|
||||
// PUT /api/collections/{id}/visibility
|
||||
[HttpPut("{id:guid}/visibility")]
|
||||
public async Task<IActionResult> SetVisibility(
|
||||
Guid id,
|
||||
[FromBody] SetVisibilityRequest request,
|
||||
CancellationToken ct)
|
||||
{
|
||||
var shareToken = await mediator.Send(
|
||||
new ShareCollectionCommand(id, currentUser.TelegramId, request.Visibility),
|
||||
ct);
|
||||
|
||||
return Ok(new { shareToken });
|
||||
}
|
||||
}
|
||||
|
||||
public sealed record CreateCollectionRequest(string Name, string? Description);
|
||||
public sealed record UpdateCollectionRequest(string Name, string? Description);
|
||||
public sealed record SetNsfwRequest(bool IsNsfw);
|
||||
public sealed record SetVisibilityRequest(CollectionVisibility Visibility);
|
||||
|
||||
public sealed record UpdateCollectionRequest(
|
||||
string Name,
|
||||
string? Description,
|
||||
bool? IsNsfw = null,
|
||||
CollectionVisibility? Visibility = null);
|
||||
|
||||
public sealed record UpdateCollectionResponse(string? ShareToken);
|
||||
|
||||
public sealed record CreateInviteRequest(CollectionRole Role, DateTimeOffset? ExpiresAt = null);
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
using MediatR;
|
||||
using MemeVault.Api.Auth;
|
||||
using MemeVault.Application.Commands.SetCollectionInbox;
|
||||
using MemeVault.Application.Queries.GetCurrentUser;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace MemeVault.Api.Controllers;
|
||||
|
||||
[ApiController]
|
||||
[Authorize]
|
||||
[Route("api/me")]
|
||||
public sealed class MeController(IMediator mediator, CurrentUser currentUser) : ControllerBase
|
||||
{
|
||||
// GET /api/me
|
||||
[HttpGet]
|
||||
[ProducesResponseType(typeof(CurrentUserDto), StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
||||
public async Task<IActionResult> GetMe(CancellationToken ct)
|
||||
{
|
||||
var result = await mediator.Send(new GetCurrentUserQuery(currentUser.TelegramId), ct);
|
||||
return result is null ? NotFound() : Ok(result);
|
||||
}
|
||||
|
||||
// PATCH /api/me
|
||||
[HttpPatch]
|
||||
[ProducesResponseType(StatusCodes.Status204NoContent)]
|
||||
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
||||
public async Task<IActionResult> PatchMe(
|
||||
[FromBody] PatchMeRequest request,
|
||||
CancellationToken ct)
|
||||
{
|
||||
if (request.InboxCollectionId.HasValue)
|
||||
{
|
||||
var ok = await mediator.Send(
|
||||
new SetCollectionInboxCommand(request.InboxCollectionId.Value, currentUser.TelegramId), ct);
|
||||
|
||||
if (!ok) return NotFound();
|
||||
}
|
||||
|
||||
return NoContent();
|
||||
}
|
||||
}
|
||||
|
||||
public sealed record PatchMeRequest(Guid? InboxCollectionId);
|
||||
@@ -2,11 +2,13 @@ using MediatR;
|
||||
using MemeVault.Api.Auth;
|
||||
using MemeVault.Application.Commands.CopyMediaToCollection;
|
||||
using MemeVault.Application.Commands.DeleteMedia;
|
||||
using MemeVault.Application.Commands.SaveMedia;
|
||||
using MemeVault.Application.Commands.UpdateMedia;
|
||||
using MemeVault.Application.Commands.SendMediaToChat;
|
||||
using MemeVault.Application.Queries.GetMediaDownloadUrl;
|
||||
using MemeVault.Application.Queries.GetUserMedia;
|
||||
using MemeVault.Application.Queries.SearchMedia;
|
||||
using MemeVault.Domain.Enums;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
@@ -17,15 +19,39 @@ namespace MemeVault.Api.Controllers;
|
||||
[Route("api/[controller]")]
|
||||
public sealed class MediaController(IMediator mediator, CurrentUser currentUser) : ControllerBase
|
||||
{
|
||||
// GET /api/media?q=...&includeNsfw=true
|
||||
// POST /api/media
|
||||
// Создаёт текстовую запись напрямую из Mini App (без бота).
|
||||
[HttpPost]
|
||||
public async Task<IActionResult> Create(
|
||||
[FromBody] CreateMediaRequest request,
|
||||
CancellationToken ct)
|
||||
{
|
||||
var tags = (request.Tags ?? [])
|
||||
.Select(t => t.TrimStart('#').Trim().ToLowerInvariant())
|
||||
.Where(t => t.Length > 0)
|
||||
.ToList();
|
||||
|
||||
var id = await mediator.Send(
|
||||
new SaveMediaCommand(
|
||||
currentUser.TelegramId,
|
||||
Source: null,
|
||||
MediaType: MediaType.Text,
|
||||
Caption: request.Caption?.Trim(),
|
||||
Tags: tags),
|
||||
ct);
|
||||
|
||||
return CreatedAtAction(nameof(GetAll), new { id }, new { id });
|
||||
}
|
||||
|
||||
// GET /api/media?q=...&includeNsfw=false
|
||||
[HttpGet]
|
||||
public async Task<IActionResult> GetAll(
|
||||
[FromQuery] string? q,
|
||||
[FromQuery] bool includeNsfw = true,
|
||||
[FromQuery] bool includeNsfw = false,
|
||||
CancellationToken ct = default)
|
||||
{
|
||||
var items = string.IsNullOrWhiteSpace(q)
|
||||
? await mediator.Send(new GetUserMediaQuery(currentUser.TelegramId), ct)
|
||||
? await mediator.Send(new GetUserMediaQuery(currentUser.TelegramId, includeNsfw), ct)
|
||||
: await mediator.Send(new SearchMediaQuery(currentUser.TelegramId, q, IncludeNsfw: includeNsfw), ct);
|
||||
|
||||
return Ok(items);
|
||||
@@ -65,7 +91,8 @@ public sealed class MediaController(IMediator mediator, CurrentUser currentUser)
|
||||
CancellationToken ct)
|
||||
{
|
||||
var ok = await mediator.Send(
|
||||
new UpdateMediaCommand(id, currentUser.TelegramId, request.Caption, request.Tags, request.CollectionId),
|
||||
new UpdateMediaCommand(id, currentUser.TelegramId, request.Caption, request.Tags, request.CollectionId,
|
||||
request.InlineTitle, request.InlineDescription),
|
||||
ct);
|
||||
|
||||
return ok ? NoContent() : NotFound();
|
||||
@@ -97,12 +124,16 @@ public sealed class MediaController(IMediator mediator, CurrentUser currentUser)
|
||||
}
|
||||
}
|
||||
|
||||
public sealed record CreateMediaRequest(string? Caption, IReadOnlyList<string>? Tags);
|
||||
|
||||
public sealed record SendToChatRequest(string QueryId);
|
||||
|
||||
public sealed record UpdateMediaRequest(
|
||||
string? Caption,
|
||||
IReadOnlyList<string> Tags,
|
||||
Guid? CollectionId = null
|
||||
Guid? CollectionId = null,
|
||||
string? InlineTitle = null,
|
||||
string? InlineDescription = null
|
||||
);
|
||||
|
||||
public sealed record CopyMediaRequest(Guid TargetCollectionId);
|
||||
|
||||
Reference in New Issue
Block a user