-
Notifications
You must be signed in to change notification settings - Fork 0
Feat/services evaluation #35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ahmed12348
wants to merge
7
commits into
develop
Choose a base branch
from
feat/services-evaluation
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
f8206f1
feat: add service evaluation feature including endpoints, application…
ahmed12348 9454c6c
feat:Fix Pattern of Service Evaluation
ahmed12348 ece7732
chore: remove temporary migration SQL script
ahmed12348 70ec25d
Merge branch 'develop' into feat/services-evaluation
ahmed12348 46c0160
feat: complete US018 service evaluation with project pattern alignment
ahmed12348 2f368db
Merge branch 'feat/services-evaluation' of https://github.com/Azm-Tec…
ahmed12348 c72f16c
fix: resolve merge conflict in Program.cs
ahmed12348 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
43 changes: 43 additions & 0 deletions
43
backend/src/CCE.Api.External/Endpoints/EvaluationEndpoints.cs
This file contains hidden or 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 CCE.Api.Common.Extensions; | ||
| using CCE.Application.Evaluation.Commands.SubmitEvaluation; | ||
| using CCE.Domain.Evaluation; | ||
| using MediatR; | ||
| using Microsoft.AspNetCore.Builder; | ||
| using Microsoft.AspNetCore.Http; | ||
| using Microsoft.AspNetCore.Routing; | ||
|
|
||
| namespace CCE.Api.External.Endpoints; | ||
|
|
||
| public static class EvaluationEndpoints | ||
| { | ||
| public static IEndpointRouteBuilder MapEvaluationEndpoints(this IEndpointRouteBuilder app) | ||
| { | ||
| var group = app.MapGroup("/api/evaluations").WithTags("Evaluations"); | ||
|
|
||
| // POST /api/evaluations — public submit (visitors & authenticated users) | ||
| group.MapPost("", async ( | ||
| SubmitEvaluationRequest body, | ||
| IMediator mediator, | ||
| CancellationToken ct) => | ||
| { | ||
|
|
||
| var cmd = new SubmitEvaluationCommand( | ||
| (EvaluationRating)body.OverallSatisfaction, | ||
| (EvaluationRating)body.EaseOfUse, | ||
| (EvaluationRating)body.ContentSuitability, | ||
| body.Feedback); | ||
| var result = await mediator.Send(cmd, ct).ConfigureAwait(false); | ||
| return result.ToHttpResult(StatusCodes.Status201Created); | ||
| }) | ||
| .AllowAnonymous() | ||
| .WithName("SubmitEvaluation"); | ||
|
|
||
| return app; | ||
| } | ||
| } | ||
|
|
||
| public sealed record SubmitEvaluationRequest( | ||
| int OverallSatisfaction, | ||
| int EaseOfUse, | ||
| int ContentSuitability, | ||
| string Feedback); |
This file contains hidden or 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
44 changes: 44 additions & 0 deletions
44
backend/src/CCE.Api.Internal/Endpoints/EvaluationEndpoints.cs
This file contains hidden or 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,44 @@ | ||
| using CCE.Api.Common.Extensions; | ||
| using CCE.Application.Evaluation.Queries.GetAllEvaluations; | ||
| using CCE.Application.Evaluation.Queries.GetEvaluationById; | ||
| using CCE.Domain; | ||
| using MediatR; | ||
| using Microsoft.AspNetCore.Builder; | ||
| using Microsoft.AspNetCore.Http; | ||
| using Microsoft.AspNetCore.Routing; | ||
|
|
||
| namespace CCE.Api.Internal.Endpoints; | ||
|
|
||
| public static class EvaluationEndpoints | ||
| { | ||
| public static IEndpointRouteBuilder MapEvaluationEndpoints(this IEndpointRouteBuilder app) | ||
| { | ||
| var group = app.MapGroup("/api/admin/evaluations").WithTags("Evaluations"); | ||
|
|
||
| // GET /api/admin/evaluations — list all (admin only) | ||
| group.MapGet("", async ( | ||
| int? page, int? pageSize, | ||
| IMediator mediator, | ||
| CancellationToken ct) => | ||
| { | ||
| var result = await mediator.Send(new GetAllEvaluationsQuery(page ?? 1, pageSize ?? 20), ct).ConfigureAwait(false); | ||
| return result.ToHttpResult(); | ||
| }) | ||
| .RequireAuthorization(Permissions.Survey_ReadAll) | ||
| .WithName("GetAllEvaluations"); | ||
|
|
||
| // GET /api/admin/evaluations/{id} — get by id (admin only) | ||
| group.MapGet("{id:guid}", async ( | ||
| System.Guid id, | ||
| IMediator mediator, | ||
| CancellationToken ct) => | ||
| { | ||
| var result = await mediator.Send(new GetEvaluationByIdQuery(id), ct).ConfigureAwait(false); | ||
| return result.ToHttpResult(); | ||
| }) | ||
| .RequireAuthorization(Permissions.Survey_ReadAll) | ||
| .WithName("GetEvaluationById"); | ||
|
|
||
| return app; | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -47,9 +47,10 @@ public async Task<TResponse> Handle( | |
| { | ||
| var fieldErrors = failures.Select(f => | ||
| { | ||
| var domainKey = f.ErrorMessage; | ||
| var domainKey = f.ErrorCode; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. explain the change |
||
| var valCode = SystemCodeMap.ToSystemCode(domainKey); | ||
| var msg = _l.GetString(domainKey); | ||
| if (msg == domainKey) msg = f.ErrorMessage; | ||
| return new FieldError( | ||
| ToCamelCase(f.PropertyName), | ||
| valCode, | ||
|
|
||
This file contains hidden or 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 hidden or 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 hidden or 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
11 changes: 11 additions & 0 deletions
11
backend/src/CCE.Application/Evaluation/Commands/SubmitEvaluation/SubmitEvaluationCommand.cs
This file contains hidden or 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 CCE.Application.Common; | ||
| using CCE.Domain.Evaluation; | ||
| using MediatR; | ||
|
|
||
| namespace CCE.Application.Evaluation.Commands.SubmitEvaluation; | ||
|
|
||
| public sealed record SubmitEvaluationCommand( | ||
| EvaluationRating OverallSatisfaction, | ||
| EvaluationRating EaseOfUse, | ||
| EvaluationRating ContentSuitability, | ||
| string Feedback) : IRequest<Response<VoidData>>; |
53 changes: 53 additions & 0 deletions
53
...rc/CCE.Application/Evaluation/Commands/SubmitEvaluation/SubmitEvaluationCommandHandler.cs
This file contains hidden or 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,53 @@ | ||
| using CCE.Application.Common; | ||
| using CCE.Application.Common.Interfaces; | ||
| using CCE.Application.Errors; | ||
| using CCE.Application.Messages; | ||
| using CCE.Domain.Common; | ||
| using DomainEvaluation = CCE.Domain.Evaluation.ServiceEvaluation; | ||
| using MediatR; | ||
|
|
||
| namespace CCE.Application.Evaluation.Commands.SubmitEvaluation; | ||
|
|
||
| public sealed class SubmitEvaluationCommandHandler | ||
| : IRequestHandler<SubmitEvaluationCommand, Response<VoidData>> | ||
| { | ||
| private readonly IEvaluationRepository _repository; | ||
| private readonly ICurrentUserAccessor _currentUser; | ||
| private readonly ISystemClock _clock; | ||
| private readonly MessageFactory _messageFactory; | ||
| private readonly ICceDbContext _db; | ||
|
|
||
| public SubmitEvaluationCommandHandler( | ||
| IEvaluationRepository repository, | ||
| ICurrentUserAccessor currentUser, | ||
| ISystemClock clock, | ||
| MessageFactory messageFactory, | ||
| ICceDbContext db) | ||
| { | ||
| _repository = repository; | ||
| _currentUser = currentUser; | ||
| _clock = clock; | ||
| _messageFactory = messageFactory; | ||
| _db = db; | ||
| } | ||
|
|
||
| public async Task<Response<VoidData>> Handle( | ||
| SubmitEvaluationCommand request, | ||
| CancellationToken cancellationToken) | ||
| { | ||
| var userId = _currentUser.GetUserId(); | ||
|
|
||
| var evaluation = DomainEvaluation.Submit( | ||
| request.OverallSatisfaction, | ||
| request.EaseOfUse, | ||
| request.ContentSuitability, | ||
| request.Feedback, | ||
| userId, | ||
| _clock); | ||
|
|
||
| await _repository.AddAsync(evaluation, cancellationToken).ConfigureAwait(false); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. as i mentioned in faq pr same comment here to use the unit of work to save the transaction |
||
| await _db.SaveChangesAsync(cancellationToken).ConfigureAwait(false); | ||
|
|
||
| return _messageFactory.Ok(ApplicationErrors.Evaluation.EVALUATION_SUBMITTED); | ||
| } | ||
| } | ||
20 changes: 20 additions & 0 deletions
20
.../CCE.Application/Evaluation/Commands/SubmitEvaluation/SubmitEvaluationCommandValidator.cs
This file contains hidden or 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,20 @@ | ||
| using CCE.Domain.Evaluation; | ||
| using FluentValidation; | ||
|
|
||
| namespace CCE.Application.Evaluation.Commands.SubmitEvaluation; | ||
|
|
||
| public sealed class SubmitEvaluationCommandValidator : AbstractValidator<SubmitEvaluationCommand> | ||
| { | ||
| public SubmitEvaluationCommandValidator() | ||
| { | ||
| RuleFor(x => x.OverallSatisfaction) | ||
| .NotEqual(EvaluationRating.None).WithErrorCode("REQUIRED_FIELD"); | ||
| RuleFor(x => x.EaseOfUse) | ||
| .NotEqual(EvaluationRating.None).WithErrorCode("REQUIRED_FIELD"); | ||
| RuleFor(x => x.ContentSuitability) | ||
| .NotEqual(EvaluationRating.None).WithErrorCode("REQUIRED_FIELD"); | ||
| RuleFor(x => x.Feedback) | ||
| .NotEmpty().WithErrorCode("REQUIRED_FIELD") | ||
| .MaximumLength(500).WithErrorCode("MAX_LENGTH"); | ||
| } | ||
| } |
13 changes: 13 additions & 0 deletions
13
backend/src/CCE.Application/Evaluation/DTOs/ServiceEvaluationDto.cs
This file contains hidden or 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,13 @@ | ||
| using CCE.Domain.Evaluation; | ||
|
|
||
| namespace CCE.Application.Evaluation.DTOs; | ||
|
|
||
| public sealed record ServiceEvaluationDto( | ||
| System.Guid Id, | ||
| EvaluationRating OverallSatisfaction, | ||
| EvaluationRating EaseOfUse, | ||
| EvaluationRating ContentSuitability, | ||
| string Feedback, | ||
| System.Guid? UserId, | ||
| System.DateTimeOffset CreatedOn, | ||
| System.Guid? CreatedById); |
8 changes: 8 additions & 0 deletions
8
backend/src/CCE.Application/Evaluation/IEvaluationRepository.cs
This file contains hidden or 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 @@ | ||
| using CCE.Domain.Evaluation; | ||
|
|
||
| namespace CCE.Application.Evaluation; | ||
|
|
||
| public interface IEvaluationRepository | ||
| { | ||
| Task AddAsync(ServiceEvaluation evaluation, CancellationToken ct); | ||
| } |
11 changes: 11 additions & 0 deletions
11
backend/src/CCE.Application/Evaluation/Queries/GetAllEvaluations/GetAllEvaluationsQuery.cs
This file contains hidden or 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 CCE.Application.Common; | ||
| using CCE.Application.Common.Pagination; | ||
| using CCE.Application.Evaluation.DTOs; | ||
| using MediatR; | ||
|
|
||
| namespace CCE.Application.Evaluation.Queries.GetAllEvaluations; | ||
|
|
||
| public sealed record GetAllEvaluationsQuery( | ||
| int Page = 1, | ||
| int PageSize = 20) | ||
| : IRequest<Response<PagedResult<ServiceEvaluationDto>>>; |
44 changes: 44 additions & 0 deletions
44
...src/CCE.Application/Evaluation/Queries/GetAllEvaluations/GetAllEvaluationsQueryHandler.cs
This file contains hidden or 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,44 @@ | ||
| using CCE.Application.Common; | ||
| using CCE.Application.Common.Interfaces; | ||
| using CCE.Application.Evaluation.DTOs; | ||
| using CCE.Application.Messages; | ||
| using MediatR; | ||
| using Microsoft.EntityFrameworkCore; | ||
| using CCE.Application.Common.Pagination; | ||
|
|
||
| namespace CCE.Application.Evaluation.Queries.GetAllEvaluations; | ||
|
|
||
| public sealed class GetAllEvaluationsQueryHandler | ||
| : IRequestHandler<GetAllEvaluationsQuery, | ||
| Response<PagedResult<ServiceEvaluationDto>>> | ||
| { | ||
| private readonly ICceDbContext _db; | ||
| private readonly MessageFactory _msg; | ||
|
|
||
| public GetAllEvaluationsQueryHandler(ICceDbContext db, MessageFactory msg) | ||
| { | ||
| _db = db; | ||
| _msg = msg; | ||
| } | ||
|
|
||
| public async Task<Response<PagedResult<ServiceEvaluationDto>>> Handle( | ||
| GetAllEvaluationsQuery request, | ||
| CancellationToken cancellationToken) | ||
| { | ||
| var query = _db.ServiceEvaluations | ||
| .OrderByDescending(e => e.CreatedOn); | ||
| var page = await query.ToPagedResultAsync( | ||
| request.Page, request.PageSize, cancellationToken) | ||
| .ConfigureAwait(false); | ||
| var result = page.Map(e => new ServiceEvaluationDto( | ||
| e.Id, | ||
| e.OverallSatisfaction, | ||
| e.EaseOfUse, | ||
| e.ContentSuitability, | ||
| e.Feedback, | ||
| e.UserId, | ||
| e.CreatedOn, | ||
| e.CreatedById)); | ||
| return _msg.Ok(result, "ITEMS_LISTED"); | ||
| } | ||
| } |
7 changes: 7 additions & 0 deletions
7
backend/src/CCE.Application/Evaluation/Queries/GetEvaluationById/GetEvaluationByIdQuery.cs
This file contains hidden or 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,7 @@ | ||
| using CCE.Application.Common; | ||
| using CCE.Application.Evaluation.DTOs; | ||
| using MediatR; | ||
|
|
||
| namespace CCE.Application.Evaluation.Queries.GetEvaluationById; | ||
|
|
||
| public sealed record GetEvaluationByIdQuery(System.Guid Id) : IRequest<Response<ServiceEvaluationDto>>; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
explain this change
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Those were optional fixes I added to improve the ERR900 validation error display.