Changeset fcc3080
- Timestamp:
- 11/14/21 13:58:42 (3 years ago)
- Branches:
- dev
- Children:
- f3c4950
- Parents:
- e071d30
- Location:
- src
- Files:
-
- 1 added
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Clients/Angular/finki-chattery/src/app/core/state/question-state/question-state-response.models.ts
re071d30 rfcc3080 80 80 public voteUid!: string; 81 81 public voteType!: VoteType; 82 public voteAlreadyExists!: boolean; 82 83 } -
src/Clients/Angular/finki-chattery/src/app/core/state/question-state/question.mapper.ts
re071d30 rfcc3080 90 90 91 91 public static ToVoteAnswerViewModel(response: VoteAnswerResponse): VoteAnswerViewModel { 92 return new VoteAnswerViewModel(response.answerUid, response.voteUid, response.voteType );92 return new VoteAnswerViewModel(response.answerUid, response.voteUid, response.voteType, response.voteAlreadyExists); 93 93 } 94 94 -
src/Clients/Angular/finki-chattery/src/app/core/state/question-state/question.reducers.ts
re071d30 rfcc3080 39 39 case VoteType.Upvote: 40 40 votesCountNew++; 41 if (action.payload.voteAlreadyExists) { 42 votesCountNew++; 43 } 41 44 break; 42 45 case VoteType.Downvote: 43 46 votesCountNew--; 47 if (action.payload.voteAlreadyExists) { 48 votesCountNew--; 49 } 44 50 break; 45 51 } -
src/Clients/Angular/finki-chattery/src/app/shared-app/models/question-state-view-models.models.ts
re071d30 rfcc3080 77 77 78 78 export class VoteAnswerViewModel { 79 constructor(public answerUid: string, public voteUid: string, public voteType: VoteType ) {}79 constructor(public answerUid: string, public voteUid: string, public voteType: VoteType, public voteAlreadyExists: boolean) {} 80 80 } -
src/FinkiChattery/FinkiChattery.Api/ApplicationServices/Questioning/EventHandlers/UpdateAnswerVotesEventHandler.cs
re071d30 rfcc3080 30 30 case VoteType.Upvote: 31 31 answer.VotesCount++; 32 33 if (notification.VoteAlreadyExists) 34 { 35 answer.VotesCount++; 36 } 32 37 break; 33 38 case VoteType.Downvote: 34 39 answer.VotesCount--; 40 if (notification.VoteAlreadyExists) 41 { 42 answer.VotesCount--; 43 } 35 44 break; 36 45 } -
src/FinkiChattery/FinkiChattery.Api/ApplicationServices/Questioning/EventHandlers/UpdateStudentReputationEventHandler.cs
re071d30 rfcc3080 30 30 case VoteType.Upvote: 31 31 student.Reputation++; 32 if (notification.VoteAlreadyExists) 33 { 34 student.Reputation++; 35 } 32 36 break; 33 37 case VoteType.Downvote: 34 38 student.Reputation--; 39 if (notification.VoteAlreadyExists) 40 { 41 student.Reputation++; 42 } 35 43 break; 36 44 } -
src/FinkiChattery/FinkiChattery.Api/Controllers/v1/VotesController.cs
re071d30 rfcc3080 29 29 { 30 30 VoteType voteType = request.VoteType == VoteTypeRequest.Upvote ? VoteType.Upvote : VoteType.Downvote; 31 var vote Uid= await MediatorService.SendAsync(new VoteAnswerCommand(voteType, answerUid, questionUid));32 return Ok(new VoteAnswerResponse(answerUid, vote Uid, request.VoteType));31 var vote = await MediatorService.SendAsync(new VoteAnswerCommand(voteType, answerUid, questionUid)); 32 return Ok(new VoteAnswerResponse(answerUid, vote.VoteUid, request.VoteType, vote.VoteAlreadyExists)); 33 33 } 34 34 } -
src/FinkiChattery/FinkiChattery.Commands/Questioning/VoteAnswer/AnswerVotedEvent.cs
re071d30 rfcc3080 7 7 public class AnswerVotedEvent : IEvent 8 8 { 9 public AnswerVotedEvent(Guid questionUid, Guid answerUid, Guid studentUid, VoteType voteType )9 public AnswerVotedEvent(Guid questionUid, Guid answerUid, Guid studentUid, VoteType voteType, bool voteAlreadyExists) 10 10 { 11 11 QuestionUid = questionUid; … … 13 13 StudentUid = studentUid; 14 14 VoteType = voteType; 15 VoteAlreadyExists = voteAlreadyExists; 15 16 } 16 17 … … 19 20 public Guid StudentUid { get; } 20 21 public VoteType VoteType { get; } 22 public bool VoteAlreadyExists { get; } 21 23 } 22 24 } -
src/FinkiChattery/FinkiChattery.Commands/Questioning/VoteAnswer/VoteAnswerCommand.cs
re071d30 rfcc3080 11 11 namespace FinkiChattery.Commands.Questioning 12 12 { 13 public class VoteAnswerCommand : ICommand< Guid>13 public class VoteAnswerCommand : ICommand<VoteAnswerDto> 14 14 { 15 15 public VoteAnswerCommand(VoteType voteType, Guid answerUid, Guid questionUid) … … 25 25 } 26 26 27 public class VoteAnswerHandler : ICommandHandler<VoteAnswerCommand, Guid>27 public class VoteAnswerHandler : ICommandHandler<VoteAnswerCommand, VoteAnswerDto> 28 28 { 29 29 public VoteAnswerHandler(IUnitOfWork unitOfWork, ICurrentUser currentUser, IEventService eventService) … … 38 38 public IEventService EventService { get; } 39 39 40 public async Task< Guid> Handle(VoteAnswerCommand request, CancellationToken cancellationToken)40 public async Task<VoteAnswerDto> Handle(VoteAnswerCommand request, CancellationToken cancellationToken) 41 41 { 42 42 var student = await UnitOfWork.Students.GetStudent(CurrentUser.Id); 43 43 var answer = await UnitOfWork.Answers.GetByUidAsync(request.AnswerUid); 44 44 var vote = await UnitOfWork.Votes.GetVoteForAnswerByStudent(request.AnswerUid, CurrentUser.Id); 45 var voteAlreadyExists = false; 45 46 46 47 if (vote == null) … … 58 59 { 59 60 vote.VoteType = request.VoteType; 61 voteAlreadyExists = true; 60 62 } 61 63 62 64 await UnitOfWork.SaveAsync(); 63 65 64 EventService.Enqueue(new AnswerVotedEvent(request.QuestionUid, request.AnswerUid, student.Uid, request.VoteType ));66 EventService.Enqueue(new AnswerVotedEvent(request.QuestionUid, request.AnswerUid, student.Uid, request.VoteType, voteAlreadyExists)); 65 67 66 return vote.Uid;68 return new VoteAnswerDto(vote.Uid, voteAlreadyExists); 67 69 } 68 70 } -
src/FinkiChattery/FinkiChattery.Contracts/Questioning/VoteAnswer/VoteAnswerResponse.cs
re071d30 rfcc3080 5 5 public class VoteAnswerResponse 6 6 { 7 public VoteAnswerResponse(Guid answerUid, Guid voteUid, VoteTypeRequest voteType )7 public VoteAnswerResponse(Guid answerUid, Guid voteUid, VoteTypeRequest voteType, bool voteAlreadyExists) 8 8 { 9 9 AnswerUid = answerUid; 10 10 VoteUid = voteUid; 11 11 VoteType = voteType; 12 VoteAlreadyExists = voteAlreadyExists; 12 13 } 13 14 … … 15 16 public Guid VoteUid { get; } 16 17 public VoteTypeRequest VoteType { get; } 18 public bool VoteAlreadyExists { get; } 17 19 } 18 20 }
Note:
See TracChangeset
for help on using the changeset viewer.