- Timestamp:
- 11/04/21 22:19:08 (3 years ago)
- Branches:
- dev
- Children:
- 7e7cc4c
- Parents:
- dd264cb
- Location:
- src/FinkiChattery
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
src/FinkiChattery/FinkiChattery.Api/ApplicationServices/Questioning/Mapper/QuestionMapper.cs
rdd264cb rcbdbb49 38 38 if (questionState.AnswersDto.Any()) 39 39 { 40 answers = questionState.AnswersDto.Select(x => 41 { 42 IEnumerable<AnswerResponseQuestionStateResponse> answerResponses = Enumerable.Empty<AnswerResponseQuestionStateResponse>(); 43 44 if (x.AnswerResponsesDto.Any()) 45 { 46 answerResponses = x.AnswerResponsesDto.Select(y => 47 { 48 var answerResponseStudent = new AnswerResponseStudentQuestionStateResponse(y.StudentDto.Id, y.StudentDto.Uid, y.StudentDto.Index, y.StudentDto.ImageUrl, y.StudentDto.Reputation); 49 50 return ToAnswerResponseQuestionStateResponse(y); 51 }); 52 } 53 54 var answerStudent = new AnswerStudentQuestionStateResponse(x.StudentDto.Id, x.StudentDto.Uid, x.StudentDto.Index, x.StudentDto.ImageUrl, x.StudentDto.Reputation); 55 56 return new AnswerQuestionStateResponse(x.Id, x.Uid, x.Text, x.CorrectAnswer, x.CreatedOn, x.VotesCount, answerStudent, answerResponses); 57 }); 40 answers = questionState.AnswersDto.Select(x => ToAnswerQuestionStateResponse(x)); 58 41 } 59 42 … … 77 60 } 78 61 62 public static AnswerQuestionStateResponse ToAnswerQuestionStateResponse(this AnswerQuestionStateDto dto) 63 { 64 IEnumerable<AnswerResponseQuestionStateResponse> answerResponses = Enumerable.Empty<AnswerResponseQuestionStateResponse>(); 65 66 if (dto.AnswerResponsesDto.Any()) 67 { 68 answerResponses = dto.AnswerResponsesDto.Select(y => ToAnswerResponseQuestionStateResponse(y)); 69 } 70 71 var answerStudent = new AnswerStudentQuestionStateResponse(dto.StudentDto.Id, dto.StudentDto.Uid, dto.StudentDto.Index, dto.StudentDto.ImageUrl, dto.StudentDto.Reputation); 72 73 return new AnswerQuestionStateResponse(dto.Id, dto.Uid, dto.Text, dto.CorrectAnswer, dto.CreatedOn, dto.VotesCount, answerStudent, answerResponses); 74 } 75 79 76 public static AnswerResponseQuestionStateResponse ToAnswerResponseQuestionStateResponse(this AnswerResponseQuestionStateDto dto) 80 77 { -
src/FinkiChattery/FinkiChattery.Api/Controllers/v1/AnswersController.cs
rdd264cb rcbdbb49 1 1 using FinkiChattery.Api.ApplicationServices.Authentication; 2 using FinkiChattery.Api.ApplicationServices.Questioning; 2 3 using FinkiChattery.Commands.Questioning; 3 4 using FinkiChattery.Common.Mediator.Interfaces; … … 27 28 public async Task<IActionResult> AnswerQuestion([FromRoute] Guid questionUid, [FromBody] AnswerQuestionRequest request) 28 29 { 29 var answer Uid= await MediatorService.SendAsync(new AnswerQuestionCommand(questionUid, request.Text));30 return Ok(answer Uid);30 var answer = await MediatorService.SendAsync(new AnswerQuestionCommand(questionUid, request.Text)); 31 return Ok(answer.ToAnswerQuestionStateResponse()); 31 32 } 32 33 -
src/FinkiChattery/FinkiChattery.Commands/Questioning/AnswerQuestion/AnswerQuestionCommand.cs
rdd264cb rcbdbb49 3 3 using FinkiChattery.Common.User; 4 4 using FinkiChattery.Persistence.Models; 5 using FinkiChattery.Persistence.Repositories.Contracts; 5 6 using FinkiChattery.Persistence.UnitOfWork; 6 7 using System; 8 using System.Linq; 7 9 using System.Threading; 8 10 using System.Threading.Tasks; … … 10 12 namespace FinkiChattery.Commands.Questioning 11 13 { 12 public class AnswerQuestionCommand : ICommand< Guid>14 public class AnswerQuestionCommand : ICommand<AnswerQuestionStateDto> 13 15 { 14 16 public AnswerQuestionCommand(Guid questionUid, string text) … … 22 24 } 23 25 24 public class AnswerQuestionHandler : ICommandHandler<AnswerQuestionCommand, Guid>26 public class AnswerQuestionHandler : ICommandHandler<AnswerQuestionCommand, AnswerQuestionStateDto> 25 27 { 26 28 public AnswerQuestionHandler(IUnitOfWork unitOfWork, ICurrentUser currentUser, IEventService eventService) … … 35 37 public IEventService EventService { get; } 36 38 37 public async Task< Guid> Handle(AnswerQuestionCommand request, CancellationToken cancellationToken)39 public async Task<AnswerQuestionStateDto> Handle(AnswerQuestionCommand request, CancellationToken cancellationToken) 38 40 { 39 41 var question = await UnitOfWork.Questions.GetByUidAsync(request.QuestionUid); … … 52 54 EventService.Enqueue(new QuestionAnsweredEvent(question.Uid, answer.Uid, student.Uid)); 53 55 54 return answer.Uid; 56 return new AnswerQuestionStateDto(answer.Id, 57 answer.Uid, 58 answer.Text, 59 answer.CorrectAnswer, 60 answer.CreatedOn, 61 answer.VotesCount, 62 new AnswerStudentQuestionStateDto(student.Id, 63 student.Uid, 64 student.IndexNumber, 65 student.ImageUrl, 66 student.Reputation), 67 Enumerable.Empty<AnswerResponseQuestionStateDto>()); 55 68 } 56 69 }
Note:
See TracChangeset
for help on using the changeset viewer.