-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from maurobernal/CA-4-crud-for-students
Ca 4 crud for students
- Loading branch information
Showing
10 changed files
with
334 additions
and
65 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
25 changes: 25 additions & 0 deletions
25
src/Application/CQRS/Students/Commands/DeleteStudentCommand/DeleteStudentCommand.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,25 @@ | ||
using ca.Application.Common.Exceptions; | ||
using ca.Application.Common.Interfaces; | ||
|
||
namespace ca.Application.CQRS.Students.Commands.DeleteStudentCommand; | ||
public class DeleteStudentCommand : IRequest<int> | ||
{ | ||
internal int Id { get; set; } | ||
public int AssignId(int id) => Id = id; | ||
} | ||
|
||
|
||
public class DeleteStudentHandler(IApplicationDbContext _context) : IRequestHandler<DeleteStudentCommand, int> | ||
{ | ||
public async Task<int> Handle(DeleteStudentCommand request, CancellationToken cancellationToken) | ||
{ | ||
var entity = await _context.Students.FindAsync(request.Id); | ||
if (entity == null) throw new ApiNotFoundException($"el registro no existe:{request.Id}"); | ||
|
||
_context.Students.Remove(entity); | ||
await _context.SaveChangesAsync(cancellationToken); | ||
return request.Id; | ||
|
||
|
||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
src/Application/CQRS/Students/Queries/GetListStudentsQueries/GetCoursesDtoOfList.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,17 @@ | ||
| ||
using ca.Domain.Entities; | ||
|
||
namespace ca.Application.CQRS.Students.Queries.GetStudentsQueries; | ||
public class GetCoursesDtoOfList | ||
{ | ||
public string Title { get; set; } = string.Empty; | ||
|
||
private class Mapping : Profile | ||
{ | ||
public Mapping() | ||
{ | ||
CreateMap<Course, GetCoursesDtoOfList>(); | ||
} | ||
} | ||
} | ||
|
22 changes: 22 additions & 0 deletions
22
src/Application/CQRS/Students/Queries/GetListStudentsQueries/GetListStudentsQueries.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,22 @@ | ||
using ca.Application.Common.Bases; | ||
using ca.Application.Common.Interfaces; | ||
using ca.Application.Common.Mappings; | ||
using ca.Application.Common.Models; | ||
|
||
namespace ca.Application.CQRS.Students.Queries.GetStudentsQueries; | ||
public class GetListStudentsQueries : PaginatedBaseDTO, IRequest<PaginatedList<GetStudentDtoOfList>> | ||
{ | ||
|
||
} | ||
|
||
public class GetListStudentHandler(IApplicationDbContext _context, IMapper _mapper) : IRequestHandler<GetListStudentsQueries, PaginatedList<GetStudentDtoOfList>> | ||
{ | ||
public async Task<PaginatedList<GetStudentDtoOfList>> Handle(GetListStudentsQueries request, CancellationToken cancellationToken) | ||
{ | ||
var res = await _context.Students | ||
.ProjectTo<GetStudentDtoOfList>(_mapper.ConfigurationProvider) | ||
.PaginatedListAsync(request.PageNumber, request.PageSize); | ||
return res; | ||
|
||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
src/Application/CQRS/Students/Queries/GetListStudentsQueries/GetStudentDtoOfList.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 ca.Domain.Entities; | ||
|
||
namespace ca.Application.CQRS.Students.Queries.GetStudentsQueries; | ||
public class GetStudentDtoOfList | ||
{ | ||
public string fullName { get; set; } = string.Empty; | ||
|
||
public int Id { get; set; } | ||
|
||
public int Year { get; set; } | ||
|
||
public int Month { get; set; } | ||
|
||
public int Day { get; set; } | ||
|
||
public List<GetCoursesDtoOfList> courses { get; set; } = new(); | ||
|
||
private class Mapping : Profile | ||
{ | ||
public Mapping() | ||
{ | ||
CreateMap<Student, GetStudentDtoOfList>() | ||
.ForMember(dest => dest.fullName, orig => orig.MapFrom(m => $"{m.FirstName} {m.LastName}")) | ||
.ForMember(dest => dest.Year, orig => orig.MapFrom(m => m.Birthdate.Year)) | ||
.ForMember(dest => dest.Month, orig => orig.MapFrom(m => m.Birthdate.Month)) | ||
.ForMember(dest => dest.Day, orig => orig.MapFrom(m => m.Birthdate.Day)) | ||
; | ||
} | ||
} | ||
} | ||
|
||
|
11 changes: 10 additions & 1 deletion
11
src/Application/CQRS/Students/Queries/GetStudentQueries/GetCoursesDto.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 |
---|---|---|
@@ -1,6 +1,15 @@ | ||
namespace ca.Application.CQRS.Students.Queries.GetStudentQueries; | ||
using ca.Domain.Entities; | ||
|
||
namespace ca.Application.CQRS.Students.Queries.GetStudentQueries; | ||
public class GetCoursesDto | ||
{ | ||
public string Title { get; set; } = string.Empty; | ||
|
||
private class Mapping : Profile | ||
{ | ||
public Mapping() | ||
{ | ||
CreateMap<Course, GetCoursesDto>(); | ||
} | ||
} | ||
} |
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
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
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
Oops, something went wrong.