Переделаны истории
This commit is contained in:
@@ -22,15 +22,15 @@ internal sealed class FriendshipRepository : IFriendshipRepository
|
||||
|
||||
public async Task<List<Knot.Contracts.Relations.Domain.Friendship>> GetAcceptedFriendshipsAsync(Guid userId, CancellationToken ct = default)
|
||||
{
|
||||
var friendships = await _context.Set<Knot.Modules.Relations.Domain.Friendship>()
|
||||
.Where(f => f.Status == Knot.Contracts.Relations.Domain.FriendshipStatus.Accepted && (f.UserId == userId || f.FriendId == userId))
|
||||
var contacts = await _context.Contacts
|
||||
.Where(f => f.Status == ContactStatus.Accepted && (f.UserId == userId || f.ContactId == userId))
|
||||
.ToListAsync(ct);
|
||||
|
||||
return friendships.Select(f => new Knot.Contracts.Relations.Domain.Friendship(
|
||||
return contacts.Select(f => new Knot.Contracts.Relations.Domain.Friendship(
|
||||
f.Id,
|
||||
f.UserId,
|
||||
f.FriendId,
|
||||
f.Status,
|
||||
f.ContactId,
|
||||
(Knot.Contracts.Relations.Domain.FriendshipStatus)f.Status,
|
||||
f.CreatedAt
|
||||
)).ToList();
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ public static class DependencyInjection
|
||||
{
|
||||
services.AddScoped<IStoryRepository, StoryRepository>();
|
||||
services.AddScoped<IUserRepository, UserRepository>();
|
||||
services.AddScoped<IStoryNotificationService, StoryNotificationService>();
|
||||
services.AddScoped<Knot.Contracts.Stories.Infrastructure.Persistence.IStoryCollection, StoryCollection>();
|
||||
|
||||
var connectionString = configuration.GetConnectionString("DefaultConnection");
|
||||
|
||||
@@ -1,3 +1,7 @@
|
||||
using Knot.Modules.Stories.Application.Stories.Commands.AddStoryReaction;
|
||||
using Knot.Modules.Stories.Application.Stories.Commands.AddStoryReply;
|
||||
using Knot.Modules.Stories.Application.Stories.Commands.RemoveStoryReaction;
|
||||
using Knot.Modules.Stories.Application.Stories.Queries.GetStoryReplies;
|
||||
using Knot.Modules.Stories.Application.DTOs;
|
||||
using Knot.Modules.Stories.Application.Stories.Commands.CreateStory;
|
||||
using Knot.Modules.Stories.Application.Stories.Commands.DeleteStory;
|
||||
@@ -15,6 +19,9 @@ using Microsoft.AspNetCore.Routing;
|
||||
|
||||
namespace Knot.Modules.Stories.Presentation.Endpoints;
|
||||
|
||||
public record AddReactionRequest(string Emoji);
|
||||
public record AddReplyRequest(string Content);
|
||||
|
||||
public static class StoriesEndpoints
|
||||
{
|
||||
public static void MapStoriesEndpoints(this WebApplication app)
|
||||
@@ -64,6 +71,30 @@ public static class StoriesEndpoints
|
||||
return Results.Ok(result.Value);
|
||||
});
|
||||
|
||||
group.MapPost("{id:guid}/reaction", async ([FromRoute] Guid id, [FromBody] AddReactionRequest req, ISender sender, IUserContext userContext, CancellationToken ct) =>
|
||||
{
|
||||
var result = await sender.Send(new AddStoryReactionCommand(userContext.UserId, id, req.Emoji), ct);
|
||||
return result.IsSuccess ? Results.Ok(new { message = "Reaction added" }) : Results.NotFound();
|
||||
});
|
||||
|
||||
group.MapPost("{id:guid}/reaction/delete", async ([FromRoute] Guid id, [FromQuery] string emoji, ISender sender, IUserContext userContext, CancellationToken ct) =>
|
||||
{
|
||||
var result = await sender.Send(new RemoveStoryReactionCommand(userContext.UserId, id, emoji), ct);
|
||||
return result.IsSuccess ? Results.Ok(new { message = "Reaction removed" }) : Results.NotFound();
|
||||
});
|
||||
|
||||
group.MapPost("{id:guid}/reply", async ([FromRoute] Guid id, [FromBody] AddReplyRequest req, ISender sender, IUserContext userContext, CancellationToken ct) =>
|
||||
{
|
||||
var result = await sender.Send(new AddStoryReplyCommand(userContext.UserId, id, req.Content), ct);
|
||||
return result.IsSuccess ? Results.Ok(new { message = "Reply added" }) : Results.NotFound();
|
||||
});
|
||||
|
||||
group.MapGet("{id:guid}/replies", async ([FromRoute] Guid id, ISender sender, IUserContext userContext, CancellationToken ct) =>
|
||||
{
|
||||
var result = await sender.Send(new GetStoryRepliesQuery(userContext.UserId, id), ct);
|
||||
return result.IsSuccess ? Results.Ok(result.Value) : Results.NotFound();
|
||||
});
|
||||
|
||||
group.MapDelete("{id:guid}", async ([FromRoute] Guid id, ISender sender, IUserContext userContext, CancellationToken ct) =>
|
||||
{
|
||||
var result = await sender.Send(new DeleteStoryCommand(userContext.UserId, id), ct);
|
||||
|
||||
Reference in New Issue
Block a user