-
Notifications
You must be signed in to change notification settings - Fork 1
Q&A service, dtos and controller #105
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
02dd0ec
Q&A service, dtos and contoller
nouranyasserr 50df6d0
Enhance DTO validation and refactor service logic
gitnasr a48df65
Enhance validation for Answer and Question DTOs
gitnasr 4313c3d
Refactor AutoMapper configurations in QuestionProfile
gitnasr 862fb32
Refactor QAController for improved dependency injection
gitnasr b8a3566
Fix route syntax for DeleteQuestion method
gitnasr d7a434e
Remove prohibited content check from CreateAnswerDtoValidator
gitnasr 27ec423
Refactor DTOs and repositories for improved validation
gitnasr 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| using AutoMapper; | ||
|
|
||
| namespace Dentizone.Application.AutoMapper.Answers | ||
| { | ||
| public class AnswerProfile : Profile | ||
| { | ||
| public AnswerProfile() | ||
| { | ||
| CreateMap<Dentizone.Application.DTOs.Q_A.AnswerDTO.CreateAnswerDto, Dentizone.Domain.Entity.Answer>() | ||
| .ForMember(dest => dest.Id, opt => opt.MapFrom(src => Guid.NewGuid().ToString())) | ||
| .ForMember(dest => dest.CreatedAt, opt => opt.MapFrom(src => DateTime.UtcNow)) | ||
| .ReverseMap(); | ||
| CreateMap<Dentizone.Application.DTOs.Q_A.AnswerDTO.UpdateAnswerDto, Dentizone.Domain.Entity.Answer>() | ||
| .ForMember(dest => dest.Text, opt => opt.MapFrom(src => src.Text)) | ||
| .ForMember(dest => dest.UpdatedAt, opt => opt.MapFrom(src => DateTime.UtcNow)) | ||
| .ReverseMap(); | ||
| CreateMap<Dentizone.Application.DTOs.Q_A.AnswerDTO.AnswerViewDto, Dentizone.Domain.Entity.Answer>() | ||
| .ReverseMap(); | ||
| } | ||
| } | ||
| } |
27 changes: 27 additions & 0 deletions
27
Dentizone.Application/AutoMapper/Questions/QuestionProfile.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,27 @@ | ||
| using AutoMapper; | ||
| using Dentizone.Application.DTOs.Q_A.QuestionDTO; | ||
|
|
||
| namespace Dentizone.Application.AutoMapper.Questions | ||
| { | ||
| public class QuestionProfile : Profile | ||
| { | ||
| public QuestionProfile() | ||
| { | ||
| CreateMap<CreateQuestionDto, Domain.Entity.Question>() | ||
| .ForMember(dest => dest.Id, opt => opt.MapFrom(src => Guid.NewGuid().ToString())) | ||
| .ForMember(dest => dest.CreatedAt, opt => opt.MapFrom(src => DateTime.UtcNow)) | ||
| .ReverseMap(); | ||
| CreateMap<QuestionViewDto, Domain.Entity.Question>() | ||
| .ForMember(dest => dest.Id, opt => opt.MapFrom(src => src.Id)) | ||
| .ForMember(dest => dest.User, opt => opt.Ignore()) | ||
| .ForMember(dest => dest.Text, opt => opt.MapFrom(src => src.Text)) | ||
| .ForMember(dest => dest.CreatedAt, opt => opt.MapFrom(src => src.CreatedAt)) | ||
| .ReverseMap() | ||
| .ForMember(dest => dest.AskerName, opt => opt.MapFrom(src => src.User != null ? src.User.FullName : string.Empty)); | ||
| CreateMap<UpdateQuestionDto, Domain.Entity.Question>() | ||
| .ForMember(dest => dest.Text, opt => opt.MapFrom(src => src.Text)) | ||
| .ForMember(dest => dest.UpdatedAt, opt => opt.MapFrom(src => DateTime.UtcNow)) | ||
| .ReverseMap(); | ||
| } | ||
| } | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| using FluentValidation; | ||
|
|
||
| namespace Dentizone.Application.DTOs.Q_A.AnswerDTO | ||
| { | ||
| public class AnswerViewDto | ||
| { | ||
| public string Id { get; set; } | ||
| public string ResponderName { get; set; } | ||
| public string Text { get; set; } | ||
| public DateTime CreatedAt { get; set; } | ||
| } | ||
|
|
||
| public class AnswerViewDtoValidator : AbstractValidator<AnswerViewDto> | ||
| { | ||
| public AnswerViewDtoValidator() | ||
| { | ||
| RuleFor(x => x.Id).NotEmpty().WithMessage("Id is required."); | ||
| RuleFor(x => x.ResponderName) | ||
| .NotEmpty().WithMessage("ResponderName is required.") | ||
| .MaximumLength(100).WithMessage("ResponderName cannot exceed 100 characters."); | ||
| RuleFor(x => x.Text) | ||
| .NotEmpty().WithMessage("Text is required.") | ||
| .MaximumLength(500).WithMessage("Text cannot exceed 500 characters."); | ||
| RuleFor(x => x.CreatedAt) | ||
| .Must(date => date != default).WithMessage("CreatedAt must be a valid date.") | ||
| .LessThanOrEqualTo(DateTime.UtcNow).WithMessage("CreatedAt cannot be in the future."); | ||
| } | ||
| } | ||
| } |
20 changes: 20 additions & 0 deletions
20
Dentizone.Application/DTOs/Q&A/AnswerDTO/CreateAnswerDto.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 FluentValidation; | ||
|
|
||
| namespace Dentizone.Application.DTOs.Q_A.AnswerDTO | ||
| { | ||
| public class CreateAnswerDto | ||
| { | ||
| public string Text { get; set; } | ||
| } | ||
|
|
||
| public class CreateAnswerDtoValidator : AbstractValidator<CreateAnswerDto> | ||
| { | ||
| public CreateAnswerDtoValidator() | ||
| { | ||
| RuleFor(x => x.Text) | ||
| .NotEmpty().WithMessage("Text is required.") | ||
| .MaximumLength(500).WithMessage("Text cannot exceed 500 characters.") | ||
| .Must(text => !string.IsNullOrWhiteSpace(text)).WithMessage("Text cannot be whitespace only."); | ||
| } | ||
| } | ||
| } |
17 changes: 17 additions & 0 deletions
17
Dentizone.Application/DTOs/Q&A/AnswerDTO/UpdateAnswerDto.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,17 @@ | ||
| using FluentValidation; | ||
|
|
||
| namespace Dentizone.Application.DTOs.Q_A.AnswerDTO | ||
| { | ||
| public class UpdateAnswerDto | ||
| { | ||
| public string Text { get; set; } | ||
| } | ||
|
|
||
| public class UpdateAnswerDtoValidator : AbstractValidator<UpdateAnswerDto> | ||
| { | ||
| public UpdateAnswerDtoValidator() | ||
| { | ||
| RuleFor(x => x.Text).NotEmpty().WithMessage("Text is required."); | ||
gitnasr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
| } | ||
21 changes: 21 additions & 0 deletions
21
Dentizone.Application/DTOs/Q&A/QuestionDTO/CreateQuestionDto.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,21 @@ | ||
| using Dentizone.Application.Validators; | ||
| using FluentValidation; | ||
|
|
||
| namespace Dentizone.Application.DTOs.Q_A.QuestionDTO | ||
| { | ||
| #nullable enable | ||
| public class CreateQuestionDto | ||
| { | ||
| public string PostId { get; set; } | ||
| public string? Text { get; set; } | ||
gitnasr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| public class CreateQuestionDtoValidator : AbstractValidator<CreateQuestionDto> | ||
| { | ||
| public CreateQuestionDtoValidator() | ||
| { | ||
| RuleFor(x => x.PostId).NotEmpty().WithMessage("PostId is required.").MustBeParsableGuid(); | ||
| RuleFor(x => x.Text).NotEmpty().WithMessage("Text is required."); | ||
| } | ||
| } | ||
| } | ||
25 changes: 25 additions & 0 deletions
25
Dentizone.Application/DTOs/Q&A/QuestionDTO/QuestionViewDto.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,25 @@ | ||
| using Dentizone.Application.DTOs.Q_A.AnswerDTO; | ||
| using FluentValidation; | ||
|
|
||
| namespace Dentizone.Application.DTOs.Q_A.QuestionDTO | ||
gitnasr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| { | ||
| public class QuestionViewDto | ||
| { | ||
| public string Id { get; set; } | ||
gitnasr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| public string AskerName { get; set; } | ||
| public string Text { get; set; } | ||
| public AnswerViewDto? Answer { get; set; } | ||
gitnasr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| public DateTime CreatedAt { get; set; } | ||
| } | ||
|
|
||
| public class QuestionViewDtoValidator : AbstractValidator<QuestionViewDto> | ||
| { | ||
| public QuestionViewDtoValidator() | ||
| { | ||
| RuleFor(x => x.Id).NotEmpty().WithMessage("Id is required."); | ||
| RuleFor(x => x.AskerName).NotEmpty().WithMessage("AskerName is required."); | ||
| RuleFor(x => x.Text).NotEmpty().WithMessage("Text is required."); | ||
gitnasr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| RuleFor(x => x.CreatedAt).NotEmpty().WithMessage("CreatedAt is required."); | ||
| } | ||
| } | ||
| } | ||
19 changes: 19 additions & 0 deletions
19
Dentizone.Application/DTOs/Q&A/QuestionDTO/UpdateQuestionDto.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,19 @@ | ||
| using FluentValidation; | ||
|
|
||
| namespace Dentizone.Application.DTOs.Q_A.QuestionDTO | ||
| { | ||
| public class UpdateQuestionDto | ||
| { | ||
| public string? Text { get; set; } | ||
| } | ||
|
|
||
| public class UpdateQuestionDtoValidator : AbstractValidator<UpdateQuestionDto> | ||
| { | ||
| public UpdateQuestionDtoValidator() | ||
| { | ||
| RuleFor(x => x.Text) | ||
| .NotEmpty().WithMessage("Text is required.") | ||
| .MaximumLength(500).WithMessage("Text cannot exceed 500 characters."); | ||
| } | ||
| } | ||
| } |
10 changes: 2 additions & 8 deletions
10
Dentizone.Application/DTOs/Withdrawal/ApproveWithdrawalDto.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 |
|---|---|---|
| @@ -1,13 +1,7 @@ | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Linq; | ||
| using System.Text; | ||
| using System.Threading.Tasks; | ||
|
|
||
| namespace Dentizone.Application.DTOs.Withdrawal | ||
| namespace Dentizone.Application.DTOs.Withdrawal | ||
| { | ||
| public class ApproveWithdrawalDto | ||
| { | ||
| public string AdminNote { get; set; } | ||
| } | ||
| } | ||
| } |
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 |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| using Dentizone.Application.DTOs.Q_A.AnswerDTO; | ||
| using Dentizone.Application.DTOs.Q_A.QuestionDTO; | ||
|
|
||
| namespace Dentizone.Application.Interfaces | ||
| { | ||
| public interface IQAService | ||
| { | ||
| Task<QuestionViewDto> AskQuestionAsync(CreateQuestionDto dto, string askerId); | ||
| Task<IEnumerable<QuestionViewDto>> GetQuestionsForPostAsync(string postId); | ||
| Task<AnswerViewDto> AnswerQuestionAsync(string questionId, CreateAnswerDto dto, string responderId); | ||
| Task UpdateQuestionAsync(string questionId, UpdateQuestionDto dto); | ||
| Task DeleteQuestionAsync(string questionId); | ||
| Task UpdateAnswerAsync(string answerId, UpdateAnswerDto dto); | ||
| Task DeleteAnswerAsync(string answerId); | ||
| } | ||
| } |
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 |
|---|---|---|
| @@ -1,20 +1,14 @@ | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Linq; | ||
| using System.Text; | ||
| using System.Threading.Tasks; | ||
| using Dentizone.Application.DTOs.Withdrawal; | ||
| using Dentizone.Domain.Entity; | ||
| using Dentizone.Application.DTOs.Withdrawal; | ||
|
|
||
| namespace Dentizone.Application.Interfaces | ||
| { | ||
| public interface IWithdrawalService | ||
| { | ||
| Task<WithdrawalRequestView> CreateWithdrawalRequestAsync(string userId, WithdrawalRequestDto withdrawalRequestDto); | ||
| Task<WithdrawalRequestView> CreateWithdrawalRequestAsync(string userId, | ||
| WithdrawalRequestDto withdrawalRequestDto); | ||
|
|
||
| Task<List<WithdrawalRequestView>> GetWithdrawalHistoryAsync(string userId, int page); | ||
| Task<WithdrawalRequestView> ApproveWithdrawalAsync(string id, string adminNote); | ||
| Task<WithdrawalRequestView> RejectWithdrawalAsync(string id, string adminNote); | ||
| } | ||
| } | ||
|
|
||
|
|
||
| } |
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.