Skip to content

Commit

Permalink
fix(AAiT-backend-1A): Refactor Comment Handler (#462)
Browse files Browse the repository at this point in the history
  • Loading branch information
nahom4 authored Sep 4, 2023
1 parent d9a936e commit 1226106
Show file tree
Hide file tree
Showing 12 changed files with 14 additions and 84 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,4 @@ public interface IAuthRepository{

Task<bool> UserExists(string username);


}
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public async Task<BaseResponse<CommentResponseDTO>> Handle(CommentCreateCommand
await _mediator.Send(new CreateNotification {
NotificationData = new NotificationCreateDTO()
{
Content = "A Comment has been given on your post",
Content = $"User with Id {request.userId} commented on your post with Id {request.NewCommentData.PostId}",
NotificationContentId = result.Id,
NotificationType = NotificationEnum.COMMENT,
UserId = post.UserId
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public async Task<BaseResponse<int>> Handle(CommentDeleteCommand request, Cancel

await _mediator.Send(new CreateNotification {NotificationData = new NotificationCreateDTO()
{
Content = "A comment on your post has been removed",
Content = $"A comment on your post made by user with Id {request.userId} has been removed",
NotificationContentId = comment.Id,
NotificationType = NotificationEnum.COMMENT,
UserId = post.UserId
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public async Task<BaseResponse<CommentResponseDTO>> Handle(UpdateCommentCommand

await _mediator.Send(new CreateNotification {NotificationData = new NotificationCreateDTO()
{
Content = "A comment on your post has been Updated",
Content = $"A comment on your post made by user with id {request.userId} has been Updated",
NotificationContentId = comment.Id,
NotificationType = NotificationEnum.COMMENT,
UserId = post.UserId}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,6 @@ public async Task<BaseResponse<int>> Handle(MakeReactionOnComment request, Cance
throw new BadRequestException("Comment is not found");
}

await _mediator.Send(new CreateNotification {
NotificationData = new NotificationCreateDTO()
{
Content = $"User with {request.UserId} reacted on your comment",
NotificationType = NotificationEnum.COMMENTREACTION,
UserId = request.UserId}
}
);

return new BaseResponse<int>()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public async Task<BaseResponse<int>> Handle(CreateFollowCommand request, Cancell

await _mediator.Send(new CreateNotification {NotificationData = new NotificationCreateDTO()
{
Content = $"The user with {request.FollowDTO.FollowerId} is currently following you",
Content = $"The user with Id {request.FollowDTO.FollowerId} is currently following you",
NotificationType = NotificationEnum.FOLLOW,
UserId = request.FollowDTO.FolloweeId}});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,14 @@ public async Task<BaseResponse<int>> Handle(DeleteFollowCommand request, Cancell

await _mediator.Send(new CreateNotification {NotificationData = new NotificationCreateDTO()
{
Content = $"The user with {request.FollowDTO.FollowerId} has currently un followed you",
Content = $"The user with Id {request.FollowDTO.FollowerId} has currently un followed you",
NotificationType = NotificationEnum.FOLLOW,
UserId = request.FollowDTO.FolloweeId
}});


createFollowResponse.Success = true;
createFollowResponse.Message = $"User with Id {followEntity.FollowerId} has un followed you";
createFollowResponse.Message = $"You have unfollowed the user with Id {request.FollowDTO.FolloweeId}";
createFollowResponse.Value = followEntity.FolloweeId;
return createFollowResponse;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public async Task<BaseResponse<PostResponseDTO>> Handle(CreatePostCommand reques

if (tagEntity == null)
{
var newTag = new Tag
var newTag = new Tag()
{
Title = tag
};
Expand All @@ -78,7 +78,7 @@ await _mediator.Send(
new CreateNotification () {
NotificationData = new NotificationCreateDTO()
{
Content = "A Post has been Created",
Content = $"User with Id {request.userId} has created a post",
NotificationContentId = result.Id,
NotificationType = NotificationEnum.POST,
UserId = request.userId
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ public TagReposiotry(SocialMediaDbContext socialMediaDbContext)
}
public Task<Tag> Add(Tag entity)
{
throw new NotImplementedException();
_socialMediaDbContext.Tags.Add(entity);
_socialMediaDbContext.SaveChanges();
return Task.FromResult(entity);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public async Task<ActionResult<BaseResponse<List<ReactionResponseDTO>>>> GetDisl
public async Task<ActionResult<BaseResponse<int>>> Post([FromBody] ReactionDTO reactionData)
{
var userId = int.Parse(User.FindFirst(ClaimTypes.NameIdentifier)!.Value);
var result = await _mediator.Send(new MakeReactionOnComment{ UserId = 3, ReactionData = reactionData });
var result = await _mediator.Send(new MakeReactionOnComment{ UserId = userId, ReactionData = reactionData });

return Ok(result);
}
Expand Down
4 changes: 2 additions & 2 deletions aait/backend/group-1A/WebApi/Controllers/PostController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ public async Task<ActionResult<BaseResponse<CommentResponseDTO>>> Delete(int id)
}

[HttpGet("/tag/{tagname}")]
public async Task<ActionResult<BaseResponse<PostResponseDTO>>> GetByTagName(GetPostsByTagQuery query){
var result = await _mediator.Send(query);
public async Task<ActionResult<BaseResponse<PostResponseDTO>>> GetByTagName(string tagname){
var result = await _mediator.Send(new GetPostsByTagQuery { TagName = tagname });
return Ok(result);
}

Expand Down
63 changes: 0 additions & 63 deletions aait/backend/group-1A/WebApi/Controllers/TagController.cs

This file was deleted.

0 comments on commit 1226106

Please sign in to comment.