diff --git a/PracticeCalendar.Api/Controllers/EventsController.cs b/PracticeCalendar.Api/Controllers/EventsController.cs index 506dde0..aecb49b 100644 --- a/PracticeCalendar.Api/Controllers/EventsController.cs +++ b/PracticeCalendar.Api/Controllers/EventsController.cs @@ -13,7 +13,7 @@ namespace PrcaticeCalendar.Controllers { private readonly IRepository eventsRepo; private readonly IMapper mapper; - private readonly ILogger _logger; + private readonly ILogger logger; public EventsController(IRepository 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>> 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 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 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 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(); diff --git a/PracticeCalendar.Api/Model/EventModel.cs b/PracticeCalendar.Api/Model/EventModel.cs index 8738d4a..e121af4 100644 --- a/PracticeCalendar.Api/Model/EventModel.cs +++ b/PracticeCalendar.Api/Model/EventModel.cs @@ -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(); } 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; } } diff --git a/PracticeCalendar.Application/PracticeCalendar.Application.csproj b/PracticeCalendar.Application/PracticeCalendar.Application.csproj new file mode 100644 index 0000000..147046d --- /dev/null +++ b/PracticeCalendar.Application/PracticeCalendar.Application.csproj @@ -0,0 +1,21 @@ + + + + net6.0 + enable + enable + + + + + + + + + + + + + + + diff --git a/PracticeCalendar.Application/PracticeEvents/Queries/GetPracticeEvents/GetPracticeEventsQuery.cs b/PracticeCalendar.Application/PracticeEvents/Queries/GetPracticeEvents/GetPracticeEventsQuery.cs new file mode 100644 index 0000000..21d45c0 --- /dev/null +++ b/PracticeCalendar.Application/PracticeEvents/Queries/GetPracticeEvents/GetPracticeEventsQuery.cs @@ -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> + { + } + + public class GetPracticeEventsQueryHandler : IRequestHandler> + { + private readonly ILogger logger; + private readonly IRepository eventsRepo; + + public GetPracticeEventsQueryHandler(IRepository eventsRepo, + ILogger logger) + { + this.eventsRepo = eventsRepo; + this.logger = logger; + } + + public async Task> Handle(GetPracticeEventsQuery request, CancellationToken cancellationToken) + { + var spec = new PracticeEventsWithAttendees(); + var evList = await eventsRepo.ListAsync(spec); + return evList; + } + } +} diff --git a/PracticeCalendar.Domain/Entities/Attendee.cs b/PracticeCalendar.Domain/Entities/Attendee.cs index d376b21..8a78a53 100644 --- a/PracticeCalendar.Domain/Entities/Attendee.cs +++ b/PracticeCalendar.Domain/Entities/Attendee.cs @@ -1,6 +1,5 @@ using Ardalis.GuardClauses; using PracticeCalendar.Domain.Common; -using System.Diagnostics.Contracts; namespace PracticeCalendar.Domain.Entities { diff --git a/PracticeCalendar.Infrastructure/PracticeCalendar.Infrastructure.csproj b/PracticeCalendar.Infrastructure/PracticeCalendar.Infrastructure.csproj index 09d0693..02e0568 100644 --- a/PracticeCalendar.Infrastructure/PracticeCalendar.Infrastructure.csproj +++ b/PracticeCalendar.Infrastructure/PracticeCalendar.Infrastructure.csproj @@ -1,4 +1,4 @@ - + net6.0 @@ -13,7 +13,7 @@ - + diff --git a/PracticeCalendar.sln b/PracticeCalendar.sln index 3598091..4e6da5b 100644 --- a/PracticeCalendar.sln +++ b/PracticeCalendar.sln @@ -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