This repository has been archived by the owner on Apr 11, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(enrolling): use mediatR to handle query
This clean-up the controller
- Loading branch information
1 parent
ef5cb0a
commit 70114d7
Showing
3 changed files
with
41 additions
and
24 deletions.
There are no files selected for viewing
26 changes: 26 additions & 0 deletions
26
src/Services/Enrolling/Enrolling.API/Application/Queries/FindAllEnrollmentsHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
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 FindAllEnrollmentsHandler | ||
: IRequestHandler<FindAllEnrollmentsQuery, IEnumerable<Enrollment>> | ||
{ | ||
private readonly EnrollingContext _context; | ||
|
||
public FindAllEnrollmentsHandler(EnrollingContext context) | ||
{ | ||
_context = context ?? throw new System.ArgumentNullException(nameof(context)); | ||
} | ||
|
||
public async Task<IEnumerable<Enrollment>> Handle(FindAllEnrollmentsQuery request, CancellationToken cancellationToken) | ||
{ | ||
return await _context.Enrollments.ToListAsync(); | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/Services/Enrolling/Enrolling.API/Application/Queries/FindAllEnrollmentsQuery.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
using System.Collections.Generic; | ||
using MediatR; | ||
using OpenCodeFoundation.ESchool.Services.Enrolling.Domain.AggregatesModel.EnrollmentAggregate; | ||
|
||
namespace OpenCodeFoundation.ESchool.Services.Enrolling.API.Application.Queries | ||
{ | ||
public class FindAllEnrollmentsQuery | ||
: IRequest<IEnumerable<Enrollment>> | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters