-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
88379f5
commit 9202919
Showing
11 changed files
with
204 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
using MediatR; | ||
using Microsoft.AspNetCore.Http; | ||
using Microsoft.AspNetCore.Mvc; | ||
using UrphaCapital.Application.UseCases.Selects.Queries; | ||
|
||
namespace UrphaCapital.API.Controllers | ||
{ | ||
[Route("api/[controller]")] | ||
[ApiController] | ||
public class SelectController : ControllerBase | ||
{ | ||
private readonly IMediator _mediator; | ||
|
||
public SelectController(IMediator mediator) | ||
{ | ||
_mediator = mediator; | ||
} | ||
|
||
[HttpGet("get-mentors")] | ||
public async Task<IActionResult> GetMentors() | ||
{ | ||
var query = new SelectAllMentorsQuery(); | ||
var result = await _mediator.Send(query); | ||
return Ok(result); | ||
} | ||
|
||
[HttpGet("get-students")] | ||
public async Task<IActionResult> GetStudents() | ||
{ | ||
var query = new SelectAllStudentsQuery(); | ||
var result = await _mediator.Send(query); | ||
return Ok(result); | ||
} | ||
|
||
[HttpGet("get-courses")] | ||
public async Task<IActionResult> GetCourses() | ||
{ | ||
var query = new SelectAllCoursesQuery(); | ||
var result = await _mediator.Send(query); | ||
return Ok(result); | ||
} | ||
} | ||
} |
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
32 changes: 32 additions & 0 deletions
32
UrphaCapital.Application/UseCases/Selects/Handlers/SelectAllCoursesQueryHandler.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,32 @@ | ||
using MediatR; | ||
using Microsoft.EntityFrameworkCore; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using UrphaCapital.Application.Abstractions; | ||
using UrphaCapital.Application.UseCases.Selects.Queries; | ||
using UrphaCapital.Application.ViewModels; | ||
|
||
namespace UrphaCapital.Application.UseCases.Selects.Handlers | ||
{ | ||
public class SelectAllCoursesQueryHandler : IRequestHandler<SelectAllCoursesQuery, IEnumerable<CourseSelectModel>> | ||
{ | ||
private readonly IApplicationDbContext _context; | ||
|
||
public SelectAllCoursesQueryHandler(IApplicationDbContext context) | ||
{ | ||
_context = context; | ||
} | ||
|
||
public async Task<IEnumerable<CourseSelectModel>> Handle(SelectAllCoursesQuery request, CancellationToken cancellationToken) | ||
{ | ||
return await _context.Courses.OrderBy(x => x.Name).Select(x => new CourseSelectModel() | ||
{ | ||
Title = x.Name, | ||
Id = x.Id, | ||
}).ToListAsync(cancellationToken); | ||
} | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
UrphaCapital.Application/UseCases/Selects/Handlers/SelectAllMentorsQueryHandler.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,29 @@ | ||
using MediatR; | ||
using Microsoft.EntityFrameworkCore; | ||
using UrphaCapital.Application.Abstractions; | ||
using UrphaCapital.Application.UseCases.Selects.Queries; | ||
using UrphaCapital.Application.ViewModels; | ||
|
||
namespace UrphaCapital.Application.UseCases.Selects.Handlers | ||
{ | ||
public class SelectAllMentorsQueryHandler : IRequestHandler<SelectAllMentorsQuery, IEnumerable<MentorSelectModel>> | ||
{ | ||
private readonly IApplicationDbContext _context; | ||
|
||
public SelectAllMentorsQueryHandler(IApplicationDbContext context) | ||
{ | ||
_context = context; | ||
} | ||
|
||
public async Task<IEnumerable<MentorSelectModel>> Handle(SelectAllMentorsQuery request, CancellationToken cancellationToken) | ||
{ | ||
return await _context.Mentors | ||
.OrderBy(m => m.Name) | ||
.Select(x => new MentorSelectModel | ||
{ | ||
FullName = x.Name, | ||
Id = x.Id | ||
}).ToListAsync(cancellationToken); | ||
} | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
UrphaCapital.Application/UseCases/Selects/Handlers/SelectAllStudentsQueryHandler.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,32 @@ | ||
using MediatR; | ||
using Microsoft.EntityFrameworkCore; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using UrphaCapital.Application.Abstractions; | ||
using UrphaCapital.Application.UseCases.Selects.Queries; | ||
using UrphaCapital.Application.ViewModels; | ||
|
||
namespace UrphaCapital.Application.UseCases.Selects.Handlers | ||
{ | ||
public class SelectAllStudentsQueryHandler : IRequestHandler<SelectAllStudentsQuery, IEnumerable<StudentSelectModel>> | ||
{ | ||
private readonly IApplicationDbContext _context; | ||
|
||
public SelectAllStudentsQueryHandler(IApplicationDbContext context) | ||
{ | ||
_context = context; | ||
} | ||
|
||
public async Task<IEnumerable<StudentSelectModel>> Handle(SelectAllStudentsQuery request, CancellationToken cancellationToken) | ||
{ | ||
return await _context.Students.OrderBy(x => x.FullName).Select(x => new StudentSelectModel() | ||
{ | ||
FullName = x.FullName, | ||
Id = x.Id, | ||
}).ToListAsync(cancellationToken); | ||
} | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
UrphaCapital.Application/UseCases/Selects/Queries/SelectAllCoursesQuery.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,14 @@ | ||
using MediatR; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using UrphaCapital.Application.ViewModels; | ||
|
||
namespace UrphaCapital.Application.UseCases.Selects.Queries | ||
{ | ||
public class SelectAllCoursesQuery : IRequest<IEnumerable<CourseSelectModel>> | ||
{ | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
UrphaCapital.Application/UseCases/Selects/Queries/SelectAllMentorsQuery.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using MediatR; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using UrphaCapital.Application.ViewModels; | ||
using UrphaCapital.Domain.Entities.Auth; | ||
|
||
namespace UrphaCapital.Application.UseCases.Selects.Queries | ||
{ | ||
public class SelectAllMentorsQuery : IRequest<IEnumerable<MentorSelectModel>> | ||
{ | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
UrphaCapital.Application/UseCases/Selects/Queries/SelectAllStudentsQuery.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using MediatR; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using UrphaCapital.Application.ViewModels; | ||
using UrphaCapital.Domain.Entities.Auth; | ||
|
||
namespace UrphaCapital.Application.UseCases.Selects.Queries | ||
{ | ||
public class SelectAllStudentsQuery : IRequest<IEnumerable<StudentSelectModel>> | ||
{ | ||
} | ||
} |
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,8 @@ | ||
namespace UrphaCapital.Application.ViewModels | ||
{ | ||
public class CourseSelectModel | ||
{ | ||
public Guid Id { get; set; } | ||
public string Title { get; set; } | ||
} | ||
} |
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,8 @@ | ||
namespace UrphaCapital.Application.ViewModels | ||
{ | ||
public class MentorSelectModel | ||
{ | ||
public long Id { get; set; } | ||
public string FullName { get; set; } | ||
} | ||
} |
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,8 @@ | ||
namespace UrphaCapital.Application.ViewModels | ||
{ | ||
public class StudentSelectModel | ||
{ | ||
public long Id { get; set; } | ||
public string FullName { get; set; } | ||
} | ||
} |