-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* This commit introduces the implementation of the Command Query Responsibility Segregation (CQRS) pattern. * Entities representing commands and queries are created to encapsulate actions and data retrieval, respectively. * Additionally, corresponding command and query handlers are implemented to execute these actions. * The service responsible for PDF generation is refactored to utilize CQRS principles, improving separation of concerns and modularity.
- Loading branch information
1 parent
a67dda9
commit 4979921
Showing
14 changed files
with
208 additions
and
147 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 |
---|---|---|
@@ -1,20 +1,29 @@ | ||
using MediatR; | ||
using CV.Domain.Entity; | ||
using CV.Application.Interface; | ||
using Microsoft.AspNetCore.Mvc; | ||
using CV.Application.CQRS.Commands; | ||
|
||
namespace CV.API.Controllers; | ||
|
||
[Route("api/[controller]")] | ||
[ApiController] | ||
public class CurriculumController(ICurriculumService curriculumService) : ControllerBase | ||
public class CurriculumController(IMediator mediator) : ControllerBase | ||
{ | ||
private readonly ICurriculumService _curriculumService = curriculumService; | ||
private readonly IMediator _mediator = mediator; | ||
|
||
[HttpPost] | ||
[Route("GenerateCurriculum")] | ||
public IActionResult GerarCurriculum([FromBody] Curriculum curriculum) | ||
public async Task<IActionResult> GerarCurriculum([FromBody] Curriculum curriculum) | ||
{ | ||
var pdfBytes = _curriculumService.GerarCurriculoPdf(curriculum); | ||
return File(pdfBytes, "application/pdf", $"{curriculum.Name}.pdf"); | ||
try | ||
{ | ||
var command = new CreateCurriculumCommand { Curriculum = curriculum }; | ||
var pdfBytes = await _mediator.Send(command); | ||
return File(pdfBytes, "application/pdf", $"{curriculum.Name}.pdf"); | ||
} | ||
catch (Exception) | ||
{ | ||
throw; | ||
} | ||
} | ||
} |
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,9 @@ | ||
using MediatR; | ||
using CV.Domain.Entity; | ||
|
||
namespace CV.Application.CQRS.Commands; | ||
|
||
public class CreateCurriculumCommand : IRequest<byte[]> | ||
{ | ||
public Curriculum Curriculum { get; set; } | ||
} |
24 changes: 24 additions & 0 deletions
24
CV.Application/CQRS/Handlers/CreateCurriculumCommandHandler.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,24 @@ | ||
using MediatR; | ||
using CV.Application.Interface; | ||
using CV.Application.CQRS.Commands; | ||
|
||
namespace CV.Application.CQRS.Handlers; | ||
|
||
public class CreateCurriculumCommandHandler(ICurriculumService curriculumService) : IRequestHandler<CreateCurriculumCommand, byte[]> | ||
{ | ||
private readonly ICurriculumService _curriculumService = curriculumService; | ||
|
||
public async Task<byte[]> Handle(CreateCurriculumCommand request, CancellationToken cancellationToken) | ||
{ | ||
try | ||
{ | ||
var pdf = await _curriculumService.GeneratePdf(request.Curriculum); | ||
return pdf; | ||
} | ||
catch (Exception) | ||
{ | ||
throw; | ||
} | ||
|
||
} | ||
} |
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
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,8 +1,7 @@ | ||
namespace CV.Domain.Entity | ||
namespace CV.Domain.Entity; | ||
|
||
public class Certification | ||
{ | ||
public class Certification | ||
{ | ||
public string Name { get; set; } | ||
public string Institution { get; set; } | ||
} | ||
public string Name { get; set; } | ||
public string Institution { 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,10 @@ | ||
namespace CV.Domain.Entity; | ||
|
||
public class ContactInfo | ||
{ | ||
public string Address { get; set; } | ||
public string Telephone { get; set; } | ||
public string Email { get; set; } | ||
public string GitHub { get; set; } | ||
public string LinkedIn { 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 |
---|---|---|
@@ -1,16 +1,10 @@ | ||
namespace CV.Domain.Entity | ||
namespace CV.Domain.Entity; | ||
|
||
public class Curriculum | ||
{ | ||
public class Curriculum | ||
{ | ||
public string Name { get; set; } | ||
public string Contact { get; set; } | ||
public string Address { get; set; } | ||
public string Telephone { get; set; } | ||
public string Email { get; set; } | ||
public string GitHub { get; set; } | ||
public string LinkedIn { get; set; } | ||
public List<Education> Education { get; set; } | ||
public List<Experience> Experience { get; set; } | ||
public List<Certification> Certification { get; set; } | ||
} | ||
public string Name { get; set; } | ||
public ContactInfo Contact { get; set; } | ||
public ICollection<Education> Education { get; set; } | ||
public ICollection<Experience> Experience { get; set; } | ||
public ICollection<Certification> Certification { 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 |
---|---|---|
@@ -1,12 +1,11 @@ | ||
namespace CV.Domain.Entity | ||
namespace CV.Domain.Entity; | ||
|
||
public class Education | ||
{ | ||
public class Education | ||
{ | ||
public string Institution { get; set; } | ||
public string City { get; set; } | ||
public string State { get; set; } | ||
public string Course { get; set; } | ||
public string Status { get; set; } | ||
public string Period { get; set; } | ||
} | ||
public string Institution { get; set; } | ||
public string City { get; set; } | ||
public string State { get; set; } | ||
public string Course { get; set; } | ||
public string Status { get; set; } | ||
public string Period { 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 |
---|---|---|
@@ -1,11 +1,10 @@ | ||
namespace CV.Domain.Entity | ||
namespace CV.Domain.Entity; | ||
|
||
public class Experience | ||
{ | ||
public class Experience | ||
{ | ||
public string Company { get; set; } | ||
public string City { get; set; } | ||
public string Position { get; set; } | ||
public string Period { get; set; } | ||
public List<string> Description { get; set; } | ||
} | ||
public string Company { get; set; } | ||
public string City { get; set; } | ||
public string Position { get; set; } | ||
public string Period { get; set; } | ||
public ICollection<string> Description { get; set; } | ||
} |
Oops, something went wrong.