This repository has been archived by the owner on Apr 11, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 40
Initial Project and Service added #388
Draft
aftabkajal
wants to merge
5
commits into
main
Choose a base branch
from
feature/attendance-service-initial-implementation
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
2b89b0e
Initial Project and Service added
aftabkajal 9d87010
Project file renaming and namespace update
aftabkajal 99d496d
Docker File updated
aftabkajal b3db5cc
Update appings and fix typo error
aftabkajal 90feee4
Removed unnecessary code
aftabkajal File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
45 changes: 45 additions & 0 deletions
45
src/Services/Attendance/Attendance.API/Application/Behaviors/LoggingBehavior.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,45 @@ | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using MediatR; | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace OpenCodeFoundation.ESchool.Services.Attending.API.Application.Behaviors | ||
{ | ||
public class LoggingBehavior<TRequest, TResponse> | ||
: IPipelineBehavior<TRequest, TResponse> | ||
where TRequest : notnull | ||
{ | ||
private readonly ILogger<LoggingBehavior<TRequest, TResponse>> _logger; | ||
|
||
public LoggingBehavior( | ||
ILogger<LoggingBehavior<TRequest, TResponse>> logger) | ||
{ | ||
_logger = logger ?? throw new System.ArgumentNullException(nameof(logger)); | ||
} | ||
|
||
public async Task<TResponse> Handle( | ||
TRequest request, | ||
CancellationToken cancellationToken, | ||
RequestHandlerDelegate<TResponse> next) | ||
{ | ||
if (next is null) | ||
{ | ||
throw new System.ArgumentNullException(nameof(next)); | ||
} | ||
|
||
_logger.LogInformation( | ||
"Handling request {RequestName} ({@Request})", | ||
request.GetType().Name, | ||
request); | ||
|
||
var response = await next().ConfigureAwait(false); | ||
|
||
_logger.LogInformation( | ||
"Request {RequestName} handled. Response: {@Response}", | ||
request.GetType().Name, | ||
response); | ||
|
||
return response; | ||
} | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
src/Services/Attendance/Attendance.API/Application/Commands/AttendanceApplicationCommand.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,9 @@ | ||
using MediatR; | ||
|
||
namespace OpenCodeFoundation.ESchool.Services.Attending.API.Application.Commands | ||
{ | ||
public record AttendanceApplicationCommand( | ||
string StudentId, | ||
string CourseId) | ||
: IRequest<bool>; | ||
} |
41 changes: 41 additions & 0 deletions
41
...ces/Attendance/Attendance.API/Application/Commands/AttendanceApplicationCommandHandler.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,41 @@ | ||
using System; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using MediatR; | ||
using Microsoft.Extensions.Logging; | ||
using OpenCodeFoundation.ESchool.Services.Attending.Infrastructure; | ||
|
||
namespace OpenCodeFoundation.ESchool.Services.Attending.API.Application.Commands | ||
{ | ||
public sealed class AttendanceApplicationCommandHandler | ||
: IRequestHandler<AttendanceApplicationCommand, bool> | ||
{ | ||
private readonly ILogger<AttendanceApplicationCommandHandler> _logger; | ||
private readonly AttendanceContext _context; | ||
|
||
public AttendanceApplicationCommandHandler( | ||
AttendanceContext context, | ||
ILogger<AttendanceApplicationCommandHandler> logger) | ||
{ | ||
_context = context ?? throw new ArgumentNullException(nameof(context)); | ||
_logger = logger ?? throw new ArgumentNullException(nameof(logger)); | ||
} | ||
|
||
public async Task<bool> Handle( | ||
AttendanceApplicationCommand command, | ||
CancellationToken cancellationToken) | ||
{ | ||
if (command == null) | ||
{ | ||
throw new ArgumentNullException(nameof(command)); | ||
} | ||
|
||
var attendance = new Domain.AggregatesModel.AttendanceAggregate.Attendance(command.StudentId, command.CourseId); | ||
await _context.Attendances.AddAsync(attendance, cancellationToken) | ||
.ConfigureAwait(false); | ||
await _context.SaveChangesAsync(cancellationToken) | ||
.ConfigureAwait(false); | ||
return true; | ||
} | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
...ttendance/Attendance.API/Application/Validations/AttendanceApplicationCommandValidator.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,15 @@ | ||
using FluentValidation; | ||
using OpenCodeFoundation.ESchool.Services.Attending.API.Application.Commands; | ||
|
||
namespace OpenCodeFoundation.ESchool.Services.Attending.API.Application.Validations | ||
{ | ||
public class AttendanceApplicationCommandValidator | ||
: AbstractValidator<AttendanceApplicationCommand> | ||
{ | ||
public AttendanceApplicationCommandValidator() | ||
{ | ||
RuleFor(application => application.CourseId).NotEmpty(); | ||
RuleFor(application => application.StudentId).NotEmpty(); | ||
} | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
src/Services/Attendance/Attendance.API/Attending.API.csproj
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,43 @@ | ||
<Project Sdk="Microsoft.NET.Sdk.Web"> | ||
<PropertyGroup> | ||
<TargetFramework>net5.0</TargetFramework> | ||
<AssemblyName>Attendance.API</AssemblyName> | ||
<RootNamespace>OpenCodeFoundation.ESchool.Services.Attending.API</RootNamespace> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<!-- HealthChecks --> | ||
<PackageReference Include="AspNetCore.HealthChecks.SqlServer" Version="5.0.2" /> | ||
<PackageReference Include="AspNetCore.HealthChecks.UI.Client" Version="5.0.1" /> | ||
<PackageReference Include="HotChocolate.AspNetCore" Version="11.1.0" /> | ||
<PackageReference Include="HotChocolate.Stitching" Version="11.1.0" /> | ||
<!-- In-memory commandbus --> | ||
<PackageReference Include="MediatR" Version="9.0.0" /> | ||
<PackageReference Include="MediatR.Extensions.Microsoft.DependencyInjection" Version="9.0.0" /> | ||
<!-- For validating inputs --> | ||
<PackageReference Include="FluentValidation.AspNetCore" Version="10.0.2" /> | ||
<!-- Polly is a .NET resilience and transient-fault-handling library that | ||
allows developers to express policies such as Retry, Circuit Breaker, Timeout, | ||
Bulkhead Isolation, and Fallback in a fluent and thread-safe manner. --> | ||
<PackageReference Include="Polly" Version="7.2.1" /> | ||
<!-- Logging --> | ||
<PackageReference Include="Serilog.AspNetCore" Version="4.1.0" /> | ||
<PackageReference Include="Serilog.Enrichers.Span" Version="1.2.0" /> | ||
<PackageReference Include="Serilog.Sinks.Seq" Version="5.0.0" /> | ||
<!-- Swagger --> | ||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.1.2" /> | ||
<!-- Need this package for generating migration files --> | ||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="5.0.5"> | ||
<PrivateAssets>all</PrivateAssets> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> | ||
</PackageReference> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\..\..\Libraries\OpenTelemetry\OpenTelemetry.csproj" /> | ||
<ProjectReference Include="..\Attendance.Domain\Attending.Domain.csproj" /> | ||
<ProjectReference Include="..\Attendance.Infrastructure\Attending.Infrastructure.csproj" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Folder Include="Application\Validations\" /> | ||
<Folder Include="Controllers\" /> | ||
</ItemGroup> | ||
</Project> |
31 changes: 31 additions & 0 deletions
31
src/Services/Attendance/Attendance.API/Controllers/AttendancesController.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,31 @@ | ||
using System; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using MediatR; | ||
using Microsoft.AspNetCore.Mvc; | ||
using OpenCodeFoundation.ESchool.Services.Attending.API.Application.Commands; | ||
|
||
namespace OpenCodeFoundation.ESchool.Services.Attending.API.Controllers | ||
{ | ||
[ApiController] | ||
[Route("[controller]")] | ||
public class AttendancesController : ControllerBase | ||
{ | ||
private readonly IMediator _mediator; | ||
|
||
public AttendancesController(IMediator mediator) | ||
{ | ||
_mediator = mediator ?? throw new ArgumentNullException(nameof(mediator)); | ||
} | ||
|
||
[HttpPost] | ||
public async Task<IActionResult> Post( | ||
[FromBody] AttendanceApplicationCommand command, | ||
CancellationToken cancellationToken) | ||
{ | ||
await _mediator.Send(command, cancellationToken) | ||
.ConfigureAwait(false); | ||
return Ok(); | ||
} | ||
} | ||
} |
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,46 @@ | ||
FROM mcr.microsoft.com/dotnet/aspnet:5.0-buster-slim AS base | ||
WORKDIR /app | ||
EXPOSE 80 | ||
|
||
FROM mcr.microsoft.com/dotnet/sdk:5.0-buster-slim AS build | ||
WORKDIR /src | ||
|
||
COPY "eSchool.sln" "eSchool.sln" | ||
|
||
COPY "src/ApiGateways/eSchool.GraphQL/eSchool.GraphQL.csproj" "src/ApiGateways/eSchool.GraphQL/eSchool.GraphQL.csproj" | ||
|
||
COPY "src/Services/Attending/Attending.API/Attending.API.csproj" "src/Services/Attending/Attending.API/Attending.API.csproj" | ||
COPY "src/Services/Attending/Attending.Domain/Attending.Domain.csproj" "src/Services/Attending/Attending.Domain/Attending.Domain.csproj" | ||
COPY "src/Services/Attending/Attending.Infrastructure/Attending.Infrastructure.csproj" "src/Services/Attending/Attending.Infrastructure/Attending.Infrastructure.csproj" | ||
COPY "src/Services/Attending/Attending.UnitTests/Attending.UnitTests.csproj" "src/Services/Attending/Attending.UnitTests/Attending.UnitTests.csproj" | ||
COPY "src/Services/Attending/Attending.FunctionalTests/Attending.FunctionalTests.csproj" "src/Services/Attending/Attending.FunctionalTests/Attending.FunctionalTests.csproj" | ||
|
||
COPY "src/Libraries/OpenTelemetry/OpenTelemetry.csproj" "src/Libraries/OpenTelemetry/OpenTelemetry.csproj" | ||
|
||
COPY "src/Web/WebStatus/WebStatus.csproj" "src/Web/WebStatus/WebStatus.csproj" | ||
|
||
COPY "src/Web/Frontend.Blazor/Frontend.Blazor.Server/Frontend.Blazor.Server.csproj" "src/Web/Frontend.Blazor/Frontend.Blazor.Server/Frontend.Blazor.Server.csproj" | ||
COPY "src/Web/Frontend.Blazor/Frontend.Blazor.Client/Frontend.Blazor.Client.csproj" "src/Web/Frontend.Blazor/Frontend.Blazor.Client/Frontend.Blazor.Client.csproj" | ||
COPY "src/Web/Frontend.Blazor/Frontend.Blazor.Shared/Frontend.Blazor.Shared.csproj" "src/Web/Frontend.Blazor/Frontend.Blazor.Shared/Frontend.Blazor.Shared.csproj" | ||
|
||
COPY "docker-compose.dcproj" "docker-compose.dcproj" | ||
|
||
RUN dotnet restore eSchool.sln -nowarn:msb3202,nu1503 | ||
|
||
COPY . . | ||
WORKDIR /src/src/Services/Attending/Attending.API | ||
RUN dotnet build --no-restore -c Release -o /app/build | ||
|
||
FROM build as unittest | ||
WORKDIR /src/src/Services/Attending/Attending.UnitTests | ||
|
||
FROM build as functionaltest | ||
WORKDIR /src/src/Services/Attending/Attending.FunctionalTests | ||
|
||
FROM build AS publish | ||
RUN dotnet publish --no-restore -c Release -o /app/publish | ||
|
||
FROM base AS final | ||
WORKDIR /app | ||
COPY --from=publish /app/publish . | ||
ENTRYPOINT ["dotnet", "Attending.API.dll"] |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please skip adding your projects to the solution file? This way your project should not be visible in visual studio, but can be built from command line.