Skip to content

Commit f11fc4f

Browse files
committed
Some kinds of post actions added to post controller
1 parent 2c7a4ea commit f11fc4f

File tree

143 files changed

+4423
-47
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

143 files changed

+4423
-47
lines changed
Binary file not shown.
Binary file not shown.
Binary file not shown.
0 Bytes
Binary file not shown.

SocialMedia/.vs/SocialMedia/v17/.suo

68 KB
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using SocialMedia.Domain.Entities;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
8+
namespace SocialMedia.Application.Abstractions.Services.PostServices
9+
{
10+
public interface IPostService
11+
{
12+
13+
Task<Post> GetPost(string userName,int postId);
14+
15+
}
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace SocialMedia.Application.Abstractions.Services.UserServices
8+
{
9+
public interface IUserService
10+
{
11+
Task AddFriend(string fromUsernName, string toUserName);
12+
Task AcceptFriend(string accept, string sent);
13+
}
14+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
using MediatR;
2+
using Microsoft.AspNetCore.Identity;
3+
using SocialMedia.Application.Abstractions.Services.PostServices;
4+
using SocialMedia.Application.Repositories.PostRepositories;
5+
using SocialMedia.Domain.Entities;
6+
using System;
7+
using System.Collections.Generic;
8+
using System.Linq;
9+
using System.Text;
10+
using System.Threading.Tasks;
11+
12+
namespace SocialMedia.Application.Features.Commands.PostCommands.PostArchiveCommands
13+
{
14+
public class PostArchiveCommandHandler : IRequestHandler<PostArchiveCommandRequest, PostArchiveCommandResponse>
15+
{
16+
17+
private readonly IPostRepository _postRepository;
18+
private readonly IPostService _postService;
19+
public PostArchiveCommandHandler(IPostRepository postRepository, IPostService postService)
20+
{
21+
_postRepository = postRepository;
22+
_postService = postService;
23+
}
24+
25+
public async Task<PostArchiveCommandResponse> Handle(PostArchiveCommandRequest request, CancellationToken cancellationToken)
26+
{
27+
28+
var post = _postService.GetPost(request.UserName, request.PostId);
29+
30+
if (post == null) throw new Exception("You can't archive this post");
31+
32+
await _postRepository.UnActive(request.PostId);
33+
await _postRepository.CommitAsync();
34+
return new PostArchiveCommandResponse();
35+
}
36+
}
37+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using MediatR;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
8+
namespace SocialMedia.Application.Features.Commands.PostCommands.PostArchiveCommands
9+
{
10+
public class PostArchiveCommandRequest : IRequest<PostArchiveCommandResponse>
11+
{
12+
public string? UserName { get; set; }
13+
public int PostId { get; set; }
14+
}
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace SocialMedia.Application.Features.Commands.PostCommands.PostArchiveCommands
8+
{
9+
public class PostArchiveCommandResponse
10+
{
11+
}
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
using MediatR;
2+
using Microsoft.AspNetCore.Identity;
3+
using SocialMedia.Application.Repositories.CommentRepositories;
4+
using SocialMedia.Application.Repositories.PostRepositories;
5+
using SocialMedia.Domain.Entities;
6+
using System;
7+
using System.Collections.Generic;
8+
using System.Linq;
9+
using System.Text;
10+
using System.Threading.Tasks;
11+
12+
namespace SocialMedia.Application.Features.Commands.PostCommands.PostCommentCommands
13+
{
14+
public class PostCommentCommandHandler : IRequestHandler<PostCommentCommandRequest, PostCommentCommandResponse>
15+
{
16+
private readonly ICommentRepository _commentRepository;
17+
private readonly UserManager<AppUser> _userManager;
18+
private readonly IPostRepository _postRepository;
19+
public PostCommentCommandHandler(ICommentRepository commentRepository, UserManager<AppUser> userManager, IPostRepository postRepository)
20+
{
21+
_commentRepository = commentRepository;
22+
_userManager = userManager;
23+
_postRepository = postRepository;
24+
}
25+
26+
public async Task<PostCommentCommandResponse> Handle(PostCommentCommandRequest request, CancellationToken cancellationToken)
27+
{
28+
var appUser = await _userManager.FindByNameAsync(request.UserName);
29+
30+
var post = await _postRepository.GetAsync(x=>x.Id == request.PostId);
31+
if (post == null) throw new Exception("Couldn't find post");
32+
33+
await _commentRepository.AddAsync(new Comment()
34+
{
35+
PostId = post.Id,
36+
AppUserId = appUser.Id,
37+
Content = request.Content
38+
});
39+
await _commentRepository.CommitAsync();
40+
return new PostCommentCommandResponse();
41+
}
42+
}
43+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using MediatR;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
8+
namespace SocialMedia.Application.Features.Commands.PostCommands.PostCommentCommands
9+
{
10+
public class PostCommentCommandRequest : IRequest<PostCommentCommandResponse>
11+
{
12+
public string? UserName { get; set; }
13+
public string Content { get; set; }
14+
public int PostId { get; set; }
15+
16+
}
17+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace SocialMedia.Application.Features.Commands.PostCommands.PostCommentCommands
8+
{
9+
public class PostCommentCommandResponse
10+
{
11+
}
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
using MediatR;
2+
using Microsoft.AspNetCore.Identity;
3+
using SocialMedia.Application.Repositories.CommentRepositories;
4+
using SocialMedia.Domain.Entities;
5+
using System;
6+
using System.Collections.Generic;
7+
using System.Linq;
8+
using System.Text;
9+
using System.Threading.Tasks;
10+
11+
namespace SocialMedia.Application.Features.Commands.PostCommands.PostCommentRemoveCommands
12+
{
13+
public class PostCommentRemoveCommandHandler : IRequestHandler<PostCommentRemoveCommandRequest, PostCommentRemoveCommandResponse>
14+
{
15+
private readonly ICommentRepository _commentRepository;
16+
private readonly UserManager<AppUser> _userManager;
17+
18+
public PostCommentRemoveCommandHandler(ICommentRepository commentRepository, UserManager<AppUser> userManager)
19+
{
20+
_commentRepository = commentRepository;
21+
_userManager = userManager;
22+
}
23+
24+
public async Task<PostCommentRemoveCommandResponse> Handle(PostCommentRemoveCommandRequest request, CancellationToken cancellationToken)
25+
{
26+
var appUser = await _userManager.FindByNameAsync(request.UserName);
27+
if (appUser == null) throw new Exception("Couldn't find user");
28+
29+
var comment = await _commentRepository.GetAsync(x => x.Id == request.CommentId);
30+
if (comment == null) throw new Exception("Couldn't find comment");
31+
32+
await _commentRepository.Remove(x=>x.Id == comment.Id);
33+
await _commentRepository.CommitAsync();
34+
35+
return new PostCommentRemoveCommandResponse();
36+
}
37+
}
38+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using MediatR;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
8+
namespace SocialMedia.Application.Features.Commands.PostCommands.PostCommentRemoveCommands
9+
{
10+
public class PostCommentRemoveCommandRequest : IRequest<PostCommentRemoveCommandResponse>
11+
{
12+
public string? UserName { get; set; }
13+
public int CommentId { get; set; }
14+
}
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace SocialMedia.Application.Features.Commands.PostCommands.PostCommentRemoveCommands
8+
{
9+
public class PostCommentRemoveCommandResponse
10+
{
11+
}
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
using MediatR;
2+
using Microsoft.AspNetCore.Identity;
3+
using SocialMedia.Application.Abstractions.Services.PostServices;
4+
using SocialMedia.Application.Repositories.PostRepositories;
5+
using SocialMedia.Domain.Entities;
6+
using System;
7+
using System.Collections.Generic;
8+
using System.Linq;
9+
using System.Text;
10+
using System.Threading.Tasks;
11+
12+
namespace SocialMedia.Application.Features.Commands.PostCommands.PostDeleteCommands
13+
{
14+
public class PostDeleteCommandHandler : IRequestHandler<PostDeleteCommandRequest, PostDeleteCommandResponse>
15+
{
16+
private readonly IPostRepository _postRepository;
17+
private readonly IPostService _postService;
18+
public PostDeleteCommandHandler(IPostRepository postRepository, IPostService postService)
19+
{
20+
_postRepository = postRepository;
21+
_postService = postService;
22+
}
23+
24+
public async Task<PostDeleteCommandResponse> Handle(PostDeleteCommandRequest request, CancellationToken cancellationToken)
25+
{
26+
var post = await _postService.GetPost(request.UserName, request.PostId);
27+
28+
if (post == null) throw new Exception("You can't remove this post!");
29+
30+
await _postRepository.Remove(x => x.Id == request.PostId);
31+
await _postRepository.CommitAsync();
32+
33+
return new PostDeleteCommandResponse()
34+
{
35+
36+
};
37+
}
38+
}
39+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using MediatR;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
8+
namespace SocialMedia.Application.Features.Commands.PostCommands.PostDeleteCommands
9+
{
10+
public class PostDeleteCommandRequest : IRequest<PostDeleteCommandResponse>
11+
{
12+
public string? UserName { get; set; }
13+
public int PostId { get; set; }
14+
}
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace SocialMedia.Application.Features.Commands.PostCommands.PostDeleteCommands
8+
{
9+
public class PostDeleteCommandResponse
10+
{
11+
}
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
using MediatR;
2+
using Microsoft.AspNetCore.Identity;
3+
using SocialMedia.Application.Repositories.PostLikeRepositories;
4+
using SocialMedia.Application.Repositories.PostRepositories;
5+
using SocialMedia.Domain.Entities;
6+
using System;
7+
using System.Collections.Generic;
8+
using System.Linq;
9+
using System.Text;
10+
using System.Threading.Tasks;
11+
12+
namespace SocialMedia.Application.Features.Commands.PostCommands.PostLikeCommands
13+
{
14+
public class PostLikeCommandHandler : IRequestHandler<PostLikeCommandRequest, PostLikeCommandResponse>
15+
{
16+
private readonly IPostLikeRepository _postLikeRepository;
17+
private readonly IPostRepository _postRepository;
18+
private readonly UserManager<AppUser> _userManager;
19+
20+
public PostLikeCommandHandler(IPostLikeRepository postLikeRepository, UserManager<AppUser> userManager, IPostRepository postRepository)
21+
{
22+
_postLikeRepository = postLikeRepository;
23+
_userManager = userManager;
24+
_postRepository = postRepository;
25+
}
26+
27+
public async Task<PostLikeCommandResponse> Handle(PostLikeCommandRequest request, CancellationToken cancellationToken)
28+
{
29+
var user = await _userManager.FindByNameAsync(request.UserName);
30+
var post = await _postRepository.GetAsync(x => x.Id == request.PostId);
31+
32+
if (post == null) throw new Exception("Couldn't find post");
33+
34+
await _postLikeRepository.AddAsync(new PostLike
35+
{
36+
PostId = post.Id,
37+
FromUser = user,
38+
});
39+
40+
await _postLikeRepository.CommitAsync();
41+
42+
return new PostLikeCommandResponse()
43+
{
44+
45+
};
46+
}
47+
}
48+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using MediatR;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
8+
namespace SocialMedia.Application.Features.Commands.PostCommands.PostLikeCommands
9+
{
10+
public class PostLikeCommandRequest : IRequest<PostLikeCommandResponse>
11+
{
12+
public int PostId { get; set; }
13+
public string? UserName { get; set; }
14+
}
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace SocialMedia.Application.Features.Commands.PostCommands.PostLikeCommands
8+
{
9+
public class PostLikeCommandResponse
10+
{
11+
}
12+
}

0 commit comments

Comments
 (0)