mirror of
https://github.com/farcasclaudiu/PracticeCalendar.git
synced 2026-06-22 03:01:14 +03:00
WIP refactoring
This commit is contained in:
@@ -13,7 +13,7 @@ namespace PrcaticeCalendar.Controllers
|
||||
{
|
||||
private readonly IRepository<PracticeEvent> eventsRepo;
|
||||
private readonly IMapper mapper;
|
||||
private readonly ILogger<EventsController> _logger;
|
||||
private readonly ILogger<EventsController> logger;
|
||||
|
||||
public EventsController(IRepository<PracticeEvent> eventsRepo,
|
||||
IMapper mapper,
|
||||
@@ -21,12 +21,13 @@ namespace PrcaticeCalendar.Controllers
|
||||
{
|
||||
this.eventsRepo = eventsRepo;
|
||||
this.mapper = mapper;
|
||||
_logger = logger;
|
||||
this.logger = logger;
|
||||
}
|
||||
|
||||
[HttpGet(Name = "GetAll")]
|
||||
public async Task<ActionResult<List<EventModel>>> Get()
|
||||
{
|
||||
|
||||
var spec = new PracticeEventsWithAttendees();
|
||||
var repoList = await eventsRepo.ListAsync(spec);
|
||||
var evList = repoList.Select(x=> {
|
||||
@@ -69,6 +70,10 @@ namespace PrcaticeCalendar.Controllers
|
||||
public async Task<IActionResult> DeleteEvent(int practiceEventId)
|
||||
{
|
||||
var org = await eventsRepo.GetByIdAsync(practiceEventId);
|
||||
if (org == null)
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
await eventsRepo.DeleteAsync(org);
|
||||
await eventsRepo.SaveChangesAsync();
|
||||
return Ok();
|
||||
@@ -79,7 +84,7 @@ namespace PrcaticeCalendar.Controllers
|
||||
public async Task<IActionResult> AttendeeAcceptEvent(int eventId, int attendeeId)
|
||||
{
|
||||
var spec = new PracticeEventByIdWithAttendees(eventId);
|
||||
var practiceEvent = await eventsRepo.GetBySpecAsync(spec);
|
||||
var practiceEvent = await eventsRepo.FirstOrDefaultAsync(spec);
|
||||
if (practiceEvent == null)
|
||||
{
|
||||
return NotFound();
|
||||
@@ -94,7 +99,7 @@ namespace PrcaticeCalendar.Controllers
|
||||
public async Task<IActionResult> AttendeeDeclineEvent(int eventId, int attendeeId)
|
||||
{
|
||||
var spec = new PracticeEventByIdWithAttendees(eventId);
|
||||
var practiceEvent = await eventsRepo.GetBySpecAsync(spec);
|
||||
var practiceEvent = await eventsRepo.FirstOrDefaultAsync(spec);
|
||||
if (practiceEvent == null)
|
||||
{
|
||||
return NotFound();
|
||||
|
||||
@@ -6,19 +6,19 @@ namespace PracticeCalendar.API.Model
|
||||
public class EventModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string Title { get; set; }
|
||||
public string Description { get; set; }
|
||||
public string Title { get; set; } = string.Empty;
|
||||
public string Description { get; set; } = string.Empty;
|
||||
|
||||
public DateTime StartTime { get; set; }
|
||||
public DateTime EndTime { get; set; }
|
||||
|
||||
public AttendeeModel[] Attendees { get; set; } = new AttendeeModel[0];
|
||||
public AttendeeModel[] Attendees { get; set; } = Array.Empty<AttendeeModel>();
|
||||
}
|
||||
|
||||
public class AttendeeModel
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public string EmailAddress { get; set; }
|
||||
public string Name { get; set; } = string.Empty;
|
||||
public string EmailAddress { get; set; } = string.Empty;
|
||||
public bool IsAttending { get; set; }
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\PracticeCalendar.Domain\PracticeCalendar.Domain.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="PracticeEvents\Commands\" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="6.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
using MediatR;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using PracticeCalendar.Domain.Common.Interfaces;
|
||||
using PracticeCalendar.Domain.Entities;
|
||||
using PracticeCalendar.Domain.Entities.Specifications;
|
||||
|
||||
namespace PracticeCalendar.Application.PracticeEvents.Queries.GetPracticeEvents
|
||||
{
|
||||
public record class GetPracticeEventsQuery : IRequest<List<PracticeEvent>>
|
||||
{
|
||||
}
|
||||
|
||||
public class GetPracticeEventsQueryHandler : IRequestHandler<GetPracticeEventsQuery, List<PracticeEvent>>
|
||||
{
|
||||
private readonly ILogger<GetPracticeEventsQueryHandler> logger;
|
||||
private readonly IRepository<PracticeEvent> eventsRepo;
|
||||
|
||||
public GetPracticeEventsQueryHandler(IRepository<PracticeEvent> eventsRepo,
|
||||
ILogger<GetPracticeEventsQueryHandler> logger)
|
||||
{
|
||||
this.eventsRepo = eventsRepo;
|
||||
this.logger = logger;
|
||||
}
|
||||
|
||||
public async Task<List<PracticeEvent>> Handle(GetPracticeEventsQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
var spec = new PracticeEventsWithAttendees();
|
||||
var evList = await eventsRepo.ListAsync(spec);
|
||||
return evList;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
using Ardalis.GuardClauses;
|
||||
using PracticeCalendar.Domain.Common;
|
||||
using System.Diagnostics.Contracts;
|
||||
|
||||
namespace PracticeCalendar.Domain.Entities
|
||||
{
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
@@ -13,7 +13,7 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\PracticeCalendar.Domain\PracticeCalendar.Domain.csproj" />
|
||||
<ProjectReference Include="..\PracticeCalendar.Application\PracticeCalendar.Application.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -7,15 +7,17 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PracticeCalendar.API", "Pra
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PracticeCalendar.Domain", "PracticeCalendar.Domain\PracticeCalendar.Domain.csproj", "{002B8118-8B5A-4CF3-A29D-12A06803221B}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PracticeCalendar.Infrastructure", "PracticeCalendar.Infrastructure\PracticeCalendar.Infrastructure.csproj", "{211BEF2A-5FB1-4F55-84FB-88FEF90A8316}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PracticeCalendar.Infrastructure", "PracticeCalendar.Infrastructure\PracticeCalendar.Infrastructure.csproj", "{211BEF2A-5FB1-4F55-84FB-88FEF90A8316}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PracticeCalendar.UnitTests", "PracticeCalendar.UnitTests\PracticeCalendar.UnitTests.csproj", "{74849455-5E08-43FE-A718-0872DE7BC350}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PracticeCalendar.UnitTests", "PracticeCalendar.UnitTests\PracticeCalendar.UnitTests.csproj", "{74849455-5E08-43FE-A718-0872DE7BC350}"
|
||||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{5F2B7855-F03D-48C9-8733-FF1E077F18F5}"
|
||||
ProjectSection(SolutionItems) = preProject
|
||||
README.md = README.md
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PracticeCalendar.Application", "PracticeCalendar.Application\PracticeCalendar.Application.csproj", "{094CA45E-92DD-47A5-A7EF-F867DB8B0625}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
@@ -38,6 +40,10 @@ Global
|
||||
{74849455-5E08-43FE-A718-0872DE7BC350}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{74849455-5E08-43FE-A718-0872DE7BC350}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{74849455-5E08-43FE-A718-0872DE7BC350}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{094CA45E-92DD-47A5-A7EF-F867DB8B0625}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{094CA45E-92DD-47A5-A7EF-F867DB8B0625}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{094CA45E-92DD-47A5-A7EF-F867DB8B0625}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{094CA45E-92DD-47A5-A7EF-F867DB8B0625}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
||||
Reference in New Issue
Block a user