From 2b89b0ee00e281c572c0573bf41ed40992fbdfed Mon Sep 17 00:00:00 2001 From: "Md. Aftab Uddin Kajal" Date: Sat, 24 Apr 2021 04:07:17 +0600 Subject: [PATCH 1/5] Initial Project and Service added --- eSchool.sln | 78 +++++++++++ .../Application/Behaviors/LoggingBehavior.cs | 45 +++++++ .../Commands/AttendanceApplicationCommand.cs | 10 ++ .../AttendanceApplicationCommandHandler.cs | 42 ++++++ .../Queries/FindAllAttendancesHandler.cs | 29 +++++ .../Queries/FindAllAttendancesQuery.cs | 11 ++ .../AttendanceApplicationCommandValidator.cs | 16 +++ .../Attendance.API/Attendance.API.csproj | 43 +++++++ .../Controllers/AttendancesController.cs | 39 ++++++ .../Attendance/Attendance.API/Dockerfile | 46 +++++++ .../Extensions/ServiceCollectionExtensions.cs | 31 +++++ .../Attendance/Attendance.API/Program.cs | 87 +++++++++++++ .../Attendance/Attendance.API/Startup.cs | 121 ++++++++++++++++++ .../Attendance.API/WebHostExtensions.cs | 60 +++++++++ .../Attendance.API/appsettings.json | 24 ++++ .../Attendance.API/graphql/AttendanceQuery.cs | 43 +++++++ .../graphql/GraphQlErrorFilter.cs | 20 +++ .../Attendance.API/graphql/Mutation.cs | 44 +++++++ .../AttendanceAggregate/Attendance.cs | 28 ++++ .../IAttendanceRepository.cs | 19 +++ .../Attendance.Domain.csproj | 10 ++ .../Attendance.Domain/SeedWork/Entity.cs | 9 ++ .../SeedWork/IAggregateRoot.cs | 10 ++ .../Attendance.Domain/SeedWork/IRepository.cs | 11 ++ .../Attendance.FunctionalTests.csproj | 24 ++++ .../AttendanceTests.cs | 24 ++++ .../TestServerCollection.cs | 13 ++ .../TestServerFixture.cs | 55 ++++++++ .../appsettings.json | 3 + .../Attendance.Infrastructure.csproj | 14 ++ .../AttendanceContext.cs | 33 +++++ .../20200330154056_Initial.Designer.cs | 46 +++++++ .../Migrations/20200330154056_Initial.cs | 32 +++++ .../AttendanceContextModelSnapshot.cs | 44 +++++++ .../Repositories/AttendanceRepository.cs | 44 +++++++ .../Attendance.UnitTests.csproj | 20 +++ .../Builders/AttendanceDto.cs | 11 ++ .../Builders/AttendanceDtoBuilder.cs | 45 +++++++ .../Domain/EnrollmentAggregateTests.cs | 58 +++++++++ 39 files changed, 1342 insertions(+) create mode 100644 src/Services/Attendance/Attendance.API/Application/Behaviors/LoggingBehavior.cs create mode 100644 src/Services/Attendance/Attendance.API/Application/Commands/AttendanceApplicationCommand.cs create mode 100644 src/Services/Attendance/Attendance.API/Application/Commands/AttendanceApplicationCommandHandler.cs create mode 100644 src/Services/Attendance/Attendance.API/Application/Queries/FindAllAttendancesHandler.cs create mode 100644 src/Services/Attendance/Attendance.API/Application/Queries/FindAllAttendancesQuery.cs create mode 100644 src/Services/Attendance/Attendance.API/Application/Validations/AttendanceApplicationCommandValidator.cs create mode 100644 src/Services/Attendance/Attendance.API/Attendance.API.csproj create mode 100644 src/Services/Attendance/Attendance.API/Controllers/AttendancesController.cs create mode 100644 src/Services/Attendance/Attendance.API/Dockerfile create mode 100644 src/Services/Attendance/Attendance.API/Extensions/ServiceCollectionExtensions.cs create mode 100644 src/Services/Attendance/Attendance.API/Program.cs create mode 100644 src/Services/Attendance/Attendance.API/Startup.cs create mode 100644 src/Services/Attendance/Attendance.API/WebHostExtensions.cs create mode 100644 src/Services/Attendance/Attendance.API/appsettings.json create mode 100644 src/Services/Attendance/Attendance.API/graphql/AttendanceQuery.cs create mode 100644 src/Services/Attendance/Attendance.API/graphql/GraphQlErrorFilter.cs create mode 100644 src/Services/Attendance/Attendance.API/graphql/Mutation.cs create mode 100644 src/Services/Attendance/Attendance.Domain/AggregatesModel/AttendanceAggregate/Attendance.cs create mode 100644 src/Services/Attendance/Attendance.Domain/AggregatesModel/AttendanceAggregate/IAttendanceRepository.cs create mode 100644 src/Services/Attendance/Attendance.Domain/Attendance.Domain.csproj create mode 100644 src/Services/Attendance/Attendance.Domain/SeedWork/Entity.cs create mode 100644 src/Services/Attendance/Attendance.Domain/SeedWork/IAggregateRoot.cs create mode 100644 src/Services/Attendance/Attendance.Domain/SeedWork/IRepository.cs create mode 100644 src/Services/Attendance/Attendance.FunctionalTests/Attendance.FunctionalTests.csproj create mode 100644 src/Services/Attendance/Attendance.FunctionalTests/AttendanceTests.cs create mode 100644 src/Services/Attendance/Attendance.FunctionalTests/TestServerCollection.cs create mode 100644 src/Services/Attendance/Attendance.FunctionalTests/TestServerFixture.cs create mode 100644 src/Services/Attendance/Attendance.FunctionalTests/appsettings.json create mode 100644 src/Services/Attendance/Attendance.Infrastructure/Attendance.Infrastructure.csproj create mode 100644 src/Services/Attendance/Attendance.Infrastructure/AttendanceContext.cs create mode 100644 src/Services/Attendance/Attendance.Infrastructure/Migrations/20200330154056_Initial.Designer.cs create mode 100644 src/Services/Attendance/Attendance.Infrastructure/Migrations/20200330154056_Initial.cs create mode 100644 src/Services/Attendance/Attendance.Infrastructure/Migrations/AttendanceContextModelSnapshot.cs create mode 100644 src/Services/Attendance/Attendance.Infrastructure/Repositories/AttendanceRepository.cs create mode 100644 src/Services/Attendance/Attendance.UnitTests/Attendance.UnitTests.csproj create mode 100644 src/Services/Attendance/Attendance.UnitTests/Builders/AttendanceDto.cs create mode 100644 src/Services/Attendance/Attendance.UnitTests/Builders/AttendanceDtoBuilder.cs create mode 100644 src/Services/Attendance/Attendance.UnitTests/Domain/EnrollmentAggregateTests.cs diff --git a/eSchool.sln b/eSchool.sln index 02ebdc1a..92eb66cc 100644 --- a/eSchool.sln +++ b/eSchool.sln @@ -41,6 +41,18 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Frontend.Blazor.Server", "s EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Frontend.Blazor.Shared", "src\Web\Frontend.Blazor\Frontend.Blazor.Shared\Frontend.Blazor.Shared.csproj", "{4EB86635-CF79-4D15-909E-C41C98B0B586}" EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Attendance", "Attendance", "{2BE71A01-0660-4264-B03F-8A386AB840ED}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Attendance.API", "src\Services\Attendance\Attendance.API\Attendance.API.csproj", "{2A2976A2-4578-49D1-BC3B-A9D466837CCB}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Attendance.Domain", "src\Services\Attendance\Attendance.Domain\Attendance.Domain.csproj", "{69EAD5CE-01BD-4132-B65B-69EAC7DA10AF}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Attendance.FunctionalTests", "src\Services\Attendance\Attendance.FunctionalTests\Attendance.FunctionalTests.csproj", "{020D0652-9802-431D-836A-B9ED27D841A2}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Attendance.Infrastructure", "src\Services\Attendance\Attendance.Infrastructure\Attendance.Infrastructure.csproj", "{767C29FF-C92E-424D-84D4-FF606FACD07A}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Attendance.UnitTests", "src\Services\Attendance\Attendance.UnitTests\Attendance.UnitTests.csproj", "{0D9BD20E-7EBC-4689-B621-676440441223}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -195,6 +207,66 @@ Global {4EB86635-CF79-4D15-909E-C41C98B0B586}.Release|x64.Build.0 = Release|Any CPU {4EB86635-CF79-4D15-909E-C41C98B0B586}.Release|x86.ActiveCfg = Release|Any CPU {4EB86635-CF79-4D15-909E-C41C98B0B586}.Release|x86.Build.0 = Release|Any CPU + {2A2976A2-4578-49D1-BC3B-A9D466837CCB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {2A2976A2-4578-49D1-BC3B-A9D466837CCB}.Debug|Any CPU.Build.0 = Debug|Any CPU + {2A2976A2-4578-49D1-BC3B-A9D466837CCB}.Debug|x64.ActiveCfg = Debug|Any CPU + {2A2976A2-4578-49D1-BC3B-A9D466837CCB}.Debug|x64.Build.0 = Debug|Any CPU + {2A2976A2-4578-49D1-BC3B-A9D466837CCB}.Debug|x86.ActiveCfg = Debug|Any CPU + {2A2976A2-4578-49D1-BC3B-A9D466837CCB}.Debug|x86.Build.0 = Debug|Any CPU + {2A2976A2-4578-49D1-BC3B-A9D466837CCB}.Release|Any CPU.ActiveCfg = Release|Any CPU + {2A2976A2-4578-49D1-BC3B-A9D466837CCB}.Release|Any CPU.Build.0 = Release|Any CPU + {2A2976A2-4578-49D1-BC3B-A9D466837CCB}.Release|x64.ActiveCfg = Release|Any CPU + {2A2976A2-4578-49D1-BC3B-A9D466837CCB}.Release|x64.Build.0 = Release|Any CPU + {2A2976A2-4578-49D1-BC3B-A9D466837CCB}.Release|x86.ActiveCfg = Release|Any CPU + {2A2976A2-4578-49D1-BC3B-A9D466837CCB}.Release|x86.Build.0 = Release|Any CPU + {69EAD5CE-01BD-4132-B65B-69EAC7DA10AF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {69EAD5CE-01BD-4132-B65B-69EAC7DA10AF}.Debug|Any CPU.Build.0 = Debug|Any CPU + {69EAD5CE-01BD-4132-B65B-69EAC7DA10AF}.Debug|x64.ActiveCfg = Debug|Any CPU + {69EAD5CE-01BD-4132-B65B-69EAC7DA10AF}.Debug|x64.Build.0 = Debug|Any CPU + {69EAD5CE-01BD-4132-B65B-69EAC7DA10AF}.Debug|x86.ActiveCfg = Debug|Any CPU + {69EAD5CE-01BD-4132-B65B-69EAC7DA10AF}.Debug|x86.Build.0 = Debug|Any CPU + {69EAD5CE-01BD-4132-B65B-69EAC7DA10AF}.Release|Any CPU.ActiveCfg = Release|Any CPU + {69EAD5CE-01BD-4132-B65B-69EAC7DA10AF}.Release|Any CPU.Build.0 = Release|Any CPU + {69EAD5CE-01BD-4132-B65B-69EAC7DA10AF}.Release|x64.ActiveCfg = Release|Any CPU + {69EAD5CE-01BD-4132-B65B-69EAC7DA10AF}.Release|x64.Build.0 = Release|Any CPU + {69EAD5CE-01BD-4132-B65B-69EAC7DA10AF}.Release|x86.ActiveCfg = Release|Any CPU + {69EAD5CE-01BD-4132-B65B-69EAC7DA10AF}.Release|x86.Build.0 = Release|Any CPU + {020D0652-9802-431D-836A-B9ED27D841A2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {020D0652-9802-431D-836A-B9ED27D841A2}.Debug|Any CPU.Build.0 = Debug|Any CPU + {020D0652-9802-431D-836A-B9ED27D841A2}.Debug|x64.ActiveCfg = Debug|Any CPU + {020D0652-9802-431D-836A-B9ED27D841A2}.Debug|x64.Build.0 = Debug|Any CPU + {020D0652-9802-431D-836A-B9ED27D841A2}.Debug|x86.ActiveCfg = Debug|Any CPU + {020D0652-9802-431D-836A-B9ED27D841A2}.Debug|x86.Build.0 = Debug|Any CPU + {020D0652-9802-431D-836A-B9ED27D841A2}.Release|Any CPU.ActiveCfg = Release|Any CPU + {020D0652-9802-431D-836A-B9ED27D841A2}.Release|Any CPU.Build.0 = Release|Any CPU + {020D0652-9802-431D-836A-B9ED27D841A2}.Release|x64.ActiveCfg = Release|Any CPU + {020D0652-9802-431D-836A-B9ED27D841A2}.Release|x64.Build.0 = Release|Any CPU + {020D0652-9802-431D-836A-B9ED27D841A2}.Release|x86.ActiveCfg = Release|Any CPU + {020D0652-9802-431D-836A-B9ED27D841A2}.Release|x86.Build.0 = Release|Any CPU + {767C29FF-C92E-424D-84D4-FF606FACD07A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {767C29FF-C92E-424D-84D4-FF606FACD07A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {767C29FF-C92E-424D-84D4-FF606FACD07A}.Debug|x64.ActiveCfg = Debug|Any CPU + {767C29FF-C92E-424D-84D4-FF606FACD07A}.Debug|x64.Build.0 = Debug|Any CPU + {767C29FF-C92E-424D-84D4-FF606FACD07A}.Debug|x86.ActiveCfg = Debug|Any CPU + {767C29FF-C92E-424D-84D4-FF606FACD07A}.Debug|x86.Build.0 = Debug|Any CPU + {767C29FF-C92E-424D-84D4-FF606FACD07A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {767C29FF-C92E-424D-84D4-FF606FACD07A}.Release|Any CPU.Build.0 = Release|Any CPU + {767C29FF-C92E-424D-84D4-FF606FACD07A}.Release|x64.ActiveCfg = Release|Any CPU + {767C29FF-C92E-424D-84D4-FF606FACD07A}.Release|x64.Build.0 = Release|Any CPU + {767C29FF-C92E-424D-84D4-FF606FACD07A}.Release|x86.ActiveCfg = Release|Any CPU + {767C29FF-C92E-424D-84D4-FF606FACD07A}.Release|x86.Build.0 = Release|Any CPU + {0D9BD20E-7EBC-4689-B621-676440441223}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {0D9BD20E-7EBC-4689-B621-676440441223}.Debug|Any CPU.Build.0 = Debug|Any CPU + {0D9BD20E-7EBC-4689-B621-676440441223}.Debug|x64.ActiveCfg = Debug|Any CPU + {0D9BD20E-7EBC-4689-B621-676440441223}.Debug|x64.Build.0 = Debug|Any CPU + {0D9BD20E-7EBC-4689-B621-676440441223}.Debug|x86.ActiveCfg = Debug|Any CPU + {0D9BD20E-7EBC-4689-B621-676440441223}.Debug|x86.Build.0 = Debug|Any CPU + {0D9BD20E-7EBC-4689-B621-676440441223}.Release|Any CPU.ActiveCfg = Release|Any CPU + {0D9BD20E-7EBC-4689-B621-676440441223}.Release|Any CPU.Build.0 = Release|Any CPU + {0D9BD20E-7EBC-4689-B621-676440441223}.Release|x64.ActiveCfg = Release|Any CPU + {0D9BD20E-7EBC-4689-B621-676440441223}.Release|x64.Build.0 = Release|Any CPU + {0D9BD20E-7EBC-4689-B621-676440441223}.Release|x86.ActiveCfg = Release|Any CPU + {0D9BD20E-7EBC-4689-B621-676440441223}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -217,6 +289,12 @@ Global {53F4E6F9-6B91-45F9-97F9-F6EFA0EBEFCE} = {0C00A596-0FE3-4FA6-B54B-FE2BE83371EF} {3BABD4D9-56A1-4BA3-B30C-30E6765AB389} = {0C00A596-0FE3-4FA6-B54B-FE2BE83371EF} {4EB86635-CF79-4D15-909E-C41C98B0B586} = {0C00A596-0FE3-4FA6-B54B-FE2BE83371EF} + {2BE71A01-0660-4264-B03F-8A386AB840ED} = {1C120673-72F4-4679-AC4C-68286E9091A5} + {2A2976A2-4578-49D1-BC3B-A9D466837CCB} = {2BE71A01-0660-4264-B03F-8A386AB840ED} + {69EAD5CE-01BD-4132-B65B-69EAC7DA10AF} = {2BE71A01-0660-4264-B03F-8A386AB840ED} + {020D0652-9802-431D-836A-B9ED27D841A2} = {2BE71A01-0660-4264-B03F-8A386AB840ED} + {767C29FF-C92E-424D-84D4-FF606FACD07A} = {2BE71A01-0660-4264-B03F-8A386AB840ED} + {0D9BD20E-7EBC-4689-B621-676440441223} = {2BE71A01-0660-4264-B03F-8A386AB840ED} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {E418719F-3193-403E-AF58-9BE9F94FD8BE} diff --git a/src/Services/Attendance/Attendance.API/Application/Behaviors/LoggingBehavior.cs b/src/Services/Attendance/Attendance.API/Application/Behaviors/LoggingBehavior.cs new file mode 100644 index 00000000..80086d6b --- /dev/null +++ b/src/Services/Attendance/Attendance.API/Application/Behaviors/LoggingBehavior.cs @@ -0,0 +1,45 @@ +using System.Threading; +using System.Threading.Tasks; +using MediatR; +using Microsoft.Extensions.Logging; + +namespace OpenCodeFoundation.ESchool.Services.Attendance.API.Application.Behaviors +{ + public class LoggingBehavior + : IPipelineBehavior + where TRequest : notnull + { + private readonly ILogger> _logger; + + public LoggingBehavior( + ILogger> logger) + { + _logger = logger ?? throw new System.ArgumentNullException(nameof(logger)); + } + + public async Task Handle( + TRequest request, + CancellationToken cancellationToken, + RequestHandlerDelegate 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; + } + } +} diff --git a/src/Services/Attendance/Attendance.API/Application/Commands/AttendanceApplicationCommand.cs b/src/Services/Attendance/Attendance.API/Application/Commands/AttendanceApplicationCommand.cs new file mode 100644 index 00000000..5c441efc --- /dev/null +++ b/src/Services/Attendance/Attendance.API/Application/Commands/AttendanceApplicationCommand.cs @@ -0,0 +1,10 @@ +using MediatR; + +namespace OpenCodeFoundation.ESchool.Services.Attendance.API.Application.Commands +{ + public record AttendanceApplicationCommand( + string Name, + string Email, + string Mobile) + : IRequest; +} diff --git a/src/Services/Attendance/Attendance.API/Application/Commands/AttendanceApplicationCommandHandler.cs b/src/Services/Attendance/Attendance.API/Application/Commands/AttendanceApplicationCommandHandler.cs new file mode 100644 index 00000000..3de5992b --- /dev/null +++ b/src/Services/Attendance/Attendance.API/Application/Commands/AttendanceApplicationCommandHandler.cs @@ -0,0 +1,42 @@ +using System; +using System.Threading; +using System.Threading.Tasks; +using MediatR; +using Microsoft.Extensions.Logging; +using OpenCodeFoundation.ESchool.Services.Attendance.Domain.AggregatesModel.AttendanceAggregate; +using OpenCodeFoundation.ESchool.Services.Attendance.Infrastructure; + +namespace OpenCodeFoundation.ESchool.Services.Attendance.API.Application.Commands +{ + public sealed class AttendanceApplicationCommandHandler + : IRequestHandler + { + private readonly ILogger _logger; + private readonly AttendanceContext _context; + + public AttendanceApplicationCommandHandler( + AttendanceContext context, + ILogger logger) + { + _context = context ?? throw new ArgumentNullException(nameof(context)); + _logger = logger ?? throw new ArgumentNullException(nameof(logger)); + } + + public async Task Handle( + AttendanceApplicationCommand command, + CancellationToken cancellationToken) + { + if (command == null) + { + throw new ArgumentNullException(nameof(command)); + } + + var attendance = new Attendance(command.Name, command.Email, command.Mobile); + await _context.Attendances.AddAsync(attendance, cancellationToken) + .ConfigureAwait(false); + await _context.SaveChangesAsync(cancellationToken) + .ConfigureAwait(false); + return true; + } + } +} diff --git a/src/Services/Attendance/Attendance.API/Application/Queries/FindAllAttendancesHandler.cs b/src/Services/Attendance/Attendance.API/Application/Queries/FindAllAttendancesHandler.cs new file mode 100644 index 00000000..fef4eaa6 --- /dev/null +++ b/src/Services/Attendance/Attendance.API/Application/Queries/FindAllAttendancesHandler.cs @@ -0,0 +1,29 @@ +using System.Collections.Generic; +using System.Threading; +using System.Threading.Tasks; +using MediatR; +using Microsoft.EntityFrameworkCore; +using OpenCodeFoundation.ESchool.Services.Enrolling.Domain.AggregatesModel.EnrollmentAggregate; +using OpenCodeFoundation.ESchool.Services.Enrolling.Infrastructure; + +namespace OpenCodeFoundation.ESchool.Services.Enrolling.API.Application.Queries +{ + public class FindAllAttendancesHandler + : IRequestHandler> + { + private readonly AttendanceContext _context; + + public FindAllAttendancesHandler(AttendanceContext context) + { + _context = context ?? throw new System.ArgumentNullException(nameof(context)); + } + + public async Task> Handle( + FindAllAttendancesQuery request, + CancellationToken cancellationToken) + { + return await _context.Enrollments.ToListAsync(cancellationToken) + .ConfigureAwait(false); + } + } +} diff --git a/src/Services/Attendance/Attendance.API/Application/Queries/FindAllAttendancesQuery.cs b/src/Services/Attendance/Attendance.API/Application/Queries/FindAllAttendancesQuery.cs new file mode 100644 index 00000000..746c064d --- /dev/null +++ b/src/Services/Attendance/Attendance.API/Application/Queries/FindAllAttendancesQuery.cs @@ -0,0 +1,11 @@ +using System.Collections.Generic; +using MediatR; +using OpenCodeFoundation.ESchool.Services.Attendance.Domain.AggregatesModel.EnrollmentAggregate; + +namespace OpenCodeFoundation.ESchool.Services.Attendance.API.Application.Queries +{ + public class FindAllAttendancesQuery + : IRequest> + { + } +} diff --git a/src/Services/Attendance/Attendance.API/Application/Validations/AttendanceApplicationCommandValidator.cs b/src/Services/Attendance/Attendance.API/Application/Validations/AttendanceApplicationCommandValidator.cs new file mode 100644 index 00000000..aa44c763 --- /dev/null +++ b/src/Services/Attendance/Attendance.API/Application/Validations/AttendanceApplicationCommandValidator.cs @@ -0,0 +1,16 @@ +using FluentValidation; +using OpenCodeFoundation.ESchool.Services.Attendance.API.Application.Commands; + +namespace OpenCodeFoundation.ESchool.Services.Attendance.API.Application.Validations +{ + public class AttendanceApplicationCommandValidator + : AbstractValidator + { + public AttendanceApplicationCommandValidator() + { + RuleFor(application => application.Name).NotEmpty(); + RuleFor(application => application.Email).NotEmpty().EmailAddress(); + RuleFor(application => application.Mobile).NotEmpty(); + } + } +} diff --git a/src/Services/Attendance/Attendance.API/Attendance.API.csproj b/src/Services/Attendance/Attendance.API/Attendance.API.csproj new file mode 100644 index 00000000..2b13f835 --- /dev/null +++ b/src/Services/Attendance/Attendance.API/Attendance.API.csproj @@ -0,0 +1,43 @@ + + + net5.0 + Attendance.API + OpenCodeFoundation.ESchool.Services.Attendance.API + + + + + + + + + + + + + + + + + + + + + + + all + runtime; build; native; contentfiles; analyzers + + + + + + + + + + + + \ No newline at end of file diff --git a/src/Services/Attendance/Attendance.API/Controllers/AttendancesController.cs b/src/Services/Attendance/Attendance.API/Controllers/AttendancesController.cs new file mode 100644 index 00000000..0bb4ad5d --- /dev/null +++ b/src/Services/Attendance/Attendance.API/Controllers/AttendancesController.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; +using System.Threading; +using System.Threading.Tasks; +using MediatR; +using Microsoft.AspNetCore.Mvc; +using OpenCodeFoundation.ESchool.Services.Attendance.API.Application.Commands; +using OpenCodeFoundation.ESchool.Services.Attendance.API.Application.Queries; +using OpenCodeFoundation.ESchool.Services.Attendance.Domain.AggregatesModel.EnrollmentAggregate; + +namespace OpenCodeFoundation.ESchool.Services.Attendance.API.Controllers +{ + [ApiController] + [Route("[controller]")] + public class AttendancesController : ControllerBase + { + private readonly IMediator _mediator; + + public AttendancesController(IMediator mediator) + { + _mediator = mediator ?? throw new ArgumentNullException(nameof(mediator)); + } + + [HttpGet] + public async Task> Get(CancellationToken cancellationToken) + => await _mediator.Send(new FindAllEnrollmentsQuery(), cancellationToken) + .ConfigureAwait(false); + + [HttpPost] + public async Task Post( + [FromBody] AttendanceApplicationCommand command, + CancellationToken cancellationToken) + { + await _mediator.Send(command, cancellationToken) + .ConfigureAwait(false); + return Ok(); + } + } +} diff --git a/src/Services/Attendance/Attendance.API/Dockerfile b/src/Services/Attendance/Attendance.API/Dockerfile new file mode 100644 index 00000000..26772158 --- /dev/null +++ b/src/Services/Attendance/Attendance.API/Dockerfile @@ -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/Enrolling/Enrolling.API/Enrolling.API.csproj" "src/Services/Enrolling/Enrolling.API/Enrolling.API.csproj" +COPY "src/Services/Enrolling/Enrolling.Domain/Enrolling.Domain.csproj" "src/Services/Enrolling/Enrolling.Domain/Enrolling.Domain.csproj" +COPY "src/Services/Enrolling/Enrolling.Infrastructure/Enrolling.Infrastructure.csproj" "src/Services/Enrolling/Enrolling.Infrastructure/Enrolling.Infrastructure.csproj" +COPY "src/Services/Enrolling/Enrolling.UnitTests/Enrolling.UnitTests.csproj" "src/Services/Enrolling/Enrolling.UnitTests/Enrolling.UnitTests.csproj" +COPY "src/Services/Enrolling/Enrolling.FunctionalTests/Enrolling.FunctionalTests.csproj" "src/Services/Enrolling/Enrolling.FunctionalTests/Enrolling.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/Enrolling/Enrolling.API +RUN dotnet build --no-restore -c Release -o /app/build + +FROM build as unittest +WORKDIR /src/src/Services/Enrolling/Enrolling.UnitTests + +FROM build as functionaltest +WORKDIR /src/src/Services/Enrolling/Enrolling.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", "Enrolling.API.dll"] \ No newline at end of file diff --git a/src/Services/Attendance/Attendance.API/Extensions/ServiceCollectionExtensions.cs b/src/Services/Attendance/Attendance.API/Extensions/ServiceCollectionExtensions.cs new file mode 100644 index 00000000..74a45bae --- /dev/null +++ b/src/Services/Attendance/Attendance.API/Extensions/ServiceCollectionExtensions.cs @@ -0,0 +1,31 @@ +using System; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Diagnostics.HealthChecks; + +namespace OpenCodeFoundation.ESchool.Services.Attendance.API.Extensions +{ + public static class ServiceCollectionExtensions + { + public static IServiceCollection AddCustomHealthChecks( + this IServiceCollection services, + IConfiguration configuration) + { + if (configuration == null) + { + throw new ArgumentNullException(nameof(configuration)); + } + + var hcBuilder = services.AddHealthChecks(); + + hcBuilder + .AddCheck("self", () => HealthCheckResult.Healthy()) + .AddSqlServer( + configuration["ConnectionStrings"], + name: "AttendanceDB-check", + tags: new string[] { "attendancedb" }); + + return services; + } + } +} diff --git a/src/Services/Attendance/Attendance.API/Program.cs b/src/Services/Attendance/Attendance.API/Program.cs new file mode 100644 index 00000000..34d2697f --- /dev/null +++ b/src/Services/Attendance/Attendance.API/Program.cs @@ -0,0 +1,87 @@ +using System; +using System.Diagnostics; +using System.IO; +using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Hosting; +using OpenCodeFoundation.ESchool.Services.Attendance.Infrastructure; +using Serilog; +using Serilog.Enrichers.Span; + +namespace OpenCodeFoundation.ESchool.Services.Attendance.API +{ + public static class Program + { + public static readonly string Namespace = typeof(Program).Namespace!; + public static readonly string AppName = Namespace.Substring(Namespace.LastIndexOf('.', Namespace.LastIndexOf('.') - 1) + 1); + + [System.Diagnostics.CodeAnalysis.SuppressMessage( + "Design", + "CA1031:Do not catch general exception types", + Justification = "Top level all exception catcher")] + public static int Main(string[] args) + { + Activity.DefaultIdFormat = ActivityIdFormat.W3C; + + var configuration = GetConfiguration(); + + Log.Logger = CreateSerilogLogger(configuration); + + try + { + Log.Information("Configuring web host ({ApplicationContext})...", AppName); + var host = CreateHostBuilder(configuration, args).Build(); + + Log.Information("Applying migrations ({ApplicationContext})...", AppName); + host.MigrateDbContext((_, _) => { }); + + Log.Information("Starting web host ({ApplicationContext})...", AppName); + host.Run(); + + return 0; + } + catch (Exception ex) + { + Log.Fatal(ex, "Host terminated unexpectedly"); + return 1; + } + finally + { + Log.CloseAndFlush(); + } + } + + public static IHostBuilder CreateHostBuilder(IConfiguration configuration, string[] args) => + Host.CreateDefaultBuilder(args) + .ConfigureWebHostDefaults(webBuilder => + { + webBuilder.UseStartup(); + webBuilder.UseConfiguration(configuration); + webBuilder.UseSerilog(); + }); + + private static ILogger CreateSerilogLogger(IConfiguration configuration) + { + return new LoggerConfiguration() + .MinimumLevel.Verbose() + .Enrich.WithProperty("ApplicationContext", AppName) + .Enrich.FromLogContext() + .Enrich.WithSpan() + .WriteTo.Console() + .WriteTo.Seq("http://seq") + .ReadFrom.Configuration(configuration) + .CreateLogger(); + } + + private static IConfiguration GetConfiguration() + { + var builder = new ConfigurationBuilder() + .SetBasePath(Directory.GetCurrentDirectory()) + .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true) + .AddEnvironmentVariables(); + + // Load other configurations here. Ex. Keyvault or AppConfiguration + return builder.Build(); + } + } +} diff --git a/src/Services/Attendance/Attendance.API/Startup.cs b/src/Services/Attendance/Attendance.API/Startup.cs new file mode 100644 index 00000000..d12c1d82 --- /dev/null +++ b/src/Services/Attendance/Attendance.API/Startup.cs @@ -0,0 +1,121 @@ +using System; +using System.Reflection; +using FluentValidation.AspNetCore; +using HealthChecks.UI.Client; +using MediatR; +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Diagnostics.HealthChecks; +using Microsoft.AspNetCore.Hosting; +using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; +using Microsoft.Extensions.Logging; +using Microsoft.OpenApi.Models; +using OpenCodeFoundation.ESchool.Services.Attendance.API.Application.Behaviors; +using OpenCodeFoundation.ESchool.Services.Attendance.API.Application.Validations; +using OpenCodeFoundation.ESchool.Services.Attendance.API.Extensions; +using OpenCodeFoundation.ESchool.Services.Attendance.API.Graphql; +using OpenCodeFoundation.ESchool.Services.Attendance.Infrastructure; +using OpenCodeFoundation.OpenTelemetry; +using Serilog; + +namespace OpenCodeFoundation.ESchool.Services.Attendance.API +{ + public class Startup + { + public Startup(IConfiguration configuration) + { + Configuration = configuration; + } + + public IConfiguration Configuration { get; } + + // This method gets called by the runtime. Use this method to add services to the container. + public void ConfigureServices(IServiceCollection services) + { + services.AddMediatR(typeof(Startup).GetTypeInfo().Assembly); + + services.AddTransient(typeof(IPipelineBehavior<,>), typeof(LoggingBehavior<,>)); + + services.AddDbContext(options => + { + options.UseSqlServer( + Configuration["ConnectionStrings"], + sqlServerOptionsAction: sqlOptions => + { + sqlOptions.MigrationsAssembly(typeof(AttendanceContext).GetTypeInfo().Assembly.GetName().Name); + sqlOptions.EnableRetryOnFailure(maxRetryCount: 15, maxRetryDelay: TimeSpan.FromSeconds(30), errorNumbersToAdd: null); + }); + }); + + services.AddGraphQLServer() + .AddQueryType(d => d.Name("Query")) + .AddType() + .AddMutationType() + .AddErrorFilter(); + + services.AddControllers() + .AddJsonOptions(options => + { + options.JsonSerializerOptions.IgnoreNullValues = true; + }) + .AddFluentValidation(fv => + fv.RegisterValidatorsFromAssemblyContaining()); + + services.AddCustomHealthChecks(Configuration); + + services.AddSwaggerGen(c => + { + c.SwaggerDoc("v1", new OpenApiInfo { Title = "Attendance HTTP API", Version = "v1" }); + }); + + services.AddOpenTelemetryIntegration(); + } + + // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. + public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILoggerFactory loggerFactory) + { + var pathBase = Configuration["PATH_BASE"]; + if (!string.IsNullOrEmpty(pathBase)) + { + loggerFactory.CreateLogger().LogInformation("Using PATH BASE '{pathBase}'", pathBase); + app.UsePathBase(pathBase); + } + + if (env.IsDevelopment()) + { + app.UseDeveloperExceptionPage(); + } + + app.UseSerilogRequestLogging(); + + app.UseSwagger() + .UseSwaggerUI(c => + { + c.SwaggerEndpoint($"{pathBase}/swagger/v1/swagger.json", "Attendance HTTP API"); + }); + + app.UseRouting(); + + app.UseAuthorization(); + + app.UseEndpoints(endpoints => + { + endpoints.MapControllers(); + + endpoints.MapHealthChecks("/hc", new HealthCheckOptions() + { + Predicate = _ => true, + ResponseWriter = UIResponseWriter.WriteHealthCheckUIResponse, + }); + endpoints.MapHealthChecks("/liveness", new HealthCheckOptions() + { + Predicate = r => r.Name.Contains("self", StringComparison.Ordinal), + }); + + endpoints.MapGraphQL(); + }); + } + } +} diff --git a/src/Services/Attendance/Attendance.API/WebHostExtensions.cs b/src/Services/Attendance/Attendance.API/WebHostExtensions.cs new file mode 100644 index 00000000..1d5f9814 --- /dev/null +++ b/src/Services/Attendance/Attendance.API/WebHostExtensions.cs @@ -0,0 +1,60 @@ +using System; +using Microsoft.Data.SqlClient; +using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; +using Microsoft.Extensions.Logging; +using Polly; + +namespace OpenCodeFoundation.ESchool.Services.Enrolling.API +{ + public static class WebHostExtensions + { + [System.Diagnostics.CodeAnalysis.SuppressMessage( + "Design", + "CA1031:Do not catch general exception types", + Justification = "Top level all exception catcher")] + public static IHost MigrateDbContext( + this IHost webHost, + Action seeder) + where TContext : DbContext + { + if (webHost == null) + { + throw new ArgumentNullException(nameof(webHost)); + } + + using var scope = webHost.Services.CreateScope(); + var services = scope.ServiceProvider; + var logger = services.GetRequiredService>(); + var context = services.GetRequiredService(); + + try + { + logger.LogInformation("Migrating database associated with context {ContextName}", typeof(TContext).Name); + + var retry = Policy.Handle() + .WaitAndRetry(new TimeSpan[] + { + TimeSpan.FromSeconds(5), + TimeSpan.FromSeconds(10), + TimeSpan.FromSeconds(15), + }); + + retry.Execute(() => + { + context.Database.Migrate(); + seeder(context, services); + }); + + logger.LogInformation($"Migrated database associated with context {typeof(TContext).Name}"); + } + catch (Exception ex) + { + logger.LogError(ex, $"An error occurred while migrating the databases used on context {typeof(TContext).Name}"); + } + + return webHost; + } + } +} diff --git a/src/Services/Attendance/Attendance.API/appsettings.json b/src/Services/Attendance/Attendance.API/appsettings.json new file mode 100644 index 00000000..eb2ca188 --- /dev/null +++ b/src/Services/Attendance/Attendance.API/appsettings.json @@ -0,0 +1,24 @@ +{ + "ConnectionStrings": "Server=tcp:127.0.0.1,5433;Database=OpenCodeFoundation.EnrollingDb;User Id=sa;Password=Pass@word;", + "Serilog": { + "MinimumLevel": { + "Default": "Information", + "Override": { + "Microsoft": "Warning", + "OpenCodeFoundation": "Information", + "System": "Warning" + } + } + }, + "AllowedHosts": "*", + "OpenTelemetry": { + "Enabled": true, + "Istio": false, + "Jaeger": { + "Enabled": true, + "ServiceName": "enrolling.api", + "Host": "jaeger", + "Port": 6831 + } + } +} \ No newline at end of file diff --git a/src/Services/Attendance/Attendance.API/graphql/AttendanceQuery.cs b/src/Services/Attendance/Attendance.API/graphql/AttendanceQuery.cs new file mode 100644 index 00000000..8a8a63a1 --- /dev/null +++ b/src/Services/Attendance/Attendance.API/graphql/AttendanceQuery.cs @@ -0,0 +1,43 @@ +using System; +using System.Collections.Generic; +using System.Threading; +using System.Threading.Tasks; +using HotChocolate; +using HotChocolate.Types; +using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.Logging; +using OpenCodeFoundation.ESchool.Services.Attendance.Domain.AggregatesModel.AttendanceAggregate; +using OpenCodeFoundation.ESchool.Services.Attendance.Infrastructure; + +namespace OpenCodeFoundation.ESchool.Services.Attendance.API.Graphql +{ + [System.Diagnostics.CodeAnalysis.SuppressMessage( + "Performance", + "CA1822:Mark members as static", + Justification = "GraphQL Query used by Hot Chocolate")] + [ExtendObjectType(Name = "Query")] + public class AttendanceQuery + { + public async Task> GetEnrollmentsAsync( + [Service] AttendanceContext context, + [Service] ILogger logger, + CancellationToken cancellationToken) + { + if (context == null) + { + throw new ArgumentNullException(nameof(context)); + } + + var attendances = await context.Attendances + .ToListAsync(cancellationToken) + .ConfigureAwait(false); + + logger.LogInformation( + "Returning attendances {AttendanceCount} with payload {@Attendance}", + attendances.Count, + attendances); + + return attendances; + } + } +} diff --git a/src/Services/Attendance/Attendance.API/graphql/GraphQlErrorFilter.cs b/src/Services/Attendance/Attendance.API/graphql/GraphQlErrorFilter.cs new file mode 100644 index 00000000..12907e95 --- /dev/null +++ b/src/Services/Attendance/Attendance.API/graphql/GraphQlErrorFilter.cs @@ -0,0 +1,20 @@ +using System; +using HotChocolate; + +namespace OpenCodeFoundation.ESchool.Services.Attendance.API.Graphql +{ + public class GraphQlErrorFilter + : IErrorFilter + { + public IError OnError(IError error) + { + if (error == null) + { + throw new ArgumentNullException(nameof(error)); + } + + return error.WithMessage( + error.Exception?.Message ?? string.Empty); + } + } +} diff --git a/src/Services/Attendance/Attendance.API/graphql/Mutation.cs b/src/Services/Attendance/Attendance.API/graphql/Mutation.cs new file mode 100644 index 00000000..1eec02cc --- /dev/null +++ b/src/Services/Attendance/Attendance.API/graphql/Mutation.cs @@ -0,0 +1,44 @@ +using System; +using System.Threading; +using System.Threading.Tasks; +using HotChocolate; +using OpenCodeFoundation.ESchool.Services.Attendance.API.Application.Commands; +using OpenCodeFoundation.ESchool.Services.Attendance.Domain.AggregatesModel.EnrollmentAggregate; +using OpenCodeFoundation.ESchool.Services.Attendance.Infrastructure; + +namespace OpenCodeFoundation.ESchool.Services.Attendance.API.Graphql +{ + [System.Diagnostics.CodeAnalysis.SuppressMessage( + "Performance", + "CA1822:Mark members as static", + Justification = "GraphQL mutation used by Hot Chocolate")] + public class Mutation + { + public async Task AddAttendanceAsync( + AttendanceApplicationCommand input, + [Service] AttendanceContext context, + CancellationToken cancellationToken) + { + if (input == null) + { + throw new ArgumentNullException(nameof(input)); + } + + if (context == null) + { + throw new ArgumentNullException(nameof(context)); + } + + var attendance = new Attendance( + input.Name, + input.Email, + input.Mobile); + + await context.Attendances.AddAsync(attendance, cancellationToken) + .ConfigureAwait(false); + await context.SaveChangesAsync(cancellationToken) + .ConfigureAwait(false); + return attendance; + } + } +} diff --git a/src/Services/Attendance/Attendance.Domain/AggregatesModel/AttendanceAggregate/Attendance.cs b/src/Services/Attendance/Attendance.Domain/AggregatesModel/AttendanceAggregate/Attendance.cs new file mode 100644 index 00000000..1c0eedb2 --- /dev/null +++ b/src/Services/Attendance/Attendance.Domain/AggregatesModel/AttendanceAggregate/Attendance.cs @@ -0,0 +1,28 @@ +using System; +using OpenCodeFoundation.ESchool.Services.Attendance.Domain.SeedWork; + +namespace OpenCodeFoundation.ESchool.Services.Attendance.Domain.AggregatesModel.AttendanceAggregate +{ + public class Attendance + : Entity, IAggregateRoot + { + public Attendance( + string name, + string emailAddress, + string mobileNumber) + { + Name = !string.IsNullOrWhiteSpace(name) ? name + : throw new ArgumentNullException(nameof(name)); + EmailAddress = !string.IsNullOrWhiteSpace(emailAddress) ? emailAddress + : throw new ArgumentNullException(nameof(emailAddress)); + MobileNumber = !string.IsNullOrWhiteSpace(mobileNumber) ? mobileNumber + : throw new ArgumentNullException(nameof(mobileNumber)); + } + + public string Name { get; private set; } + + public string EmailAddress { get; private set; } + + public string MobileNumber { get; private set; } + } +} diff --git a/src/Services/Attendance/Attendance.Domain/AggregatesModel/AttendanceAggregate/IAttendanceRepository.cs b/src/Services/Attendance/Attendance.Domain/AggregatesModel/AttendanceAggregate/IAttendanceRepository.cs new file mode 100644 index 00000000..17238b38 --- /dev/null +++ b/src/Services/Attendance/Attendance.Domain/AggregatesModel/AttendanceAggregate/IAttendanceRepository.cs @@ -0,0 +1,19 @@ +using System; +using System.Threading; +using System.Threading.Tasks; +using OpenCodeFoundation.ESchool.Services.Attendance.Domain.SeedWork; + +namespace OpenCodeFoundation.ESchool.Services.Attendance.Domain.AggregatesModel.AttendanceAggregate +{ + public interface IAttendanceRepository + : IRepository + { + Attendance Add(Attendance attendance); + + Attendance Update(Attendance attendance); + + Task FindByIdAsync( + Guid id, + CancellationToken cancellationToken = default); + } +} diff --git a/src/Services/Attendance/Attendance.Domain/Attendance.Domain.csproj b/src/Services/Attendance/Attendance.Domain/Attendance.Domain.csproj new file mode 100644 index 00000000..6b58a401 --- /dev/null +++ b/src/Services/Attendance/Attendance.Domain/Attendance.Domain.csproj @@ -0,0 +1,10 @@ + + + + net5.0 + + Attendance.Domain + OpenCodeFoundation.ESchool.Services.Attendance.Domain + + + diff --git a/src/Services/Attendance/Attendance.Domain/SeedWork/Entity.cs b/src/Services/Attendance/Attendance.Domain/SeedWork/Entity.cs new file mode 100644 index 00000000..3b1f2132 --- /dev/null +++ b/src/Services/Attendance/Attendance.Domain/SeedWork/Entity.cs @@ -0,0 +1,9 @@ +using System; + +namespace OpenCodeFoundation.ESchool.Services.Attendance.Domain.SeedWork +{ + public abstract class Entity + { + public Guid Id { get; protected set; } + } +} diff --git a/src/Services/Attendance/Attendance.Domain/SeedWork/IAggregateRoot.cs b/src/Services/Attendance/Attendance.Domain/SeedWork/IAggregateRoot.cs new file mode 100644 index 00000000..a5c0bdea --- /dev/null +++ b/src/Services/Attendance/Attendance.Domain/SeedWork/IAggregateRoot.cs @@ -0,0 +1,10 @@ +namespace OpenCodeFoundation.ESchool.Services.Attendance.Domain.SeedWork +{ + [System.Diagnostics.CodeAnalysis.SuppressMessage( + "Design", + "CA1040:Avoid empty interfaces", + Justification = "Marker interface")] + public interface IAggregateRoot + { + } +} diff --git a/src/Services/Attendance/Attendance.Domain/SeedWork/IRepository.cs b/src/Services/Attendance/Attendance.Domain/SeedWork/IRepository.cs new file mode 100644 index 00000000..c2a90eb1 --- /dev/null +++ b/src/Services/Attendance/Attendance.Domain/SeedWork/IRepository.cs @@ -0,0 +1,11 @@ +namespace OpenCodeFoundation.ESchool.Services.Attendance.Domain.SeedWork +{ + [System.Diagnostics.CodeAnalysis.SuppressMessage( + "Design", + "CA1040:Avoid empty interfaces", + Justification = "Marker interface")] + public interface IRepository + where T : IAggregateRoot + { + } +} diff --git a/src/Services/Attendance/Attendance.FunctionalTests/Attendance.FunctionalTests.csproj b/src/Services/Attendance/Attendance.FunctionalTests/Attendance.FunctionalTests.csproj new file mode 100644 index 00000000..30faf1db --- /dev/null +++ b/src/Services/Attendance/Attendance.FunctionalTests/Attendance.FunctionalTests.csproj @@ -0,0 +1,24 @@ + + + net5.0 + OpenCodeFoundation.ESchool.Services.Attendance.FunctionalTests + false + + + + + + + + + + + + + + + + Always + + + \ No newline at end of file diff --git a/src/Services/Attendance/Attendance.FunctionalTests/AttendanceTests.cs b/src/Services/Attendance/Attendance.FunctionalTests/AttendanceTests.cs new file mode 100644 index 00000000..297de354 --- /dev/null +++ b/src/Services/Attendance/Attendance.FunctionalTests/AttendanceTests.cs @@ -0,0 +1,24 @@ +using System.Threading.Tasks; +using Xunit; + +namespace OpenCodeFoundation.ESchool.Services.Attendance.FunctionalTests +{ + [Collection("TestServer")] + public class AttendanceTests + { + private readonly TestServerFixture _testServer; + + public AttendanceTests(TestServerFixture testServer) + { + _testServer = testServer ?? throw new System.ArgumentNullException(nameof(testServer)); + } + + [Fact] + public async Task Get_all_enrolling_ok_status_code() + { + var response = await _testServer.Client.GetAsync("/Enrollments"); + + response.EnsureSuccessStatusCode(); + } + } +} diff --git a/src/Services/Attendance/Attendance.FunctionalTests/TestServerCollection.cs b/src/Services/Attendance/Attendance.FunctionalTests/TestServerCollection.cs new file mode 100644 index 00000000..a6e19c97 --- /dev/null +++ b/src/Services/Attendance/Attendance.FunctionalTests/TestServerCollection.cs @@ -0,0 +1,13 @@ +using Xunit; + +namespace OpenCodeFoundation.ESchool.Services.Attendance.FunctionalTests +{ + [CollectionDefinition("TestServer")] + public class TestServerCollection + : ICollectionFixture + { + // This class has no code, and is never created. Its purpose is simply + // to be the place to apply [CollectionDefinition] and all the + // ICollectionFixture<> interfaces. + } +} diff --git a/src/Services/Attendance/Attendance.FunctionalTests/TestServerFixture.cs b/src/Services/Attendance/Attendance.FunctionalTests/TestServerFixture.cs new file mode 100644 index 00000000..487fef72 --- /dev/null +++ b/src/Services/Attendance/Attendance.FunctionalTests/TestServerFixture.cs @@ -0,0 +1,55 @@ +using System; +using System.IO; +using System.Net.Http; +using System.Reflection; +using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.TestHost; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Hosting; +using OpenCodeFoundation.ESchool.Services.Attendance.API; +using OpenCodeFoundation.ESchool.Services.Attendance.Infrastructure; +using Serilog; + +namespace OpenCodeFoundation.ESchool.Services.Attendance.FunctionalTests +{ + public class TestServerFixture + : IDisposable + { + public TestServerFixture() + { + WebHost = CreateHost(); + WebHost.MigrateDbContext((_, __) => { }); + } + + public HttpClient Client => WebHost.GetTestClient(); + + public IHost WebHost { get; } + + public IHost CreateHost() + { + var path = Assembly.GetAssembly(typeof(TestServerFixture)) + .Location; + + var builder = Host.CreateDefaultBuilder() + .UseContentRoot(Path.GetDirectoryName(path)) + .ConfigureWebHostDefaults(webBuilder => + { + webBuilder.UseTestServer(); + webBuilder.UseStartup(); + webBuilder.ConfigureAppConfiguration(config => + { + config.AddJsonFile("appsettings.json", optional: false) + .AddEnvironmentVariables(); + }); + webBuilder.UseSerilog(); + }); + + return builder.Start(); + } + + public void Dispose() + { + WebHost.Dispose(); + } + } +} diff --git a/src/Services/Attendance/Attendance.FunctionalTests/appsettings.json b/src/Services/Attendance/Attendance.FunctionalTests/appsettings.json new file mode 100644 index 00000000..5ca22b67 --- /dev/null +++ b/src/Services/Attendance/Attendance.FunctionalTests/appsettings.json @@ -0,0 +1,3 @@ +{ + "ConnectionStrings": "Server=tcp:127.0.0.1,5433;Database=OpenCodeFoundation.EnrollingDb;User Id=sa;Password=Pass@word;" +} \ No newline at end of file diff --git a/src/Services/Attendance/Attendance.Infrastructure/Attendance.Infrastructure.csproj b/src/Services/Attendance/Attendance.Infrastructure/Attendance.Infrastructure.csproj new file mode 100644 index 00000000..8cbdb761 --- /dev/null +++ b/src/Services/Attendance/Attendance.Infrastructure/Attendance.Infrastructure.csproj @@ -0,0 +1,14 @@ + + + net5.0 + Attendance.Infrastructure + OpenCodeFoundation.ESchool.Services.Attendance.Infrastructure + + + + + + + + + \ No newline at end of file diff --git a/src/Services/Attendance/Attendance.Infrastructure/AttendanceContext.cs b/src/Services/Attendance/Attendance.Infrastructure/AttendanceContext.cs new file mode 100644 index 00000000..1dfa0746 --- /dev/null +++ b/src/Services/Attendance/Attendance.Infrastructure/AttendanceContext.cs @@ -0,0 +1,33 @@ +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Design; + +namespace OpenCodeFoundation.ESchool.Services.Attendance.Infrastructure +{ + public class AttendanceContext + : DbContext + { + public AttendanceContext(DbContextOptions options) + : base(options) + { + } + + public DbSet Attendances { get; set; } = default!; + } + + /// + /// Helper class for creating migration. To create new migration, run the + /// command from `Enrolling.Intrastructure` folder. + /// + /// $ dotnet ef migrations add name_of_migration --startup-project ../Enrolling.API. + /// + public class AttendanceContextFactory : IDesignTimeDbContextFactory + { + public AttendanceContext CreateDbContext(string[] args) + { + var optionsBuilder = new DbContextOptionsBuilder() + .UseSqlServer("Server=.;Initial Catalog=OpenCodeFoundation.AttendanceDb;Integrated Security=true"); + + return new AttendanceContext(optionsBuilder.Options); + } + } +} diff --git a/src/Services/Attendance/Attendance.Infrastructure/Migrations/20200330154056_Initial.Designer.cs b/src/Services/Attendance/Attendance.Infrastructure/Migrations/20200330154056_Initial.Designer.cs new file mode 100644 index 00000000..45beed6c --- /dev/null +++ b/src/Services/Attendance/Attendance.Infrastructure/Migrations/20200330154056_Initial.Designer.cs @@ -0,0 +1,46 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using OpenCodeFoundation.ESchool.Services.Enrolling.Infrastructure; + +namespace OpenCodeFoundation.ESchool.Services.Enrolling.Infrastructure.Migrations +{ + [DbContext(typeof(AttendanceContext))] + [Migration("20200330154056_Initial")] + partial class Initial + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "3.1.3") + .HasAnnotation("Relational:MaxIdentifierLength", 128) + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + modelBuilder.Entity("OpenCodeFoundation.ESchool.Services.Enrolling.Domain.AggregatesModel.EnrollmentAggregate.Enrollment", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uniqueidentifier"); + + b.Property("EmailAddress") + .HasColumnType("nvarchar(max)"); + + b.Property("MobileNumber") + .HasColumnType("nvarchar(max)"); + + b.Property("Name") + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Enrollments"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/src/Services/Attendance/Attendance.Infrastructure/Migrations/20200330154056_Initial.cs b/src/Services/Attendance/Attendance.Infrastructure/Migrations/20200330154056_Initial.cs new file mode 100644 index 00000000..19aa3ecb --- /dev/null +++ b/src/Services/Attendance/Attendance.Infrastructure/Migrations/20200330154056_Initial.cs @@ -0,0 +1,32 @@ +// +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +namespace OpenCodeFoundation.ESchool.Services.Attendance.Infrastructure.Migrations +{ + public partial class Initial : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "Attendances", + columns: table => new + { + Id = table.Column(nullable: false), + Name = table.Column(nullable: true), + EmailAddress = table.Column(nullable: true), + MobileNumber = table.Column(nullable: true), + }, + constraints: table => + { + table.PrimaryKey("PK_Attendances", x => x.Id); + }); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "Attendances"); + } + } +} diff --git a/src/Services/Attendance/Attendance.Infrastructure/Migrations/AttendanceContextModelSnapshot.cs b/src/Services/Attendance/Attendance.Infrastructure/Migrations/AttendanceContextModelSnapshot.cs new file mode 100644 index 00000000..572ac04c --- /dev/null +++ b/src/Services/Attendance/Attendance.Infrastructure/Migrations/AttendanceContextModelSnapshot.cs @@ -0,0 +1,44 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using OpenCodeFoundation.ESchool.Services.Attendance.Infrastructure; + +namespace OpenCodeFoundation.ESchool.Services.Attendance.Infrastructure.Migrations +{ + [DbContext(typeof(AttendanceContext))] + partial class AttendanceContextModelSnapshot : ModelSnapshot + { + protected override void BuildModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "3.1.3") + .HasAnnotation("Relational:MaxIdentifierLength", 128) + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + modelBuilder.Entity("OpenCodeFoundation.ESchool.Services.Attendance.Domain.AggregatesModel.AttendanceAggregate.Attendance", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uniqueidentifier"); + + b.Property("EmailAddress") + .HasColumnType("nvarchar(max)"); + + b.Property("MobileNumber") + .HasColumnType("nvarchar(max)"); + + b.Property("Name") + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Attendances"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/src/Services/Attendance/Attendance.Infrastructure/Repositories/AttendanceRepository.cs b/src/Services/Attendance/Attendance.Infrastructure/Repositories/AttendanceRepository.cs new file mode 100644 index 00000000..9968d272 --- /dev/null +++ b/src/Services/Attendance/Attendance.Infrastructure/Repositories/AttendanceRepository.cs @@ -0,0 +1,44 @@ +using System; +using System.Linq; +using System.Threading; +using System.Threading.Tasks; +using Microsoft.EntityFrameworkCore; +using OpenCodeFoundation.ESchool.Services.Attendance.Domain.AggregatesModel.AttendanceAggregate; + +namespace OpenCodeFoundation.ESchool.Services.Attendance.Infrastructure.Repositories +{ + public class AttendanceRepository + : IAttendanceRepository + { + private readonly AttendanceContext _context; + + public AttendanceRepository(AttendanceContext context) + { + _context = context ?? throw new ArgumentNullException(nameof(context)); + } + + public Attendance Add(Attendance attendance) + { + return _context.Attendances + .Add(attendance) + .Entity; + } + + public async Task FindByIdAsync( + Guid id, + CancellationToken cancellationToken = default) + { + return await _context.Attendances + .Where(e => e.Id == id) + .SingleOrDefaultAsync(cancellationToken) + .ConfigureAwait(false); + } + + public Attendance Update(Attendance attendance) + { + return _context.Attendances + .Update(attendance) + .Entity; + } + } +} diff --git a/src/Services/Attendance/Attendance.UnitTests/Attendance.UnitTests.csproj b/src/Services/Attendance/Attendance.UnitTests/Attendance.UnitTests.csproj new file mode 100644 index 00000000..92382007 --- /dev/null +++ b/src/Services/Attendance/Attendance.UnitTests/Attendance.UnitTests.csproj @@ -0,0 +1,20 @@ + + + net5.0 + false + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + + \ No newline at end of file diff --git a/src/Services/Attendance/Attendance.UnitTests/Builders/AttendanceDto.cs b/src/Services/Attendance/Attendance.UnitTests/Builders/AttendanceDto.cs new file mode 100644 index 00000000..145ffd16 --- /dev/null +++ b/src/Services/Attendance/Attendance.UnitTests/Builders/AttendanceDto.cs @@ -0,0 +1,11 @@ +namespace Attendance.UnitTests.Builders +{ + public class AttendanceDto + { + public string? Name { get; set; } + + public string? Email { get; set; } + + public string? Mobile { get; set; } + } +} diff --git a/src/Services/Attendance/Attendance.UnitTests/Builders/AttendanceDtoBuilder.cs b/src/Services/Attendance/Attendance.UnitTests/Builders/AttendanceDtoBuilder.cs new file mode 100644 index 00000000..cd0d7d1f --- /dev/null +++ b/src/Services/Attendance/Attendance.UnitTests/Builders/AttendanceDtoBuilder.cs @@ -0,0 +1,45 @@ +namespace Attendance.UnitTests.Builders +{ + public class AttendanceDtoBuilder + { + private string? _name; + private string? _email; + private string? _mobile; + + public AttendanceDtoBuilder WithDefaults() + { + _name = "John Doe"; + _email = "john@example.com"; + _mobile = "01771999999"; + return this; + } + + public AttendanceDtoBuilder WithEmptyName() + { + _name = string.Empty; + return this; + } + + public AttendanceDtoBuilder WithEmail(string email) + { + _email = email; + return this; + } + + public AttendanceDtoBuilder WithMobile(string mobile) + { + _mobile = mobile; + return this; + } + + public AttendanceDto Build() + { + return new AttendanceDto + { + Name = _name, + Email = _email, + Mobile = _mobile, + }; + } + } +} diff --git a/src/Services/Attendance/Attendance.UnitTests/Domain/EnrollmentAggregateTests.cs b/src/Services/Attendance/Attendance.UnitTests/Domain/EnrollmentAggregateTests.cs new file mode 100644 index 00000000..35deae2c --- /dev/null +++ b/src/Services/Attendance/Attendance.UnitTests/Domain/EnrollmentAggregateTests.cs @@ -0,0 +1,58 @@ +using System; +using Enrolling.UnitTests.Builders; +using OpenCodeFoundation.ESchool.Services.Enrolling.Domain.AggregatesModel.EnrollmentAggregate; +using Xunit; + +namespace Enrolling.UnitTests.Domain +{ + public class EnrollmentAggregateTests + { + [Fact] + public void NewApplicationShouldSuccessWithValidInput() + { + var dto = new AttendanceDtoBuilder() + .WithDefaults() + .Build(); + + var enrollment = new Enrollment(dto.Name!, dto.Email!, dto.Mobile!); + + Assert.NotNull(enrollment); + Assert.Equal(dto.Name, enrollment.Name); + Assert.Equal(dto.Email, enrollment.EmailAddress); + Assert.Equal(dto.Mobile, enrollment.MobileNumber); + } + + [Fact] + public void ShouldThrowExceptionIfNameIsEmpty() + { + var dto = new AttendanceDtoBuilder() + .WithDefaults() + .WithEmptyName() + .Build(); + + Assert.Throws(() => new Enrollment(dto.Name!, dto.Email!, dto.Mobile!)); + } + + [Fact] + public void ShouldThrowExceptionEmtpyEmail() + { + var dto = new AttendanceDtoBuilder() + .WithDefaults() + .WithEmail(string.Empty) + .Build(); + + Assert.Throws(() => new Enrollment(dto.Name!, dto.Email!, dto.Mobile!)); + } + + [Fact] + public void ShouldThrowExceptionEmptyMobile() + { + var dto = new AttendanceDtoBuilder() + .WithDefaults() + .WithMobile(string.Empty) + .Build(); + + Assert.Throws(() => new Enrollment(dto.Name!, dto.Email!, dto.Mobile!)); + } + } +} From 9d870109e5ef520eebc03abba847d1d11253e076 Mon Sep 17 00:00:00 2001 From: "Md. Aftab Uddin Kajal" Date: Sat, 24 Apr 2021 05:32:07 +0600 Subject: [PATCH 2/5] Project file renaming and namespace update --- eSchool.sln | 22 +++---- .../Application/Behaviors/LoggingBehavior.cs | 2 +- .../Commands/AttendanceApplicationCommand.cs | 7 +-- .../AttendanceApplicationCommandHandler.cs | 7 +-- .../Queries/FindAllAttendancesHandler.cs | 11 ++-- .../Queries/FindAllAttendancesQuery.cs | 5 +- .../AttendanceApplicationCommandValidator.cs | 4 +- ...ndance.API.csproj => Attending.API.csproj} | 8 +-- .../Controllers/AttendancesController.cs | 11 ++-- .../Extensions/ServiceCollectionExtensions.cs | 2 +- .../Attendance/Attendance.API/Program.cs | 4 +- .../Attendance/Attendance.API/Startup.cs | 12 ++-- .../Attendance.API/WebHostExtensions.cs | 2 +- .../Attendance.API/graphql/AttendanceQuery.cs | 7 +-- .../graphql/GraphQlErrorFilter.cs | 2 +- .../Attendance.API/graphql/Mutation.cs | 16 +++-- .../AttendanceAggregate/Attendance.cs | 25 ++++---- .../IAttendanceRepository.cs | 4 +- .../Attendance.Domain.csproj | 10 ---- .../Attendance.Domain/Attending.Domain.csproj | 10 ++++ .../Attendance.Domain/SeedWork/Entity.cs | 2 +- .../SeedWork/IAggregateRoot.cs | 2 +- .../Attendance.Domain/SeedWork/IRepository.cs | 2 +- .../AttendanceTests.cs | 6 +- ...sproj => Attending.FunctionalTests.csproj} | 18 +++--- .../TestServerCollection.cs | 2 +- .../TestServerFixture.cs | 6 +- .../AttendanceContext.cs | 7 ++- ...csproj => Attending.Infrastructure.csproj} | 10 ++-- .../Migrations/20200330154056_Initial.cs | 7 +-- .../AttendanceContextModelSnapshot.cs | 10 +--- .../Repositories/AttendanceRepository.cs | 4 +- ...ests.csproj => Attending.UnitTests.csproj} | 14 ++--- .../Builders/AttendanceDto.cs | 8 +-- .../Builders/AttendanceDtoBuilder.cs | 35 +++-------- .../Domain/AttendanceAggregateTests.cs | 24 ++++++++ .../Domain/EnrollmentAggregateTests.cs | 58 ------------------- 37 files changed, 156 insertions(+), 230 deletions(-) rename src/Services/Attendance/Attendance.API/{Attendance.API.csproj => Attending.API.csproj} (89%) delete mode 100644 src/Services/Attendance/Attendance.Domain/Attendance.Domain.csproj create mode 100644 src/Services/Attendance/Attendance.Domain/Attending.Domain.csproj rename src/Services/Attendance/Attendance.FunctionalTests/{Attendance.FunctionalTests.csproj => Attending.FunctionalTests.csproj} (63%) rename src/Services/Attendance/Attendance.Infrastructure/{Attendance.Infrastructure.csproj => Attending.Infrastructure.csproj} (56%) rename src/Services/Attendance/Attendance.UnitTests/{Attendance.UnitTests.csproj => Attending.UnitTests.csproj} (67%) create mode 100644 src/Services/Attendance/Attendance.UnitTests/Domain/AttendanceAggregateTests.cs delete mode 100644 src/Services/Attendance/Attendance.UnitTests/Domain/EnrollmentAggregateTests.cs diff --git a/eSchool.sln b/eSchool.sln index 92eb66cc..0b22ece3 100644 --- a/eSchool.sln +++ b/eSchool.sln @@ -27,31 +27,31 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WebStatus", "src\Web\WebSta EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Libraries", "Libraries", "{74511F4E-FF9D-42C4-9531-A75C61270B73}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenTelemetry", "src\Libraries\OpenTelemetry\OpenTelemetry.csproj", "{7B410F3B-36E0-4853-9B4E-41D0CC2865B5}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenTelemetry", "src\Libraries\OpenTelemetry\OpenTelemetry.csproj", "{7B410F3B-36E0-4853-9B4E-41D0CC2865B5}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "ApiGateways", "ApiGateways", "{256317ED-A2C8-48A0-9C6E-D6EB1F7D0BE0}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "eSchool.GraphQL", "src\ApiGateways\eSchool.GraphQL\eSchool.GraphQL.csproj", "{4053591A-1C1A-4A81-8496-F2FF7EAB2D5C}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "eSchool.GraphQL", "src\ApiGateways\eSchool.GraphQL\eSchool.GraphQL.csproj", "{4053591A-1C1A-4A81-8496-F2FF7EAB2D5C}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Frontend.Blazor", "Frontend.Blazor", "{0C00A596-0FE3-4FA6-B54B-FE2BE83371EF}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Frontend.Blazor.Client", "src\Web\Frontend.Blazor\Frontend.Blazor.Client\Frontend.Blazor.Client.csproj", "{53F4E6F9-6B91-45F9-97F9-F6EFA0EBEFCE}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Frontend.Blazor.Client", "src\Web\Frontend.Blazor\Frontend.Blazor.Client\Frontend.Blazor.Client.csproj", "{53F4E6F9-6B91-45F9-97F9-F6EFA0EBEFCE}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Frontend.Blazor.Server", "src\Web\Frontend.Blazor\Frontend.Blazor.Server\Frontend.Blazor.Server.csproj", "{3BABD4D9-56A1-4BA3-B30C-30E6765AB389}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Frontend.Blazor.Server", "src\Web\Frontend.Blazor\Frontend.Blazor.Server\Frontend.Blazor.Server.csproj", "{3BABD4D9-56A1-4BA3-B30C-30E6765AB389}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Frontend.Blazor.Shared", "src\Web\Frontend.Blazor\Frontend.Blazor.Shared\Frontend.Blazor.Shared.csproj", "{4EB86635-CF79-4D15-909E-C41C98B0B586}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Frontend.Blazor.Shared", "src\Web\Frontend.Blazor\Frontend.Blazor.Shared\Frontend.Blazor.Shared.csproj", "{4EB86635-CF79-4D15-909E-C41C98B0B586}" EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Attendance", "Attendance", "{2BE71A01-0660-4264-B03F-8A386AB840ED}" +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Attending", "Attending", "{2BE71A01-0660-4264-B03F-8A386AB840ED}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Attendance.API", "src\Services\Attendance\Attendance.API\Attendance.API.csproj", "{2A2976A2-4578-49D1-BC3B-A9D466837CCB}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Attending.API", "src\Services\Attendance\Attendance.API\Attending.API.csproj", "{2A2976A2-4578-49D1-BC3B-A9D466837CCB}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Attendance.Domain", "src\Services\Attendance\Attendance.Domain\Attendance.Domain.csproj", "{69EAD5CE-01BD-4132-B65B-69EAC7DA10AF}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Attending.Domain", "src\Services\Attendance\Attendance.Domain\Attending.Domain.csproj", "{69EAD5CE-01BD-4132-B65B-69EAC7DA10AF}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Attendance.FunctionalTests", "src\Services\Attendance\Attendance.FunctionalTests\Attendance.FunctionalTests.csproj", "{020D0652-9802-431D-836A-B9ED27D841A2}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Attending.FunctionalTests", "src\Services\Attendance\Attendance.FunctionalTests\Attending.FunctionalTests.csproj", "{020D0652-9802-431D-836A-B9ED27D841A2}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Attendance.Infrastructure", "src\Services\Attendance\Attendance.Infrastructure\Attendance.Infrastructure.csproj", "{767C29FF-C92E-424D-84D4-FF606FACD07A}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Attending.Infrastructure", "src\Services\Attendance\Attendance.Infrastructure\Attending.Infrastructure.csproj", "{767C29FF-C92E-424D-84D4-FF606FACD07A}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Attendance.UnitTests", "src\Services\Attendance\Attendance.UnitTests\Attendance.UnitTests.csproj", "{0D9BD20E-7EBC-4689-B621-676440441223}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Attending.UnitTests", "src\Services\Attendance\Attendance.UnitTests\Attending.UnitTests.csproj", "{0D9BD20E-7EBC-4689-B621-676440441223}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution diff --git a/src/Services/Attendance/Attendance.API/Application/Behaviors/LoggingBehavior.cs b/src/Services/Attendance/Attendance.API/Application/Behaviors/LoggingBehavior.cs index 80086d6b..6b67304e 100644 --- a/src/Services/Attendance/Attendance.API/Application/Behaviors/LoggingBehavior.cs +++ b/src/Services/Attendance/Attendance.API/Application/Behaviors/LoggingBehavior.cs @@ -3,7 +3,7 @@ using MediatR; using Microsoft.Extensions.Logging; -namespace OpenCodeFoundation.ESchool.Services.Attendance.API.Application.Behaviors +namespace OpenCodeFoundation.ESchool.Services.Attending.API.Application.Behaviors { public class LoggingBehavior : IPipelineBehavior diff --git a/src/Services/Attendance/Attendance.API/Application/Commands/AttendanceApplicationCommand.cs b/src/Services/Attendance/Attendance.API/Application/Commands/AttendanceApplicationCommand.cs index 5c441efc..e995ff5a 100644 --- a/src/Services/Attendance/Attendance.API/Application/Commands/AttendanceApplicationCommand.cs +++ b/src/Services/Attendance/Attendance.API/Application/Commands/AttendanceApplicationCommand.cs @@ -1,10 +1,9 @@ using MediatR; -namespace OpenCodeFoundation.ESchool.Services.Attendance.API.Application.Commands +namespace OpenCodeFoundation.ESchool.Services.Attending.API.Application.Commands { public record AttendanceApplicationCommand( - string Name, - string Email, - string Mobile) + string StudentId, + string CourseId) : IRequest; } diff --git a/src/Services/Attendance/Attendance.API/Application/Commands/AttendanceApplicationCommandHandler.cs b/src/Services/Attendance/Attendance.API/Application/Commands/AttendanceApplicationCommandHandler.cs index 3de5992b..ba3b0738 100644 --- a/src/Services/Attendance/Attendance.API/Application/Commands/AttendanceApplicationCommandHandler.cs +++ b/src/Services/Attendance/Attendance.API/Application/Commands/AttendanceApplicationCommandHandler.cs @@ -3,10 +3,9 @@ using System.Threading.Tasks; using MediatR; using Microsoft.Extensions.Logging; -using OpenCodeFoundation.ESchool.Services.Attendance.Domain.AggregatesModel.AttendanceAggregate; -using OpenCodeFoundation.ESchool.Services.Attendance.Infrastructure; +using OpenCodeFoundation.ESchool.Services.Attending.Infrastructure; -namespace OpenCodeFoundation.ESchool.Services.Attendance.API.Application.Commands +namespace OpenCodeFoundation.ESchool.Services.Attending.API.Application.Commands { public sealed class AttendanceApplicationCommandHandler : IRequestHandler @@ -31,7 +30,7 @@ public async Task Handle( throw new ArgumentNullException(nameof(command)); } - var attendance = new Attendance(command.Name, command.Email, command.Mobile); + var attendance = new Domain.AggregatesModel.AttendanceAggregate.Attendance(command.StudentId, command.CourseId); await _context.Attendances.AddAsync(attendance, cancellationToken) .ConfigureAwait(false); await _context.SaveChangesAsync(cancellationToken) diff --git a/src/Services/Attendance/Attendance.API/Application/Queries/FindAllAttendancesHandler.cs b/src/Services/Attendance/Attendance.API/Application/Queries/FindAllAttendancesHandler.cs index fef4eaa6..8213995e 100644 --- a/src/Services/Attendance/Attendance.API/Application/Queries/FindAllAttendancesHandler.cs +++ b/src/Services/Attendance/Attendance.API/Application/Queries/FindAllAttendancesHandler.cs @@ -3,13 +3,12 @@ using System.Threading.Tasks; using MediatR; using Microsoft.EntityFrameworkCore; -using OpenCodeFoundation.ESchool.Services.Enrolling.Domain.AggregatesModel.EnrollmentAggregate; -using OpenCodeFoundation.ESchool.Services.Enrolling.Infrastructure; +using OpenCodeFoundation.ESchool.Services.Attending.Infrastructure; -namespace OpenCodeFoundation.ESchool.Services.Enrolling.API.Application.Queries +namespace OpenCodeFoundation.ESchool.Services.Attending.API.Application.Queries { public class FindAllAttendancesHandler - : IRequestHandler> + : IRequestHandler> { private readonly AttendanceContext _context; @@ -18,11 +17,11 @@ public FindAllAttendancesHandler(AttendanceContext context) _context = context ?? throw new System.ArgumentNullException(nameof(context)); } - public async Task> Handle( + public async Task> Handle( FindAllAttendancesQuery request, CancellationToken cancellationToken) { - return await _context.Enrollments.ToListAsync(cancellationToken) + return await _context.Attendances.ToListAsync(cancellationToken) .ConfigureAwait(false); } } diff --git a/src/Services/Attendance/Attendance.API/Application/Queries/FindAllAttendancesQuery.cs b/src/Services/Attendance/Attendance.API/Application/Queries/FindAllAttendancesQuery.cs index 746c064d..945d463b 100644 --- a/src/Services/Attendance/Attendance.API/Application/Queries/FindAllAttendancesQuery.cs +++ b/src/Services/Attendance/Attendance.API/Application/Queries/FindAllAttendancesQuery.cs @@ -1,11 +1,10 @@ using System.Collections.Generic; using MediatR; -using OpenCodeFoundation.ESchool.Services.Attendance.Domain.AggregatesModel.EnrollmentAggregate; -namespace OpenCodeFoundation.ESchool.Services.Attendance.API.Application.Queries +namespace OpenCodeFoundation.ESchool.Services.Attending.API.Application.Queries { public class FindAllAttendancesQuery - : IRequest> + : IRequest> { } } diff --git a/src/Services/Attendance/Attendance.API/Application/Validations/AttendanceApplicationCommandValidator.cs b/src/Services/Attendance/Attendance.API/Application/Validations/AttendanceApplicationCommandValidator.cs index aa44c763..97e958ef 100644 --- a/src/Services/Attendance/Attendance.API/Application/Validations/AttendanceApplicationCommandValidator.cs +++ b/src/Services/Attendance/Attendance.API/Application/Validations/AttendanceApplicationCommandValidator.cs @@ -1,7 +1,7 @@ using FluentValidation; -using OpenCodeFoundation.ESchool.Services.Attendance.API.Application.Commands; +using OpenCodeFoundation.ESchool.Services.Attending.API.Application.Commands; -namespace OpenCodeFoundation.ESchool.Services.Attendance.API.Application.Validations +namespace OpenCodeFoundation.ESchool.Services.Attending.API.Application.Validations { public class AttendanceApplicationCommandValidator : AbstractValidator diff --git a/src/Services/Attendance/Attendance.API/Attendance.API.csproj b/src/Services/Attendance/Attendance.API/Attending.API.csproj similarity index 89% rename from src/Services/Attendance/Attendance.API/Attendance.API.csproj rename to src/Services/Attendance/Attendance.API/Attending.API.csproj index 2b13f835..5907651c 100644 --- a/src/Services/Attendance/Attendance.API/Attendance.API.csproj +++ b/src/Services/Attendance/Attendance.API/Attending.API.csproj @@ -1,8 +1,8 @@ - + net5.0 Attendance.API - OpenCodeFoundation.ESchool.Services.Attendance.API + OpenCodeFoundation.ESchool.Services.Attending.API @@ -32,9 +32,9 @@ - - + + diff --git a/src/Services/Attendance/Attendance.API/Controllers/AttendancesController.cs b/src/Services/Attendance/Attendance.API/Controllers/AttendancesController.cs index 0bb4ad5d..9b87152d 100644 --- a/src/Services/Attendance/Attendance.API/Controllers/AttendancesController.cs +++ b/src/Services/Attendance/Attendance.API/Controllers/AttendancesController.cs @@ -4,11 +4,10 @@ using System.Threading.Tasks; using MediatR; using Microsoft.AspNetCore.Mvc; -using OpenCodeFoundation.ESchool.Services.Attendance.API.Application.Commands; -using OpenCodeFoundation.ESchool.Services.Attendance.API.Application.Queries; -using OpenCodeFoundation.ESchool.Services.Attendance.Domain.AggregatesModel.EnrollmentAggregate; +using OpenCodeFoundation.ESchool.Services.Attending.API.Application.Commands; +using OpenCodeFoundation.ESchool.Services.Attending.API.Application.Queries; -namespace OpenCodeFoundation.ESchool.Services.Attendance.API.Controllers +namespace OpenCodeFoundation.ESchool.Services.Attending.API.Controllers { [ApiController] [Route("[controller]")] @@ -22,8 +21,8 @@ public AttendancesController(IMediator mediator) } [HttpGet] - public async Task> Get(CancellationToken cancellationToken) - => await _mediator.Send(new FindAllEnrollmentsQuery(), cancellationToken) + public async Task> Get(CancellationToken cancellationToken) + => await _mediator.Send(new FindAllAttendancesQuery(), cancellationToken) .ConfigureAwait(false); [HttpPost] diff --git a/src/Services/Attendance/Attendance.API/Extensions/ServiceCollectionExtensions.cs b/src/Services/Attendance/Attendance.API/Extensions/ServiceCollectionExtensions.cs index 74a45bae..8688afae 100644 --- a/src/Services/Attendance/Attendance.API/Extensions/ServiceCollectionExtensions.cs +++ b/src/Services/Attendance/Attendance.API/Extensions/ServiceCollectionExtensions.cs @@ -3,7 +3,7 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Diagnostics.HealthChecks; -namespace OpenCodeFoundation.ESchool.Services.Attendance.API.Extensions +namespace OpenCodeFoundation.ESchool.Services.Attending.API.Extensions { public static class ServiceCollectionExtensions { diff --git a/src/Services/Attendance/Attendance.API/Program.cs b/src/Services/Attendance/Attendance.API/Program.cs index 34d2697f..ec8e11b2 100644 --- a/src/Services/Attendance/Attendance.API/Program.cs +++ b/src/Services/Attendance/Attendance.API/Program.cs @@ -4,11 +4,11 @@ using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Hosting; -using OpenCodeFoundation.ESchool.Services.Attendance.Infrastructure; +using OpenCodeFoundation.ESchool.Services.Attending.Infrastructure; using Serilog; using Serilog.Enrichers.Span; -namespace OpenCodeFoundation.ESchool.Services.Attendance.API +namespace OpenCodeFoundation.ESchool.Services.Attending.API { public static class Program { diff --git a/src/Services/Attendance/Attendance.API/Startup.cs b/src/Services/Attendance/Attendance.API/Startup.cs index d12c1d82..121a7fe9 100644 --- a/src/Services/Attendance/Attendance.API/Startup.cs +++ b/src/Services/Attendance/Attendance.API/Startup.cs @@ -12,15 +12,15 @@ using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; using Microsoft.OpenApi.Models; -using OpenCodeFoundation.ESchool.Services.Attendance.API.Application.Behaviors; -using OpenCodeFoundation.ESchool.Services.Attendance.API.Application.Validations; -using OpenCodeFoundation.ESchool.Services.Attendance.API.Extensions; -using OpenCodeFoundation.ESchool.Services.Attendance.API.Graphql; -using OpenCodeFoundation.ESchool.Services.Attendance.Infrastructure; +using OpenCodeFoundation.ESchool.Services.Attending.API.Application.Behaviors; +using OpenCodeFoundation.ESchool.Services.Attending.API.Application.Validations; +using OpenCodeFoundation.ESchool.Services.Attending.API.Extensions; +using OpenCodeFoundation.ESchool.Services.Attending.API.Graphql; +using OpenCodeFoundation.ESchool.Services.Attending.Infrastructure; using OpenCodeFoundation.OpenTelemetry; using Serilog; -namespace OpenCodeFoundation.ESchool.Services.Attendance.API +namespace OpenCodeFoundation.ESchool.Services.Attending.API { public class Startup { diff --git a/src/Services/Attendance/Attendance.API/WebHostExtensions.cs b/src/Services/Attendance/Attendance.API/WebHostExtensions.cs index 1d5f9814..28305477 100644 --- a/src/Services/Attendance/Attendance.API/WebHostExtensions.cs +++ b/src/Services/Attendance/Attendance.API/WebHostExtensions.cs @@ -6,7 +6,7 @@ using Microsoft.Extensions.Logging; using Polly; -namespace OpenCodeFoundation.ESchool.Services.Enrolling.API +namespace OpenCodeFoundation.ESchool.Services.Attending.API { public static class WebHostExtensions { diff --git a/src/Services/Attendance/Attendance.API/graphql/AttendanceQuery.cs b/src/Services/Attendance/Attendance.API/graphql/AttendanceQuery.cs index 8a8a63a1..f2247c44 100644 --- a/src/Services/Attendance/Attendance.API/graphql/AttendanceQuery.cs +++ b/src/Services/Attendance/Attendance.API/graphql/AttendanceQuery.cs @@ -6,10 +6,9 @@ using HotChocolate.Types; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Logging; -using OpenCodeFoundation.ESchool.Services.Attendance.Domain.AggregatesModel.AttendanceAggregate; -using OpenCodeFoundation.ESchool.Services.Attendance.Infrastructure; +using OpenCodeFoundation.ESchool.Services.Attending.Infrastructure; -namespace OpenCodeFoundation.ESchool.Services.Attendance.API.Graphql +namespace OpenCodeFoundation.ESchool.Services.Attending.API.Graphql { [System.Diagnostics.CodeAnalysis.SuppressMessage( "Performance", @@ -18,7 +17,7 @@ namespace OpenCodeFoundation.ESchool.Services.Attendance.API.Graphql [ExtendObjectType(Name = "Query")] public class AttendanceQuery { - public async Task> GetEnrollmentsAsync( + public async Task> GetEnrollmentsAsync( [Service] AttendanceContext context, [Service] ILogger logger, CancellationToken cancellationToken) diff --git a/src/Services/Attendance/Attendance.API/graphql/GraphQlErrorFilter.cs b/src/Services/Attendance/Attendance.API/graphql/GraphQlErrorFilter.cs index 12907e95..9fe3bcd4 100644 --- a/src/Services/Attendance/Attendance.API/graphql/GraphQlErrorFilter.cs +++ b/src/Services/Attendance/Attendance.API/graphql/GraphQlErrorFilter.cs @@ -1,7 +1,7 @@ using System; using HotChocolate; -namespace OpenCodeFoundation.ESchool.Services.Attendance.API.Graphql +namespace OpenCodeFoundation.ESchool.Services.Attending.API.Graphql { public class GraphQlErrorFilter : IErrorFilter diff --git a/src/Services/Attendance/Attendance.API/graphql/Mutation.cs b/src/Services/Attendance/Attendance.API/graphql/Mutation.cs index 1eec02cc..a3750ce7 100644 --- a/src/Services/Attendance/Attendance.API/graphql/Mutation.cs +++ b/src/Services/Attendance/Attendance.API/graphql/Mutation.cs @@ -2,11 +2,10 @@ using System.Threading; using System.Threading.Tasks; using HotChocolate; -using OpenCodeFoundation.ESchool.Services.Attendance.API.Application.Commands; -using OpenCodeFoundation.ESchool.Services.Attendance.Domain.AggregatesModel.EnrollmentAggregate; -using OpenCodeFoundation.ESchool.Services.Attendance.Infrastructure; +using OpenCodeFoundation.ESchool.Services.Attending.API.Application.Commands; +using OpenCodeFoundation.ESchool.Services.Attending.Infrastructure; -namespace OpenCodeFoundation.ESchool.Services.Attendance.API.Graphql +namespace OpenCodeFoundation.ESchool.Services.Attending.API.Graphql { [System.Diagnostics.CodeAnalysis.SuppressMessage( "Performance", @@ -14,7 +13,7 @@ namespace OpenCodeFoundation.ESchool.Services.Attendance.API.Graphql Justification = "GraphQL mutation used by Hot Chocolate")] public class Mutation { - public async Task AddAttendanceAsync( + public async Task AddAttendanceAsync( AttendanceApplicationCommand input, [Service] AttendanceContext context, CancellationToken cancellationToken) @@ -29,10 +28,9 @@ public async Task AddAttendanceAsync( throw new ArgumentNullException(nameof(context)); } - var attendance = new Attendance( - input.Name, - input.Email, - input.Mobile); + var attendance = new Domain.AggregatesModel.AttendanceAggregate.Attendance( + input.StudentId, + input.CourseId); await context.Attendances.AddAsync(attendance, cancellationToken) .ConfigureAwait(false); diff --git a/src/Services/Attendance/Attendance.Domain/AggregatesModel/AttendanceAggregate/Attendance.cs b/src/Services/Attendance/Attendance.Domain/AggregatesModel/AttendanceAggregate/Attendance.cs index 1c0eedb2..be2792ec 100644 --- a/src/Services/Attendance/Attendance.Domain/AggregatesModel/AttendanceAggregate/Attendance.cs +++ b/src/Services/Attendance/Attendance.Domain/AggregatesModel/AttendanceAggregate/Attendance.cs @@ -1,28 +1,23 @@ using System; -using OpenCodeFoundation.ESchool.Services.Attendance.Domain.SeedWork; +using OpenCodeFoundation.ESchool.Services.Attending.Domain.SeedWork; -namespace OpenCodeFoundation.ESchool.Services.Attendance.Domain.AggregatesModel.AttendanceAggregate +namespace OpenCodeFoundation.ESchool.Services.Attending.Domain.AggregatesModel.AttendanceAggregate { public class Attendance : Entity, IAggregateRoot { public Attendance( - string name, - string emailAddress, - string mobileNumber) + string studentId, + string courseId) { - Name = !string.IsNullOrWhiteSpace(name) ? name - : throw new ArgumentNullException(nameof(name)); - EmailAddress = !string.IsNullOrWhiteSpace(emailAddress) ? emailAddress - : throw new ArgumentNullException(nameof(emailAddress)); - MobileNumber = !string.IsNullOrWhiteSpace(mobileNumber) ? mobileNumber - : throw new ArgumentNullException(nameof(mobileNumber)); + StudentId = !string.IsNullOrWhiteSpace(studentId) ? studentId + : throw new ArgumentNullException(nameof(studentId)); + CourseId = !string.IsNullOrWhiteSpace(courseId) ? courseId + : throw new ArgumentNullException(nameof(courseId)); } - public string Name { get; private set; } + public string StudentId { get; private set; } - public string EmailAddress { get; private set; } - - public string MobileNumber { get; private set; } + public string CourseId { get; private set; } } } diff --git a/src/Services/Attendance/Attendance.Domain/AggregatesModel/AttendanceAggregate/IAttendanceRepository.cs b/src/Services/Attendance/Attendance.Domain/AggregatesModel/AttendanceAggregate/IAttendanceRepository.cs index 17238b38..afc57fcb 100644 --- a/src/Services/Attendance/Attendance.Domain/AggregatesModel/AttendanceAggregate/IAttendanceRepository.cs +++ b/src/Services/Attendance/Attendance.Domain/AggregatesModel/AttendanceAggregate/IAttendanceRepository.cs @@ -1,9 +1,9 @@ using System; using System.Threading; using System.Threading.Tasks; -using OpenCodeFoundation.ESchool.Services.Attendance.Domain.SeedWork; +using OpenCodeFoundation.ESchool.Services.Attending.Domain.SeedWork; -namespace OpenCodeFoundation.ESchool.Services.Attendance.Domain.AggregatesModel.AttendanceAggregate +namespace OpenCodeFoundation.ESchool.Services.Attending.Domain.AggregatesModel.AttendanceAggregate { public interface IAttendanceRepository : IRepository diff --git a/src/Services/Attendance/Attendance.Domain/Attendance.Domain.csproj b/src/Services/Attendance/Attendance.Domain/Attendance.Domain.csproj deleted file mode 100644 index 6b58a401..00000000 --- a/src/Services/Attendance/Attendance.Domain/Attendance.Domain.csproj +++ /dev/null @@ -1,10 +0,0 @@ - - - - net5.0 - - Attendance.Domain - OpenCodeFoundation.ESchool.Services.Attendance.Domain - - - diff --git a/src/Services/Attendance/Attendance.Domain/Attending.Domain.csproj b/src/Services/Attendance/Attendance.Domain/Attending.Domain.csproj new file mode 100644 index 00000000..b88b57c1 --- /dev/null +++ b/src/Services/Attendance/Attendance.Domain/Attending.Domain.csproj @@ -0,0 +1,10 @@ + + + + net5.0 + + Attending.Domain + OpenCodeFoundation.ESchool.Services.Attending.Domain + + + diff --git a/src/Services/Attendance/Attendance.Domain/SeedWork/Entity.cs b/src/Services/Attendance/Attendance.Domain/SeedWork/Entity.cs index 3b1f2132..75110785 100644 --- a/src/Services/Attendance/Attendance.Domain/SeedWork/Entity.cs +++ b/src/Services/Attendance/Attendance.Domain/SeedWork/Entity.cs @@ -1,6 +1,6 @@ using System; -namespace OpenCodeFoundation.ESchool.Services.Attendance.Domain.SeedWork +namespace OpenCodeFoundation.ESchool.Services.Attending.Domain.SeedWork { public abstract class Entity { diff --git a/src/Services/Attendance/Attendance.Domain/SeedWork/IAggregateRoot.cs b/src/Services/Attendance/Attendance.Domain/SeedWork/IAggregateRoot.cs index a5c0bdea..07c297f9 100644 --- a/src/Services/Attendance/Attendance.Domain/SeedWork/IAggregateRoot.cs +++ b/src/Services/Attendance/Attendance.Domain/SeedWork/IAggregateRoot.cs @@ -1,4 +1,4 @@ -namespace OpenCodeFoundation.ESchool.Services.Attendance.Domain.SeedWork +namespace OpenCodeFoundation.ESchool.Services.Attending.Domain.SeedWork { [System.Diagnostics.CodeAnalysis.SuppressMessage( "Design", diff --git a/src/Services/Attendance/Attendance.Domain/SeedWork/IRepository.cs b/src/Services/Attendance/Attendance.Domain/SeedWork/IRepository.cs index c2a90eb1..c5982e2b 100644 --- a/src/Services/Attendance/Attendance.Domain/SeedWork/IRepository.cs +++ b/src/Services/Attendance/Attendance.Domain/SeedWork/IRepository.cs @@ -1,4 +1,4 @@ -namespace OpenCodeFoundation.ESchool.Services.Attendance.Domain.SeedWork +namespace OpenCodeFoundation.ESchool.Services.Attending.Domain.SeedWork { [System.Diagnostics.CodeAnalysis.SuppressMessage( "Design", diff --git a/src/Services/Attendance/Attendance.FunctionalTests/AttendanceTests.cs b/src/Services/Attendance/Attendance.FunctionalTests/AttendanceTests.cs index 297de354..7ed6d341 100644 --- a/src/Services/Attendance/Attendance.FunctionalTests/AttendanceTests.cs +++ b/src/Services/Attendance/Attendance.FunctionalTests/AttendanceTests.cs @@ -1,7 +1,7 @@ using System.Threading.Tasks; using Xunit; -namespace OpenCodeFoundation.ESchool.Services.Attendance.FunctionalTests +namespace OpenCodeFoundation.ESchool.Services.Attending.FunctionalTests { [Collection("TestServer")] public class AttendanceTests @@ -14,9 +14,9 @@ public AttendanceTests(TestServerFixture testServer) } [Fact] - public async Task Get_all_enrolling_ok_status_code() + public async Task Get_all_attending_ok_status_code() { - var response = await _testServer.Client.GetAsync("/Enrollments"); + var response = await _testServer.Client.GetAsync("/Attendances"); response.EnsureSuccessStatusCode(); } diff --git a/src/Services/Attendance/Attendance.FunctionalTests/Attendance.FunctionalTests.csproj b/src/Services/Attendance/Attendance.FunctionalTests/Attending.FunctionalTests.csproj similarity index 63% rename from src/Services/Attendance/Attendance.FunctionalTests/Attendance.FunctionalTests.csproj rename to src/Services/Attendance/Attendance.FunctionalTests/Attending.FunctionalTests.csproj index 30faf1db..2d7e9cb5 100644 --- a/src/Services/Attendance/Attendance.FunctionalTests/Attendance.FunctionalTests.csproj +++ b/src/Services/Attendance/Attendance.FunctionalTests/Attending.FunctionalTests.csproj @@ -1,20 +1,20 @@ net5.0 - OpenCodeFoundation.ESchool.Services.Attendance.FunctionalTests + OpenCodeFoundation.ESchool.Services.Attending.FunctionalTests false - - - - - + + + + + - - - + + + diff --git a/src/Services/Attendance/Attendance.FunctionalTests/TestServerCollection.cs b/src/Services/Attendance/Attendance.FunctionalTests/TestServerCollection.cs index a6e19c97..6cbf7356 100644 --- a/src/Services/Attendance/Attendance.FunctionalTests/TestServerCollection.cs +++ b/src/Services/Attendance/Attendance.FunctionalTests/TestServerCollection.cs @@ -1,6 +1,6 @@ using Xunit; -namespace OpenCodeFoundation.ESchool.Services.Attendance.FunctionalTests +namespace OpenCodeFoundation.ESchool.Services.Attending.FunctionalTests { [CollectionDefinition("TestServer")] public class TestServerCollection diff --git a/src/Services/Attendance/Attendance.FunctionalTests/TestServerFixture.cs b/src/Services/Attendance/Attendance.FunctionalTests/TestServerFixture.cs index 487fef72..28ab60fc 100644 --- a/src/Services/Attendance/Attendance.FunctionalTests/TestServerFixture.cs +++ b/src/Services/Attendance/Attendance.FunctionalTests/TestServerFixture.cs @@ -6,11 +6,11 @@ using Microsoft.AspNetCore.TestHost; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Hosting; -using OpenCodeFoundation.ESchool.Services.Attendance.API; -using OpenCodeFoundation.ESchool.Services.Attendance.Infrastructure; +using OpenCodeFoundation.ESchool.Services.Attending.API; +using OpenCodeFoundation.ESchool.Services.Attending.Infrastructure; using Serilog; -namespace OpenCodeFoundation.ESchool.Services.Attendance.FunctionalTests +namespace OpenCodeFoundation.ESchool.Services.Attending.FunctionalTests { public class TestServerFixture : IDisposable diff --git a/src/Services/Attendance/Attendance.Infrastructure/AttendanceContext.cs b/src/Services/Attendance/Attendance.Infrastructure/AttendanceContext.cs index 1dfa0746..14dfa82d 100644 --- a/src/Services/Attendance/Attendance.Infrastructure/AttendanceContext.cs +++ b/src/Services/Attendance/Attendance.Infrastructure/AttendanceContext.cs @@ -1,7 +1,8 @@ using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Design; +using OpenCodeFoundation.ESchool.Services.Attending.Domain.AggregatesModel.AttendanceAggregate; -namespace OpenCodeFoundation.ESchool.Services.Attendance.Infrastructure +namespace OpenCodeFoundation.ESchool.Services.Attending.Infrastructure { public class AttendanceContext : DbContext @@ -11,14 +12,14 @@ public AttendanceContext(DbContextOptions options) { } - public DbSet Attendances { get; set; } = default!; + public DbSet Attendances { get; set; } = default!; } /// /// Helper class for creating migration. To create new migration, run the /// command from `Enrolling.Intrastructure` folder. /// - /// $ dotnet ef migrations add name_of_migration --startup-project ../Enrolling.API. + /// $ dotnet ef migrations add name_of_migration --startup-project ../Attending.API. /// public class AttendanceContextFactory : IDesignTimeDbContextFactory { diff --git a/src/Services/Attendance/Attendance.Infrastructure/Attendance.Infrastructure.csproj b/src/Services/Attendance/Attendance.Infrastructure/Attending.Infrastructure.csproj similarity index 56% rename from src/Services/Attendance/Attendance.Infrastructure/Attendance.Infrastructure.csproj rename to src/Services/Attendance/Attendance.Infrastructure/Attending.Infrastructure.csproj index 8cbdb761..4b9fb66b 100644 --- a/src/Services/Attendance/Attendance.Infrastructure/Attendance.Infrastructure.csproj +++ b/src/Services/Attendance/Attendance.Infrastructure/Attending.Infrastructure.csproj @@ -1,14 +1,14 @@ - + net5.0 Attendance.Infrastructure - OpenCodeFoundation.ESchool.Services.Attendance.Infrastructure + OpenCodeFoundation.ESchool.Services.Attending.Infrastructure - + - - + + \ No newline at end of file diff --git a/src/Services/Attendance/Attendance.Infrastructure/Migrations/20200330154056_Initial.cs b/src/Services/Attendance/Attendance.Infrastructure/Migrations/20200330154056_Initial.cs index 19aa3ecb..67096569 100644 --- a/src/Services/Attendance/Attendance.Infrastructure/Migrations/20200330154056_Initial.cs +++ b/src/Services/Attendance/Attendance.Infrastructure/Migrations/20200330154056_Initial.cs @@ -2,7 +2,7 @@ using System; using Microsoft.EntityFrameworkCore.Migrations; -namespace OpenCodeFoundation.ESchool.Services.Attendance.Infrastructure.Migrations +namespace OpenCodeFoundation.ESchool.Services.Attending.Infrastructure.Migrations { public partial class Initial : Migration { @@ -13,9 +13,8 @@ protected override void Up(MigrationBuilder migrationBuilder) columns: table => new { Id = table.Column(nullable: false), - Name = table.Column(nullable: true), - EmailAddress = table.Column(nullable: true), - MobileNumber = table.Column(nullable: true), + StudentId = table.Column(nullable: false), + CourseId = table.Column(nullable: false) }, constraints: table => { diff --git a/src/Services/Attendance/Attendance.Infrastructure/Migrations/AttendanceContextModelSnapshot.cs b/src/Services/Attendance/Attendance.Infrastructure/Migrations/AttendanceContextModelSnapshot.cs index 572ac04c..3ecb28eb 100644 --- a/src/Services/Attendance/Attendance.Infrastructure/Migrations/AttendanceContextModelSnapshot.cs +++ b/src/Services/Attendance/Attendance.Infrastructure/Migrations/AttendanceContextModelSnapshot.cs @@ -3,10 +3,9 @@ using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Metadata; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; using OpenCodeFoundation.ESchool.Services.Attendance.Infrastructure; -namespace OpenCodeFoundation.ESchool.Services.Attendance.Infrastructure.Migrations +namespace OpenCodeFoundation.ESchool.Services.Attending.Infrastructure.Migrations { [DbContext(typeof(AttendanceContext))] partial class AttendanceContextModelSnapshot : ModelSnapshot @@ -25,13 +24,10 @@ protected override void BuildModel(ModelBuilder modelBuilder) .ValueGeneratedOnAdd() .HasColumnType("uniqueidentifier"); - b.Property("EmailAddress") + b.Property("StudentId") .HasColumnType("nvarchar(max)"); - b.Property("MobileNumber") - .HasColumnType("nvarchar(max)"); - - b.Property("Name") + b.Property("CourseId") .HasColumnType("nvarchar(max)"); b.HasKey("Id"); diff --git a/src/Services/Attendance/Attendance.Infrastructure/Repositories/AttendanceRepository.cs b/src/Services/Attendance/Attendance.Infrastructure/Repositories/AttendanceRepository.cs index 9968d272..302613fe 100644 --- a/src/Services/Attendance/Attendance.Infrastructure/Repositories/AttendanceRepository.cs +++ b/src/Services/Attendance/Attendance.Infrastructure/Repositories/AttendanceRepository.cs @@ -3,9 +3,9 @@ using System.Threading; using System.Threading.Tasks; using Microsoft.EntityFrameworkCore; -using OpenCodeFoundation.ESchool.Services.Attendance.Domain.AggregatesModel.AttendanceAggregate; +using OpenCodeFoundation.ESchool.Services.Attending.Domain.AggregatesModel.AttendanceAggregate; -namespace OpenCodeFoundation.ESchool.Services.Attendance.Infrastructure.Repositories +namespace OpenCodeFoundation.ESchool.Services.Attending.Infrastructure.Repositories { public class AttendanceRepository : IAttendanceRepository diff --git a/src/Services/Attendance/Attendance.UnitTests/Attendance.UnitTests.csproj b/src/Services/Attendance/Attendance.UnitTests/Attending.UnitTests.csproj similarity index 67% rename from src/Services/Attendance/Attendance.UnitTests/Attendance.UnitTests.csproj rename to src/Services/Attendance/Attendance.UnitTests/Attending.UnitTests.csproj index 92382007..0d73abf0 100644 --- a/src/Services/Attendance/Attendance.UnitTests/Attendance.UnitTests.csproj +++ b/src/Services/Attendance/Attendance.UnitTests/Attending.UnitTests.csproj @@ -1,20 +1,20 @@ - + net5.0 false - - + + all runtime; build; native; contentfiles; analyzers; buildtransitive - + - - - + + + \ No newline at end of file diff --git a/src/Services/Attendance/Attendance.UnitTests/Builders/AttendanceDto.cs b/src/Services/Attendance/Attendance.UnitTests/Builders/AttendanceDto.cs index 145ffd16..d9aa5c5f 100644 --- a/src/Services/Attendance/Attendance.UnitTests/Builders/AttendanceDto.cs +++ b/src/Services/Attendance/Attendance.UnitTests/Builders/AttendanceDto.cs @@ -1,11 +1,9 @@ -namespace Attendance.UnitTests.Builders +namespace Attending.UnitTests.Builders { public class AttendanceDto { - public string? Name { get; set; } + public string? StudentId { get; set; } - public string? Email { get; set; } - - public string? Mobile { get; set; } + public string? CourseId { get; set; } } } diff --git a/src/Services/Attendance/Attendance.UnitTests/Builders/AttendanceDtoBuilder.cs b/src/Services/Attendance/Attendance.UnitTests/Builders/AttendanceDtoBuilder.cs index cd0d7d1f..da0c356b 100644 --- a/src/Services/Attendance/Attendance.UnitTests/Builders/AttendanceDtoBuilder.cs +++ b/src/Services/Attendance/Attendance.UnitTests/Builders/AttendanceDtoBuilder.cs @@ -1,34 +1,14 @@ -namespace Attendance.UnitTests.Builders +namespace Attending.UnitTests.Builders { public class AttendanceDtoBuilder { - private string? _name; - private string? _email; - private string? _mobile; + private string? _studentId; + private string? _courseId; public AttendanceDtoBuilder WithDefaults() { - _name = "John Doe"; - _email = "john@example.com"; - _mobile = "01771999999"; - return this; - } - - public AttendanceDtoBuilder WithEmptyName() - { - _name = string.Empty; - return this; - } - - public AttendanceDtoBuilder WithEmail(string email) - { - _email = email; - return this; - } - - public AttendanceDtoBuilder WithMobile(string mobile) - { - _mobile = mobile; + _studentId = "2d16af83-15b7-4e28-be1d-25ed1630a365"; + _courseId = "8a5e3a17-115f-4df6-b6e4-000441a6b672"; return this; } @@ -36,9 +16,8 @@ public AttendanceDto Build() { return new AttendanceDto { - Name = _name, - Email = _email, - Mobile = _mobile, + StudentId = _studentId, + CourseId = _courseId }; } } diff --git a/src/Services/Attendance/Attendance.UnitTests/Domain/AttendanceAggregateTests.cs b/src/Services/Attendance/Attendance.UnitTests/Domain/AttendanceAggregateTests.cs new file mode 100644 index 00000000..eff1055c --- /dev/null +++ b/src/Services/Attendance/Attendance.UnitTests/Domain/AttendanceAggregateTests.cs @@ -0,0 +1,24 @@ +using Attending.UnitTests.Builders; +using OpenCodeFoundation.ESchool.Services.Attending.Domain.AggregatesModel.AttendanceAggregate; +using Xunit; + +namespace Attending.UnitTests.Domain +{ + public class AttendanceAggregateTests + { + [Fact] + public void NewApplicationShouldSuccessWithValidInput() + { + var dto = new AttendanceDtoBuilder() + .WithDefaults() + .Build(); + + var attendance = new Attendance(dto.StudentId!, dto.CourseId!); + + Assert.NotNull(attendance); + Assert.Equal(dto.StudentId, attendance.StudentId); + Assert.Equal(dto.CourseId, attendance.CourseId); + } + + } +} diff --git a/src/Services/Attendance/Attendance.UnitTests/Domain/EnrollmentAggregateTests.cs b/src/Services/Attendance/Attendance.UnitTests/Domain/EnrollmentAggregateTests.cs deleted file mode 100644 index 35deae2c..00000000 --- a/src/Services/Attendance/Attendance.UnitTests/Domain/EnrollmentAggregateTests.cs +++ /dev/null @@ -1,58 +0,0 @@ -using System; -using Enrolling.UnitTests.Builders; -using OpenCodeFoundation.ESchool.Services.Enrolling.Domain.AggregatesModel.EnrollmentAggregate; -using Xunit; - -namespace Enrolling.UnitTests.Domain -{ - public class EnrollmentAggregateTests - { - [Fact] - public void NewApplicationShouldSuccessWithValidInput() - { - var dto = new AttendanceDtoBuilder() - .WithDefaults() - .Build(); - - var enrollment = new Enrollment(dto.Name!, dto.Email!, dto.Mobile!); - - Assert.NotNull(enrollment); - Assert.Equal(dto.Name, enrollment.Name); - Assert.Equal(dto.Email, enrollment.EmailAddress); - Assert.Equal(dto.Mobile, enrollment.MobileNumber); - } - - [Fact] - public void ShouldThrowExceptionIfNameIsEmpty() - { - var dto = new AttendanceDtoBuilder() - .WithDefaults() - .WithEmptyName() - .Build(); - - Assert.Throws(() => new Enrollment(dto.Name!, dto.Email!, dto.Mobile!)); - } - - [Fact] - public void ShouldThrowExceptionEmtpyEmail() - { - var dto = new AttendanceDtoBuilder() - .WithDefaults() - .WithEmail(string.Empty) - .Build(); - - Assert.Throws(() => new Enrollment(dto.Name!, dto.Email!, dto.Mobile!)); - } - - [Fact] - public void ShouldThrowExceptionEmptyMobile() - { - var dto = new AttendanceDtoBuilder() - .WithDefaults() - .WithMobile(string.Empty) - .Build(); - - Assert.Throws(() => new Enrollment(dto.Name!, dto.Email!, dto.Mobile!)); - } - } -} From 99d496d3c04f9121c6191d991bb675303f31dda4 Mon Sep 17 00:00:00 2001 From: "Md. Aftab Uddin Kajal" Date: Sat, 24 Apr 2021 05:45:19 +0600 Subject: [PATCH 3/5] Docker File updated --- .../Attendance/Attendance.API/Dockerfile | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/Services/Attendance/Attendance.API/Dockerfile b/src/Services/Attendance/Attendance.API/Dockerfile index 26772158..f19202e6 100644 --- a/src/Services/Attendance/Attendance.API/Dockerfile +++ b/src/Services/Attendance/Attendance.API/Dockerfile @@ -9,11 +9,11 @@ COPY "eSchool.sln" "eSchool.sln" COPY "src/ApiGateways/eSchool.GraphQL/eSchool.GraphQL.csproj" "src/ApiGateways/eSchool.GraphQL/eSchool.GraphQL.csproj" -COPY "src/Services/Enrolling/Enrolling.API/Enrolling.API.csproj" "src/Services/Enrolling/Enrolling.API/Enrolling.API.csproj" -COPY "src/Services/Enrolling/Enrolling.Domain/Enrolling.Domain.csproj" "src/Services/Enrolling/Enrolling.Domain/Enrolling.Domain.csproj" -COPY "src/Services/Enrolling/Enrolling.Infrastructure/Enrolling.Infrastructure.csproj" "src/Services/Enrolling/Enrolling.Infrastructure/Enrolling.Infrastructure.csproj" -COPY "src/Services/Enrolling/Enrolling.UnitTests/Enrolling.UnitTests.csproj" "src/Services/Enrolling/Enrolling.UnitTests/Enrolling.UnitTests.csproj" -COPY "src/Services/Enrolling/Enrolling.FunctionalTests/Enrolling.FunctionalTests.csproj" "src/Services/Enrolling/Enrolling.FunctionalTests/Enrolling.FunctionalTests.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" @@ -28,14 +28,14 @@ COPY "docker-compose.dcproj" "docker-compose.dcproj" RUN dotnet restore eSchool.sln -nowarn:msb3202,nu1503 COPY . . -WORKDIR /src/src/Services/Enrolling/Enrolling.API +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/Enrolling/Enrolling.UnitTests +WORKDIR /src/src/Services/Attending/Attending.UnitTests FROM build as functionaltest -WORKDIR /src/src/Services/Enrolling/Enrolling.FunctionalTests +WORKDIR /src/src/Services/Attending/Attending.FunctionalTests FROM build AS publish RUN dotnet publish --no-restore -c Release -o /app/publish @@ -43,4 +43,4 @@ RUN dotnet publish --no-restore -c Release -o /app/publish FROM base AS final WORKDIR /app COPY --from=publish /app/publish . -ENTRYPOINT ["dotnet", "Enrolling.API.dll"] \ No newline at end of file +ENTRYPOINT ["dotnet", "Attending.API.dll"] \ No newline at end of file From b3db5ccb464c4d13e674a113d38d641c64812411 Mon Sep 17 00:00:00 2001 From: "Md. Aftab Uddin Kajal" Date: Sat, 24 Apr 2021 05:56:00 +0600 Subject: [PATCH 4/5] Update appings and fix typo error --- .../Attendance.API/appsettings.json | 24 +++++++++---------- .../AttendanceContextModelSnapshot.cs | 1 - 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/src/Services/Attendance/Attendance.API/appsettings.json b/src/Services/Attendance/Attendance.API/appsettings.json index eb2ca188..fca964ca 100644 --- a/src/Services/Attendance/Attendance.API/appsettings.json +++ b/src/Services/Attendance/Attendance.API/appsettings.json @@ -1,5 +1,16 @@ { - "ConnectionStrings": "Server=tcp:127.0.0.1,5433;Database=OpenCodeFoundation.EnrollingDb;User Id=sa;Password=Pass@word;", + "AllowedHosts": "*", + "ConnectionStrings": "Server=tcp:127.0.0.1,5433;Database=OpenCodeFoundation.AttendingDb;User Id=sa;Password=Pass@word;", + "OpenTelemetry": { + "Enabled": true, + "Istio": false, + "Jaeger": { + "Enabled": true, + "ServiceName": "attending.api", + "Host": "jaeger", + "Port": 6833 + } + }, "Serilog": { "MinimumLevel": { "Default": "Information", @@ -9,16 +20,5 @@ "System": "Warning" } } - }, - "AllowedHosts": "*", - "OpenTelemetry": { - "Enabled": true, - "Istio": false, - "Jaeger": { - "Enabled": true, - "ServiceName": "enrolling.api", - "Host": "jaeger", - "Port": 6831 - } } } \ No newline at end of file diff --git a/src/Services/Attendance/Attendance.Infrastructure/Migrations/AttendanceContextModelSnapshot.cs b/src/Services/Attendance/Attendance.Infrastructure/Migrations/AttendanceContextModelSnapshot.cs index 3ecb28eb..2c24d785 100644 --- a/src/Services/Attendance/Attendance.Infrastructure/Migrations/AttendanceContextModelSnapshot.cs +++ b/src/Services/Attendance/Attendance.Infrastructure/Migrations/AttendanceContextModelSnapshot.cs @@ -3,7 +3,6 @@ using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Metadata; -using OpenCodeFoundation.ESchool.Services.Attendance.Infrastructure; namespace OpenCodeFoundation.ESchool.Services.Attending.Infrastructure.Migrations { From 90feee49fe47d59fc60f91b3c299c164ef63a68d Mon Sep 17 00:00:00 2001 From: "Md. Aftab Uddin Kajal" Date: Sun, 2 May 2021 01:21:54 +0600 Subject: [PATCH 5/5] Removed unnecessary code --- .../Queries/FindAllAttendancesHandler.cs | 28 ----------- .../Queries/FindAllAttendancesQuery.cs | 10 ---- .../AttendanceApplicationCommandValidator.cs | 5 +- .../Controllers/AttendancesController.cs | 7 --- .../Attendance/Attendance.API/Startup.cs | 6 --- .../Attendance.API/graphql/AttendanceQuery.cs | 42 ----------------- .../graphql/GraphQlErrorFilter.cs | 20 -------- .../Attendance.API/graphql/Mutation.cs | 42 ----------------- .../Attending.Infrastructure.csproj | 3 ++ .../20200330154056_Initial.Designer.cs | 46 ------------------- .../Migrations/20200330154056_Initial.cs | 31 ------------- 11 files changed, 5 insertions(+), 235 deletions(-) delete mode 100644 src/Services/Attendance/Attendance.API/Application/Queries/FindAllAttendancesHandler.cs delete mode 100644 src/Services/Attendance/Attendance.API/Application/Queries/FindAllAttendancesQuery.cs delete mode 100644 src/Services/Attendance/Attendance.API/graphql/AttendanceQuery.cs delete mode 100644 src/Services/Attendance/Attendance.API/graphql/GraphQlErrorFilter.cs delete mode 100644 src/Services/Attendance/Attendance.API/graphql/Mutation.cs delete mode 100644 src/Services/Attendance/Attendance.Infrastructure/Migrations/20200330154056_Initial.Designer.cs delete mode 100644 src/Services/Attendance/Attendance.Infrastructure/Migrations/20200330154056_Initial.cs diff --git a/src/Services/Attendance/Attendance.API/Application/Queries/FindAllAttendancesHandler.cs b/src/Services/Attendance/Attendance.API/Application/Queries/FindAllAttendancesHandler.cs deleted file mode 100644 index 8213995e..00000000 --- a/src/Services/Attendance/Attendance.API/Application/Queries/FindAllAttendancesHandler.cs +++ /dev/null @@ -1,28 +0,0 @@ -using System.Collections.Generic; -using System.Threading; -using System.Threading.Tasks; -using MediatR; -using Microsoft.EntityFrameworkCore; -using OpenCodeFoundation.ESchool.Services.Attending.Infrastructure; - -namespace OpenCodeFoundation.ESchool.Services.Attending.API.Application.Queries -{ - public class FindAllAttendancesHandler - : IRequestHandler> - { - private readonly AttendanceContext _context; - - public FindAllAttendancesHandler(AttendanceContext context) - { - _context = context ?? throw new System.ArgumentNullException(nameof(context)); - } - - public async Task> Handle( - FindAllAttendancesQuery request, - CancellationToken cancellationToken) - { - return await _context.Attendances.ToListAsync(cancellationToken) - .ConfigureAwait(false); - } - } -} diff --git a/src/Services/Attendance/Attendance.API/Application/Queries/FindAllAttendancesQuery.cs b/src/Services/Attendance/Attendance.API/Application/Queries/FindAllAttendancesQuery.cs deleted file mode 100644 index 945d463b..00000000 --- a/src/Services/Attendance/Attendance.API/Application/Queries/FindAllAttendancesQuery.cs +++ /dev/null @@ -1,10 +0,0 @@ -using System.Collections.Generic; -using MediatR; - -namespace OpenCodeFoundation.ESchool.Services.Attending.API.Application.Queries -{ - public class FindAllAttendancesQuery - : IRequest> - { - } -} diff --git a/src/Services/Attendance/Attendance.API/Application/Validations/AttendanceApplicationCommandValidator.cs b/src/Services/Attendance/Attendance.API/Application/Validations/AttendanceApplicationCommandValidator.cs index 97e958ef..473a2197 100644 --- a/src/Services/Attendance/Attendance.API/Application/Validations/AttendanceApplicationCommandValidator.cs +++ b/src/Services/Attendance/Attendance.API/Application/Validations/AttendanceApplicationCommandValidator.cs @@ -8,9 +8,8 @@ public class AttendanceApplicationCommandValidator { public AttendanceApplicationCommandValidator() { - RuleFor(application => application.Name).NotEmpty(); - RuleFor(application => application.Email).NotEmpty().EmailAddress(); - RuleFor(application => application.Mobile).NotEmpty(); + RuleFor(application => application.CourseId).NotEmpty(); + RuleFor(application => application.StudentId).NotEmpty(); } } } diff --git a/src/Services/Attendance/Attendance.API/Controllers/AttendancesController.cs b/src/Services/Attendance/Attendance.API/Controllers/AttendancesController.cs index 9b87152d..0ed9f06e 100644 --- a/src/Services/Attendance/Attendance.API/Controllers/AttendancesController.cs +++ b/src/Services/Attendance/Attendance.API/Controllers/AttendancesController.cs @@ -1,11 +1,9 @@ using System; -using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; using MediatR; using Microsoft.AspNetCore.Mvc; using OpenCodeFoundation.ESchool.Services.Attending.API.Application.Commands; -using OpenCodeFoundation.ESchool.Services.Attending.API.Application.Queries; namespace OpenCodeFoundation.ESchool.Services.Attending.API.Controllers { @@ -20,11 +18,6 @@ public AttendancesController(IMediator mediator) _mediator = mediator ?? throw new ArgumentNullException(nameof(mediator)); } - [HttpGet] - public async Task> Get(CancellationToken cancellationToken) - => await _mediator.Send(new FindAllAttendancesQuery(), cancellationToken) - .ConfigureAwait(false); - [HttpPost] public async Task Post( [FromBody] AttendanceApplicationCommand command, diff --git a/src/Services/Attendance/Attendance.API/Startup.cs b/src/Services/Attendance/Attendance.API/Startup.cs index 121a7fe9..d45a96b1 100644 --- a/src/Services/Attendance/Attendance.API/Startup.cs +++ b/src/Services/Attendance/Attendance.API/Startup.cs @@ -15,7 +15,6 @@ using OpenCodeFoundation.ESchool.Services.Attending.API.Application.Behaviors; using OpenCodeFoundation.ESchool.Services.Attending.API.Application.Validations; using OpenCodeFoundation.ESchool.Services.Attending.API.Extensions; -using OpenCodeFoundation.ESchool.Services.Attending.API.Graphql; using OpenCodeFoundation.ESchool.Services.Attending.Infrastructure; using OpenCodeFoundation.OpenTelemetry; using Serilog; @@ -49,11 +48,6 @@ public void ConfigureServices(IServiceCollection services) }); }); - services.AddGraphQLServer() - .AddQueryType(d => d.Name("Query")) - .AddType() - .AddMutationType() - .AddErrorFilter(); services.AddControllers() .AddJsonOptions(options => diff --git a/src/Services/Attendance/Attendance.API/graphql/AttendanceQuery.cs b/src/Services/Attendance/Attendance.API/graphql/AttendanceQuery.cs deleted file mode 100644 index f2247c44..00000000 --- a/src/Services/Attendance/Attendance.API/graphql/AttendanceQuery.cs +++ /dev/null @@ -1,42 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Threading; -using System.Threading.Tasks; -using HotChocolate; -using HotChocolate.Types; -using Microsoft.EntityFrameworkCore; -using Microsoft.Extensions.Logging; -using OpenCodeFoundation.ESchool.Services.Attending.Infrastructure; - -namespace OpenCodeFoundation.ESchool.Services.Attending.API.Graphql -{ - [System.Diagnostics.CodeAnalysis.SuppressMessage( - "Performance", - "CA1822:Mark members as static", - Justification = "GraphQL Query used by Hot Chocolate")] - [ExtendObjectType(Name = "Query")] - public class AttendanceQuery - { - public async Task> GetEnrollmentsAsync( - [Service] AttendanceContext context, - [Service] ILogger logger, - CancellationToken cancellationToken) - { - if (context == null) - { - throw new ArgumentNullException(nameof(context)); - } - - var attendances = await context.Attendances - .ToListAsync(cancellationToken) - .ConfigureAwait(false); - - logger.LogInformation( - "Returning attendances {AttendanceCount} with payload {@Attendance}", - attendances.Count, - attendances); - - return attendances; - } - } -} diff --git a/src/Services/Attendance/Attendance.API/graphql/GraphQlErrorFilter.cs b/src/Services/Attendance/Attendance.API/graphql/GraphQlErrorFilter.cs deleted file mode 100644 index 9fe3bcd4..00000000 --- a/src/Services/Attendance/Attendance.API/graphql/GraphQlErrorFilter.cs +++ /dev/null @@ -1,20 +0,0 @@ -using System; -using HotChocolate; - -namespace OpenCodeFoundation.ESchool.Services.Attending.API.Graphql -{ - public class GraphQlErrorFilter - : IErrorFilter - { - public IError OnError(IError error) - { - if (error == null) - { - throw new ArgumentNullException(nameof(error)); - } - - return error.WithMessage( - error.Exception?.Message ?? string.Empty); - } - } -} diff --git a/src/Services/Attendance/Attendance.API/graphql/Mutation.cs b/src/Services/Attendance/Attendance.API/graphql/Mutation.cs deleted file mode 100644 index a3750ce7..00000000 --- a/src/Services/Attendance/Attendance.API/graphql/Mutation.cs +++ /dev/null @@ -1,42 +0,0 @@ -using System; -using System.Threading; -using System.Threading.Tasks; -using HotChocolate; -using OpenCodeFoundation.ESchool.Services.Attending.API.Application.Commands; -using OpenCodeFoundation.ESchool.Services.Attending.Infrastructure; - -namespace OpenCodeFoundation.ESchool.Services.Attending.API.Graphql -{ - [System.Diagnostics.CodeAnalysis.SuppressMessage( - "Performance", - "CA1822:Mark members as static", - Justification = "GraphQL mutation used by Hot Chocolate")] - public class Mutation - { - public async Task AddAttendanceAsync( - AttendanceApplicationCommand input, - [Service] AttendanceContext context, - CancellationToken cancellationToken) - { - if (input == null) - { - throw new ArgumentNullException(nameof(input)); - } - - if (context == null) - { - throw new ArgumentNullException(nameof(context)); - } - - var attendance = new Domain.AggregatesModel.AttendanceAggregate.Attendance( - input.StudentId, - input.CourseId); - - await context.Attendances.AddAsync(attendance, cancellationToken) - .ConfigureAwait(false); - await context.SaveChangesAsync(cancellationToken) - .ConfigureAwait(false); - return attendance; - } - } -} diff --git a/src/Services/Attendance/Attendance.Infrastructure/Attending.Infrastructure.csproj b/src/Services/Attendance/Attendance.Infrastructure/Attending.Infrastructure.csproj index 4b9fb66b..cb9f3104 100644 --- a/src/Services/Attendance/Attendance.Infrastructure/Attending.Infrastructure.csproj +++ b/src/Services/Attendance/Attendance.Infrastructure/Attending.Infrastructure.csproj @@ -11,4 +11,7 @@ + + + \ No newline at end of file diff --git a/src/Services/Attendance/Attendance.Infrastructure/Migrations/20200330154056_Initial.Designer.cs b/src/Services/Attendance/Attendance.Infrastructure/Migrations/20200330154056_Initial.Designer.cs deleted file mode 100644 index 45beed6c..00000000 --- a/src/Services/Attendance/Attendance.Infrastructure/Migrations/20200330154056_Initial.Designer.cs +++ /dev/null @@ -1,46 +0,0 @@ -// -using System; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Metadata; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -using OpenCodeFoundation.ESchool.Services.Enrolling.Infrastructure; - -namespace OpenCodeFoundation.ESchool.Services.Enrolling.Infrastructure.Migrations -{ - [DbContext(typeof(AttendanceContext))] - [Migration("20200330154056_Initial")] - partial class Initial - { - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("ProductVersion", "3.1.3") - .HasAnnotation("Relational:MaxIdentifierLength", 128) - .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); - - modelBuilder.Entity("OpenCodeFoundation.ESchool.Services.Enrolling.Domain.AggregatesModel.EnrollmentAggregate.Enrollment", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uniqueidentifier"); - - b.Property("EmailAddress") - .HasColumnType("nvarchar(max)"); - - b.Property("MobileNumber") - .HasColumnType("nvarchar(max)"); - - b.Property("Name") - .HasColumnType("nvarchar(max)"); - - b.HasKey("Id"); - - b.ToTable("Enrollments"); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/src/Services/Attendance/Attendance.Infrastructure/Migrations/20200330154056_Initial.cs b/src/Services/Attendance/Attendance.Infrastructure/Migrations/20200330154056_Initial.cs deleted file mode 100644 index 67096569..00000000 --- a/src/Services/Attendance/Attendance.Infrastructure/Migrations/20200330154056_Initial.cs +++ /dev/null @@ -1,31 +0,0 @@ -// -using System; -using Microsoft.EntityFrameworkCore.Migrations; - -namespace OpenCodeFoundation.ESchool.Services.Attending.Infrastructure.Migrations -{ - public partial class Initial : Migration - { - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.CreateTable( - name: "Attendances", - columns: table => new - { - Id = table.Column(nullable: false), - StudentId = table.Column(nullable: false), - CourseId = table.Column(nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Attendances", x => x.Id); - }); - } - - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropTable( - name: "Attendances"); - } - } -}