-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(AAiT-backend-2B): Add Feeds Feature (#455)
- Loading branch information
1 parent
224ae2a
commit 80047cf
Showing
7 changed files
with
96 additions
and
26 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
27 changes: 27 additions & 0 deletions
27
...end/group-2B/Application/Features/Feed/Handlers/Queries/GetFeedsByUserIdRequestHandler.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,27 @@ | ||
using AutoMapper; | ||
using MediatR; | ||
using SocialSync.Application.Common.Responses; | ||
using SocialSync.Application.Contracts.Persistence; | ||
using SocialSync.Application.DTOs.PostDtos; | ||
using SocialSync.Application.Features.Feed.Requests.Queries; | ||
|
||
namespace SocialSync.Application.Features.Feed.Handlers.Queries; | ||
|
||
public class GetFeedsByUserIdRequestHandler : IRequestHandler<GetFeedsByUserIdRequest, CommonResponse<List<PostDto>>> | ||
{ | ||
private readonly IUnitOfWork _unitOfWork; | ||
private readonly IMapper _mapper; | ||
public GetFeedsByUserIdRequestHandler(IUnitOfWork unitOfWork, IMapper mapper){ | ||
_unitOfWork = unitOfWork; | ||
_mapper = mapper; | ||
} | ||
|
||
public async Task<CommonResponse<List<PostDto>>> Handle(GetFeedsByUserIdRequest request, CancellationToken cancellationToken){ | ||
var feeds = await _unitOfWork.PostRepository.GetFeedsByUserIdAsync(request.UserID); | ||
if(feeds == null){ | ||
CommonResponse<List<PostDto>>.Failure("Feeds Not Found!"); | ||
} | ||
|
||
return CommonResponse<List<PostDto>>.Success(_mapper.Map<List<PostDto>>(feeds)); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
aait/backend/group-2B/Application/Features/Feed/Requests/Queries/GetFeedsByUserIdRequest.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 MediatR; | ||
using SocialSync.Application.Common.Responses; | ||
using SocialSync.Application.DTOs.PostDtos; | ||
|
||
namespace SocialSync.Application.Features.Feed.Requests.Queries; | ||
|
||
public class GetFeedsByUserIdRequest : IRequest<CommonResponse<List<PostDto>>> | ||
{ | ||
public int UserID; | ||
} |
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
28 changes: 28 additions & 0 deletions
28
aait/backend/group-2B/WebApi/Controllers/FeedsController.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,28 @@ | ||
using MediatR; | ||
using Microsoft.AspNetCore.Mvc; | ||
using SocialSync.Application.Features.Feed.Requests.Queries; | ||
|
||
namespace SocialSync.WebApi.Controllers; | ||
|
||
[Route("api/[controller]")] | ||
[ApiController] | ||
public class FeedsController : ControllerBase | ||
{ | ||
private readonly IMediator _mediator; | ||
public FeedsController(IMediator mediator){ | ||
_mediator = mediator; | ||
} | ||
|
||
[HttpGet] | ||
public async Task<IActionResult> GetFeeds(int userID){ | ||
var feedsRequest = new GetFeedsByUserIdRequest {UserID = userID}; | ||
var response = await _mediator.Send(feedsRequest); | ||
|
||
if(response.IsSuccess){ | ||
return Ok(response); | ||
} | ||
else{ | ||
return BadRequest(response); | ||
} | ||
} | ||
} |
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,27 +1,22 @@ | ||
<Project Sdk="Microsoft.NET.Sdk.Web"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net7.0</TargetFramework> | ||
<Nullable>enable</Nullable> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="MediatR" Version="11.0.0" /> | ||
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="7.0.5" /> | ||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.10"> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
<PrivateAssets>all</PrivateAssets> | ||
</PackageReference> | ||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" /> | ||
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="7.0.0" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="../Persistence/Persistence.csproj" /> | ||
<ProjectReference Include="..\Infrastructure\Infrastructure.csproj" /> | ||
<ProjectReference Include="..\Application\Application.csproj" /> | ||
</ItemGroup> | ||
|
||
|
||
<PropertyGroup> | ||
<TargetFramework>net7.0</TargetFramework> | ||
<Nullable>enable</Nullable> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<PackageReference Include="MediatR" Version="11.0.0" /> | ||
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="7.0.5" /> | ||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.10"> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
<PrivateAssets>all</PrivateAssets> | ||
</PackageReference> | ||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" /> | ||
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="7.0.0" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="../Persistence/Persistence.csproj" /> | ||
<ProjectReference Include="..\Infrastructure\Infrastructure.csproj" /> | ||
<ProjectReference Include="..\Application\Application.csproj" /> | ||
</ItemGroup> | ||
</Project> |