-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #29 from Alper-Soy/develop
Prod - 08/25/2024 - 3
- Loading branch information
Showing
35 changed files
with
1,062 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
using Application.Features.Comments.Commands.CreateComment; | ||
using Application.Features.Comments.Queries.GetComments; | ||
using MediatR; | ||
using Microsoft.AspNetCore.SignalR; | ||
|
||
namespace API.SignalR; | ||
|
||
public class ChatHub(IMediator mediator) : Hub | ||
{ | ||
public async Task SendComment(CreateCommentCommand command) | ||
{ | ||
var comment = await mediator.Send(command); | ||
|
||
await Clients.Group(command.ActivityId.ToString()).SendAsync("ReceiveComment", comment.Value); | ||
} | ||
|
||
public override async Task OnConnectedAsync() | ||
{ | ||
var httpContext = Context.GetHttpContext(); | ||
var activityId = httpContext!.Request.Query["activityId"]; | ||
await Groups.AddToGroupAsync(Context.ConnectionId, activityId); | ||
var result = await mediator.Send(new GetCommentsQuery { ActivityId = Guid.Parse(activityId) }); | ||
await Clients.Caller.SendAsync("LoadComments", result.Value); | ||
} | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
Application/Features/Comments/Commands/CreateComment/CreateCommandHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
using Application.Core; | ||
using Application.Features.Comments.Contracts; | ||
using Application.Interfaces; | ||
using AutoMapper; | ||
using Domain.Entities; | ||
using MediatR; | ||
using Microsoft.EntityFrameworkCore; | ||
using Persistence; | ||
|
||
namespace Application.Features.Comments.Commands.CreateComment; | ||
|
||
public class CreateCommandHandler(DataContext context, IMapper mapper, IUserAccessor userAccessor) | ||
: IRequestHandler<CreateCommentCommand, Result<CommentDto>> | ||
{ | ||
public async Task<Result<CommentDto>> Handle(CreateCommentCommand request, CancellationToken cancellationToken) | ||
{ | ||
var activity = await context.Activities.FindAsync(request.ActivityId); | ||
|
||
if (activity == null) return null; | ||
|
||
var user = await context.Users.Include(p => p.Photos) | ||
.SingleOrDefaultAsync(x => x.UserName == userAccessor.GetUsername()); | ||
|
||
var comment = new Comment | ||
{ | ||
Author = user, | ||
Activity = activity, | ||
Body = request.Body | ||
}; | ||
|
||
activity.Comments.Add(comment); | ||
|
||
var success = await context.SaveChangesAsync() > 0; | ||
|
||
return success | ||
? Result<CommentDto>.Success(mapper.Map<CommentDto>(comment)) | ||
: Result<CommentDto>.Failure("Failed to add comment"); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
Application/Features/Comments/Commands/CreateComment/CreateCommentCommand.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
using Application.Core; | ||
using Application.Features.Comments.Contracts; | ||
using MediatR; | ||
|
||
namespace Application.Features.Comments.Commands.CreateComment; | ||
|
||
public class CreateCommentCommand : IRequest<Result<CommentDto>> | ||
{ | ||
public string Body { get; set; } | ||
public Guid ActivityId { get; set; } | ||
} |
11 changes: 11 additions & 0 deletions
11
Application/Features/Comments/Commands/CreateComment/CreateCommentValidator.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
using FluentValidation; | ||
|
||
namespace Application.Features.Comments.Commands.CreateComment; | ||
|
||
public class CreateCommentValidator : AbstractValidator<CreateCommentCommand> | ||
{ | ||
public CreateCommentValidator() | ||
{ | ||
RuleFor(x => x.Body).NotEmpty(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
namespace Application.Features.Comments.Contracts; | ||
|
||
public class CommentDto | ||
{ | ||
public int Id { get; set; } | ||
public DateTime CreatedAt { get; set; } | ||
public string Body { get; set; } | ||
public string Username { get; set; } | ||
public string DisplayName { get; set; } | ||
public string Image { get; set; } | ||
} |
24 changes: 24 additions & 0 deletions
24
Application/Features/Comments/Queries/GetComments/GetCommentsHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using Application.Core; | ||
using Application.Features.Comments.Contracts; | ||
using AutoMapper; | ||
using AutoMapper.QueryableExtensions; | ||
using MediatR; | ||
using Microsoft.EntityFrameworkCore; | ||
using Persistence; | ||
|
||
namespace Application.Features.Comments.Queries.GetComments; | ||
|
||
public class GetCommentsHandler(DataContext context, IMapper mapper) | ||
: IRequestHandler<GetCommentsQuery, Result<List<CommentDto>>> | ||
{ | ||
public async Task<Result<List<CommentDto>>> Handle(GetCommentsQuery request, CancellationToken cancellationToken) | ||
{ | ||
var comments = await context.Comments | ||
.Where(x => x.Activity.Id == request.ActivityId) | ||
.OrderByDescending(x => x.CreatedAt) | ||
.ProjectTo<CommentDto>(mapper.ConfigurationProvider) | ||
.ToListAsync(); | ||
|
||
return Result<List<CommentDto>>.Success(comments); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
Application/Features/Comments/Queries/GetComments/GetCommentsQuery.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
using Application.Core; | ||
using Application.Features.Comments.Contracts; | ||
using MediatR; | ||
|
||
namespace Application.Features.Comments.Queries.GetComments; | ||
|
||
public class GetCommentsQuery : IRequest<Result<List<CommentDto>>> | ||
{ | ||
public Guid ActivityId { get; set; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 6 additions & 5 deletions
11
Application/Features/Profiles/Queries/GetProfile/GetProfileHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,22 @@ | ||
using Application.Core; | ||
using Application.Features.Profiles.Contracts; | ||
using AutoMapper; | ||
using AutoMapper.QueryableExtensions; | ||
using MediatR; | ||
using Microsoft.EntityFrameworkCore; | ||
using Persistence; | ||
using Profile = Application.Features.Profiles.Contracts.Profile; | ||
|
||
namespace Application.Features.Profiles.Queries.GetProfile; | ||
|
||
public class GetProfileHandler(DataContext context, IMapper mapper) : IRequestHandler<GetProfileQuery, Result<Profile>> | ||
public class GetProfileHandler(DataContext context, IMapper mapper) | ||
: IRequestHandler<GetProfileQuery, Result<ProfileDto>> | ||
{ | ||
public async Task<Result<Profile>> Handle(GetProfileQuery request, CancellationToken cancellationToken) | ||
public async Task<Result<ProfileDto>> Handle(GetProfileQuery request, CancellationToken cancellationToken) | ||
{ | ||
var user = await context.Users | ||
.ProjectTo<Profile>(mapper.ConfigurationProvider) | ||
.ProjectTo<ProfileDto>(mapper.ConfigurationProvider) | ||
.SingleOrDefaultAsync(x => x.Username == request.Username); | ||
|
||
return Result<Profile>.Success(user); | ||
return Result<ProfileDto>.Success(user); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
namespace Domain.Entities; | ||
|
||
public class Comment | ||
{ | ||
public int Id { get; set; } | ||
public string Body { get; set; } | ||
public User Author { get; set; } | ||
public Activity Activity { get; set; } | ||
public DateTime CreatedAt { get; set; } = DateTime.UtcNow; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.