Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Aastu.web.g1.yoseph.shemeles.homepage #261

Open
wants to merge 32 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
0fd66c6
feat(aastu.web):Homepage-stories-responsivness
jossyfresh Aug 25, 2023
3e521cf
feat(aastu.web.g1):blog page responsiveness
jossyfresh Aug 25, 2023
4ded1c5
feat(aaastu.web.g1):additional features
jossyfresh Aug 25, 2023
ab2dcdc
Update pr_title_check.yml
bruk-tedla-a2sv Aug 25, 2023
deb96a8
feat(AAiT-mobile-2): Add Article Create/Update and Detail Screen (#222)
meraf00 Aug 25, 2023
1833db5
feat(AASTU-web-G2): Some cleaning up (#228)
natanim-ashenafi Aug 25, 2023
a3f7133
aastu.web.g2.natanim ashenafi.some cleaning up (#232)
natanim-ashenafi Aug 25, 2023
3533639
fix(AASTU-web-G2): Route some links (#233)
natanim-ashenafi Aug 25, 2023
16f6367
feat(aastu.web):Homepage-stories-responsivness (#229)
yoseph-shemeles-a2sv Aug 25, 2023
38f73b0
feat(aait.web.g3):Add redux store config (#221)
yohannes-07 Aug 25, 2023
6542674
(AASTU-web_g1): teampage completed (#234)
ruth-wossen-a2sv Aug 25, 2023
5a358df
feat(aait.web.g3):Add blogs api, blog detail api and create blog api …
yohannes-07 Aug 25, 2023
db6da1e
feat(aait-mobile-g2): implement bloc for authentication feature (#224)
Temesgenzewude Aug 25, 2023
72da4a8
feat(AAiT.mob.g2): add user bloc (#226)
NaolAklilu Aug 25, 2023
d3dd575
Yohanse.auth.data (#236)
yohanse Aug 25, 2023
94b7e40
feat(AAiT-web_g3): add login and register page (#174)
dawit-andargachew Aug 25, 2023
2312999
aait.mobile.g3.abinet_onboarding_pages (#206)
abi26anamo Aug 25, 2023
d5c21cb
feat(aait-backend-2b.authentication): Add DTOs, Mocks for tesing and …
ffekirnew Aug 25, 2023
06ce67e
feat(AAiT-backend-1B) : add notifications for likes and comment creat…
AnaniyaT Aug 25, 2023
c47eb79
Feat(AASTU-Web-G2): fix teams page (#247)
abel-getahun-a2sv Aug 25, 2023
fa99abd
feat(aastu-web-g1): profile pages integration done (#246)
zerubabel-kassahun-a2sv Aug 25, 2023
fa7177f
Aastu.ruth.wossen.team.page (#249)
ruth-wossen-a2sv Aug 25, 2023
b38e6a8
feat(AAit-mobile-g3): add presentaion bloc layer (#251)
yohanse Aug 25, 2023
1d3a11a
feat(aait.web.g3): Add blog detail page (#213)
yohannes-07 Aug 25, 2023
8576655
fix(aastu-web-g1): fixed inner html in blog details (#253)
zerubabel-kassahun-a2sv Aug 25, 2023
7195fc8
feat(AAiT-web_g3): pofile pages added (#187)
dawit-andargachew Aug 25, 2023
c031457
Ketema.homepage (#65)
Ketema741 Aug 25, 2023
c2fa35f
fix(aastu.web.g2):fix_header (#259)
Naolt Aug 25, 2023
564d47e
feat(AAiT-Mobile-3): Add functional dep. injection (#230)
primequantuM4 Aug 25, 2023
65bb8ec
fix(aastu-web-g1): fixed some ui (#260)
zerubabel-kassahun-a2sv Aug 25, 2023
a848590
fix(aastu.web.g2):fix single blog (#262)
Naolt Aug 25, 2023
f7bf80e
feat(aaastu.web.g1):additional features
jossyfresh Aug 25, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/pr_title_check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ on:
jobs:
publish:
name: PR Title Check
runs-on: ubuntu-18.04
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v1
- uses: dylanvann/check-pull-request-title@v1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public interface IPostLikesRepository
Task<bool> Exists(int userId, int postId);
Task Delete(PostLike like);
Task<PostLike> Add(PostLike like);
Task ChangeLike(PostLike like);
Task<int> ChangeLike(PostLike like);
Task<List<PostLike>> GetLikesByPostId(int postId);
Task<List<PostLike>> GetLikesByUserId(int userId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,46 @@ namespace Application.Features.Comments.Handlers.Commands;

public class CreateCommentRequestHandler : IRequestHandler<CreateCommentRequest, CommentContentDto>
{
private readonly ICommentRepository _commentRepository;
private readonly IPostRepository _postRepository;
private readonly IUnitOfWork _unitOfWork;
private readonly IMapper _mapper;

public CreateCommentRequestHandler(ICommentRepository commentRepository, IPostRepository postRepository, IMapper mapper)
public CreateCommentRequestHandler(IUnitOfWork unitOfWork, IMapper mapper)
{
_commentRepository = commentRepository;
_postRepository = postRepository;
_unitOfWork = unitOfWork;
_mapper = mapper;
}

public async Task<CommentContentDto> Handle(CreateCommentRequest request, CancellationToken token)
{
var validator = new CreateCommentDtoValidator(_postRepository);
var validator = new CreateCommentDtoValidator(_unitOfWork.PostRepository);
var validationResult = await validator.ValidateAsync(request.Comment, token);


Console.WriteLine("Trying to create comment");
if (validationResult.IsValid == false)
{
foreach (var error in validationResult.Errors)
{
Console.WriteLine(error.ErrorMessage);
}

throw new ValidationException(validationResult);
}

Console.WriteLine("Here");
var comment = await _unitOfWork.CommentRepository.Add(_mapper.Map<Comment>(request.Comment));

var recievingPost = await _unitOfWork.PostRepository.Get(request.Comment.PostId);

var notif = new Notification()
{
UserId = recievingPost.UserId,
NotificationType = NotificationType.Comment,
Message = $"User {request.Comment.UserId} has commented on your post with Id {request.Comment.PostId}."
};

var comment = await _commentRepository.Add(_mapper.Map<Comment>(request.Comment));
await _unitOfWork.NotificationRepository.Add(notif);

await _unitOfWork.Save();
return _mapper.Map<CommentContentDto>(comment);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,38 @@ namespace Application.Features.PostLikes.Handlers.Commands;

public class ChangeLikeRequestHandler : IRequestHandler<ChangeLikeRequest, Unit>
{
private readonly IPostRepository _postRepository;
private readonly IPostLikesRepository _likesRepository;
private readonly IUnitOfWork _unitOfWork;
private readonly IMapper _mapper;

public ChangeLikeRequestHandler(IPostLikesRepository postLikesRepository, IPostRepository postRepository, IMapper mapper)
public ChangeLikeRequestHandler(IUnitOfWork unitOfWork, IMapper mapper)
{
_postRepository = postRepository;
_likesRepository = postLikesRepository;
_unitOfWork = unitOfWork;
_mapper = mapper;
}

public async Task<Unit> Handle(ChangeLikeRequest request, CancellationToken token)
{
var validator = new ChangeLikeDtoValidator(_postRepository);
var validator = new ChangeLikeDtoValidator(_unitOfWork.PostRepository);
var validationResult = await validator.ValidateAsync(request.ChangeLike, token);
if (validationResult.IsValid == false)
throw new ValidationException(validationResult);

await _likesRepository.ChangeLike(_mapper.Map<PostLike>(request.ChangeLike));
var liked = await _unitOfWork.PostLikesRepository.ChangeLike(_mapper.Map<PostLike>(request.ChangeLike));
if (liked == 1)
{
var recievingPost = await _unitOfWork.PostRepository.Get(request.ChangeLike.PostId);

var notif = new Notification()
{
UserId = recievingPost.UserId,
NotificationType = NotificationType.Like,
Message = $"User {request.ChangeLike.UserId} has liked your post with Id {request.ChangeLike.PostId}."
};

await _unitOfWork.NotificationRepository.Add(notif);
}

await _unitOfWork.Save();
return Unit.Value;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ namespace Application.Features.Posts.Handlers.Commands;

public class UpdatePostRequestHandler : IRequestHandler<UpdatePostRequest, Post>
{

private readonly IMapper _mapper;
private readonly IUnitOfWork _unitOfWork;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,19 @@ public async Task<PostLike> Add(PostLike like)
return like;
}

public async Task ChangeLike(PostLike like)
// Returns 1 if it likes and 0 if it dislikes
public async Task<int> ChangeLike(PostLike like)
{
var exists = await Exists(like.UserId, like.PostId);
if (exists)
{
Console.WriteLine($"Deleted Like {like.UserId} {like.PostId}");
await Delete(like);
return 0;
}
else
{
Console.WriteLine($"Created Like {like.UserId} {like.PostId}");
await Add(like);
return 1;
}
}

Expand Down
3 changes: 3 additions & 0 deletions aait/backend/group-1B/Persistence/SocialSyncDbContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ public override Task<int> SaveChangesAsync(CancellationToken cancellationToken =
{
entry.Entity.DateCreated = DateTime.UtcNow;
}



}

return base.SaveChangesAsync(cancellationToken);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using Application.Features.Comments.Requests.Commands;
using Application.Features.Comments.Requests.Queries;
using MediatR;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc;

namespace WebApi.Controllers;
Expand Down Expand Up @@ -62,7 +61,7 @@ public async Task<IActionResult> Update(UpdateCommentDto commentDto)
return Ok(comment);
}

[HttpDelete("{id:int}")]
[HttpDelete]
public async Task<IActionResult> Delete(int id)
{
var request = new DeleteCommentRequest() { Id = id };
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
using System.Security.Claims;
using Application.DTOs.Notifications;
using Application.Features.Notifications.Requests.Commands;
using Application.Features.Notifications.Requests.Queries;
using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;

namespace WebApi.Controllers;

[ApiController]
[Authorize]
[Route("api/[controller]")]
public class NotificationsController : ControllerBase
{
private readonly IMediator _mediator;

public NotificationsController(IMediator mediator)
{
_mediator = mediator;
}

[HttpGet]
public async Task<IActionResult> GetAll()
{
// Get user Id from the verified token
var userId = int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value);

var request = new GetAllNotificationsRequest() { UserId = userId };
var notifications = await _mediator.Send(request);

return Ok(notifications);
}

[HttpGet("{id:int}")]
public async Task<IActionResult> Get(int id)
{
var request = new GetNotificationRequest() { Id = id };
var notification = await _mediator.Send(request);

return Ok(notification);
}

[HttpPatch("seen/{id:int}")]
public async Task<IActionResult> MarkAsSeen(int id)
{
// Get user Id from the verified token
var userId = int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value);

var request = new MarkNotificationAsSeenRequest()
{ UpdateDto = new UpdateNotificationDto() { UserId = userId, Id = id } };
await _mediator.Send(request);

return NoContent();
}

[HttpDelete("{id:int}")]
public async Task<IActionResult> Delete(int id)
{
// Get user Id from the verified token
var userId = int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value);

var request = new DeleteNotificationRequest()
{ DeleteDto = new UpdateNotificationDto() { UserId = userId, Id = id } };
await _mediator.Send(request);

return NoContent();
}

}
4 changes: 2 additions & 2 deletions aait/backend/group-1B/WebApi/Controllers/PostsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public async Task<IActionResult> GetByUserId(int userId)
return Ok(posts);
}

[HttpGet("tag/{tagName}")]
[HttpGet("search/{tagName}")]
public async Task<IActionResult> GetByTag(string tagName)
{
var request = new GetPostsByTagRequest() { Tag = tagName };
Expand All @@ -65,7 +65,7 @@ public async Task<IActionResult> GetFeed()
return Ok(posts);
}

[HttpGet("like/{postId:int}")]
[HttpGet("{postId:int}/likes")]
public async Task<IActionResult> GetLikes(int postId)
{
var request = new GetLikesByPostIdRequest() { PostId = postId };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.5.0"/>
<PackageReference Include="xunit" Version="2.4.2"/>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.5.0" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
Expand All @@ -20,8 +20,12 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Moq" Version="4.18.4"/>
<PackageReference Include="Shouldly" Version="4.2.1"/>
<PackageReference Include="Moq" Version="4.18.4" />
<PackageReference Include="Shouldly" Version="4.2.1" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Application\Application.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using Moq;
using SocialSync.Application.Contracts.Persistence;

namespace SocialSync.Application.Tests.Mocks;


public class MockUnitOfWork {
public static Mock<IUnitOfWork> GetMockUnitOfWork() {
var unitOfWork = new Mock<IUnitOfWork>();

var mockUserRepository = MockUserRepository.GetUserRepository();

unitOfWork.Setup(uow => uow.UserRepository).Returns(mockUserRepository.Object);
unitOfWork.Setup(uow => uow.SaveAsync()).ReturnsAsync(1);

return unitOfWork;
}
}
Loading