Changes in / [53bebc0:74ad056]


Ignore:
Location:
src
Files:
15 deleted
17 edited

Legend:

Unmodified
Added
Removed
  • src/Clients/Angular/finki-chattery/src/app/core/state/question-facade.service.ts

    r53bebc0 r74ad056  
    1515import {
    1616  AnswerQuestion,
    17   EditAnswerQuestion,
    18   EditAnswerResponse,
    1917  EffectStartedWorking,
    2018  GetPreviewQuestionsLatest,
     
    9391  }
    9492
    95   public editAnswerResponse(answerUid: string, questionUid: string, answerResponseUid: string, text: string): void {
    96     this.dispatchEffect(new EditAnswerResponse(questionUid, answerUid, answerResponseUid, text));
    97   }
    98 
    99   public editAnswer(answerUid: string, questionUid: string, text: string): void {
    100     this.dispatchEffect(new EditAnswerQuestion(questionUid, answerUid, text));
    101   }
    102 
    10393  public fetchQuestion(questionUid: string): void {
    10494    this.dispatchEffect(new GetQuestionState(questionUid));
  • src/Clients/Angular/finki-chattery/src/app/core/state/question-state/question.actions.ts

    r53bebc0 r74ad056  
    2929  AnswerQuestion = '[Question] AnswerQuestion',
    3030  AnswerQuestionSuccess = '[Question] AnswerQuestion Success',
    31   EditAnswerQuestion = '[Question] EditAnswerQuestion',
    32   EditAnswerQuestionSuccess = '[Question] EditAnswerQuestion Success',
    33   EditAnswerResponse = '[Question] EditAnswerResponse',
    34   EditAnswerResponseSuccess = '[Question] EditAnswerResponse Success',
    3531  EffectStartedWorking = '[Question] Effect Started Working',
    3632  EffectFinishedWorking = '[Question] Effect Finished Working',
    3733  EffectFinishedWorkingError = '[Question] Effect Finished Working error'
    38 }
    39 
    40 export class EditAnswerQuestion implements Action {
    41   readonly type = QuestionActionTypes.EditAnswerQuestion;
    42 
    43   constructor(public questionUid: string, public answerUid: string, public text: string) {}
    44 }
    45 
    46 export class EditAnswerQuestionSuccess implements Action {
    47   readonly type = QuestionActionTypes.EditAnswerQuestionSuccess;
    48 
    49   constructor(public payload: AnswerQuestionStateViewModel, public answerUid: string) {}
    50 }
    51 
    52 export class EditAnswerResponse implements Action {
    53   readonly type = QuestionActionTypes.EditAnswerResponse;
    54 
    55   constructor(public questionUid: string, public answerUid: string, public answerResponseUid: string, public text: string) {}
    56 }
    57 
    58 export class EditAnswerResponseSuccess implements Action {
    59   readonly type = QuestionActionTypes.EditAnswerResponseSuccess;
    60 
    61   constructor(public payload: AnswerResponseQuestionStateViewModel, public answerUid: string, public answerResponseUid: string) {}
    6234}
    6335
     
    185157  | RespondToAnswerSuccess
    186158  | AnswerQuestionSuccess
    187   | EditAnswerQuestionSuccess
    188   | EditAnswerResponseSuccess
    189159  | EffectStartedWorking
    190160  | EffectFinishedWorking
  • src/Clients/Angular/finki-chattery/src/app/core/state/question-state/question.effects.ts

    r53bebc0 r74ad056  
    1919  AnswerQuestion,
    2020  AnswerQuestionSuccess,
    21   EditAnswerQuestion,
    22   EditAnswerQuestionSuccess,
    23   EditAnswerResponse,
    24   EditAnswerResponseSuccess,
    2521  EffectFinishedWorking,
    2622  EffectFinishedWorkingError,
     
    190186    );
    191187  });
    192 
    193   editResponseToAnswer$ = createEffect(() => {
    194     return this.actions$.pipe(
    195       ofType<EditAnswerResponse>(QuestionActionTypes.EditAnswerResponse),
    196       mergeMap((action) => {
    197         return this.api
    198           .put<AnswerResponseQuestionStateResponse>(
    199             `v1/questions/${action.questionUid}/answers/${action.answerUid}/answerresponses/${action.answerResponseUid}`,
    200             new RespondToAnswerRequest(action.text)
    201           )
    202           .pipe(
    203             tap((state) => this.notification.successNotification('success-edit-answer-response')),
    204             switchMap((state) => [
    205               new EditAnswerResponseSuccess(
    206                 QuestionMapper.ToAnswerResponseQuestionStateViewModel(state),
    207                 action.answerUid,
    208                 action.answerResponseUid
    209               ),
    210               new EffectFinishedWorking()
    211             ]),
    212             catchError((err) => [new EffectFinishedWorkingError(err)])
    213           );
    214       })
    215     );
    216   });
    217 
    218   editAnswer$ = createEffect(() => {
    219     return this.actions$.pipe(
    220       ofType<EditAnswerQuestion>(QuestionActionTypes.EditAnswerQuestion),
    221       mergeMap((action) => {
    222         return this.api
    223           .put<AnswerQuestionStateResponse>(
    224             `v1/questions/${action.questionUid}/answers/${action.answerUid}`,
    225             new AnswerQuestionRequest(action.text)
    226           )
    227           .pipe(
    228             tap((state) => this.notification.successNotification('success-edit-answer')),
    229             switchMap((state) => [
    230               new EditAnswerQuestionSuccess(QuestionMapper.ToAnswerQuestionStateViewModel(state), action.answerUid),
    231               new EffectFinishedWorking()
    232             ]),
    233             catchError((err) => [new EffectFinishedWorkingError(err)])
    234           );
    235       })
    236     );
    237   });
    238188}
  • src/Clients/Angular/finki-chattery/src/app/core/state/question-state/question.reducers.ts

    r53bebc0 r74ad056  
    114114      };
    115115    }
    116     case QuestionActionTypes.EditAnswerResponseSuccess: {
    117       if (state.question) {
    118         return {
    119           ...state,
    120           question: {
    121             ...state.question,
    122             answers: state.question.answers.map((x) => {
    123               if (x.uid === action.answerUid) {
    124                 return {
    125                   ...x,
    126                   answerResponses: [...x.answerResponses.filter((y) => y.uid !== action.answerResponseUid), action.payload]
    127                 };
    128               }
    129 
    130               return x;
    131             })
    132           }
    133         };
    134       }
    135 
    136       return {
    137         ...state
    138       };
    139     }
    140     case QuestionActionTypes.EditAnswerQuestionSuccess: {
    141       if (state.question) {
    142         return {
    143           ...state,
    144           question: {
    145             ...state.question,
    146             answers: state.question.answers.map((x) => {
    147               if (x.uid === action.answerUid) {
    148                 return {
    149                   ...x,
    150                   text: action.payload.text
    151                 };
    152               }
    153 
    154               return x;
    155             })
    156           }
    157         };
    158       }
    159 
    160       return {
    161         ...state
    162       };
    163     }
    164116    case QuestionActionTypes.AnswerQuestionSuccess: {
    165117      if (state.question) {
  • src/Clients/Angular/finki-chattery/src/app/shared-app/components/components.ts

    r53bebc0 r74ad056  
    77import { AnswerQuestionComponent } from './question/answer-question/answer-question.component';
    88import { AskQuestionSharedComponent } from './question/ask-question-shared/ask-question-shared.component';
    9 import { EditAnswerDialogComponent } from './question/edit-answer-dialog/edit-answer-dialog.component';
    10 import { EditAnswerResponseDialogComponent } from './question/edit-answer-response-dialog/edit-answer-response-dialog.component';
    119import { PreviewQuestionDisplayComponent } from './question/preview-question-display/preview-question-display.component';
    1210import { PreviewQuestionFullComponent } from './question/preview-question-full/preview-question-full.component';
     
    3028  TextEditorComponent,
    3129  RespondToAnswerDialogComponent,
    32   AnswerQuestionComponent,
    33   EditAnswerDialogComponent,
    34   EditAnswerResponseDialogComponent
     30  AnswerQuestionComponent
    3531];
  • src/Clients/Angular/finki-chattery/src/app/shared-app/components/question/question-preview/question-preview.component.html

    r53bebc0 r74ad056  
    4747              <mat-chip class="cursor">{{ answerResponse.student.index }}</mat-chip> -
    4848              {{ answerResponse.createdOn | momentDate: 'LL' }}
    49               <span
    50                 class="cursor text-bold"
    51                 *ngIf="studentQuestion.currentUserCanEditAnswerResponse(answerResponse)"
    52                 (click)="editAnswerResponse(question.uid, answer.uid, answerResponse.uid, answerResponse.text)"
    53                 >{{ 'question-preview-edit-answer-response' | translate }}</span
    54               >
    5549              <hr />
    5650            </div>
     
    6256          'question-preview-respond-to-answer-button' | translate
    6357        }}</app-button>
    64         <app-button
    65           *ngIf="studentQuestion.currentUserCanEditAnswer(answer)"
    66           (action)="editAnswer(question.uid, answer.uid, answer.text)"
    67           [buttonType]="ButtonType.Basic"
    68           >{{ 'question-preview-edit-answer' | translate }}</app-button
    69         >
    7058      </mat-card-actions>
    7159    </mat-card>
  • src/Clients/Angular/finki-chattery/src/app/shared-app/components/question/question-preview/question-preview.component.ts

    r53bebc0 r74ad056  
    22import { Component, OnInit } from '@angular/core';
    33import { NotificationService } from 'src/app/core/services/notification.service';
    4 import { StudentQuestionService } from 'src/app/core/services/student-question.service';
    54import { QuestionFacadeService } from 'src/app/core/state/question-facade.service';
    65
     
    2221    private questionFacade: QuestionFacadeService,
    2322    private notification: NotificationService,
    24     private dialog: SharedDialogService,
    25     public studentQuestion: StudentQuestionService
     23    private dialog: SharedDialogService
    2624  ) {}
    2725
     
    5048    this.dialog.respondToAnswer(this.question.uid, answerUid);
    5149  }
    52 
    53   editAnswer(questionUid: string, answerUid: string, text: string): void {
    54     this.dialog.editAnswer(questionUid, answerUid, text);
    55   }
    56 
    57   editAnswerResponse(questionUid: string, answerUid: string, answerResponseUid: string, text: string): void {
    58     this.dialog.editResponseToAnswer(questionUid, answerUid, answerResponseUid, text);
    59   }
    6050}
  • src/Clients/Angular/finki-chattery/src/app/shared-app/components/question/respond-to-answer-dialog/respond-to-answer-dialog.component.html

    r53bebc0 r74ad056  
    1313</mat-dialog-content>
    1414<mat-dialog-actions>
    15   <app-button class="margin-right-sm" [buttonType]="ButtonType.Basic" (action)="dialogRef.close()">
     15  <app-button [buttonType]="ButtonType.Basic" (action)="dialogRef.close()">
    1616    {{ 'close-button' | translate }}
    1717  </app-button>
  • src/Clients/Angular/finki-chattery/src/app/shared-app/services/shared-dialog.service.ts

    r53bebc0 r74ad056  
    22import { MatDialog, MatDialogRef } from '@angular/material/dialog';
    33import { Observable } from 'rxjs';
    4 import { EditAnswerDialogComponent } from '../components/question/edit-answer-dialog/edit-answer-dialog.component';
    5 // tslint:disable-next-line: max-line-length
    6 import { EditAnswerResponseDialogComponent } from '../components/question/edit-answer-response-dialog/edit-answer-response-dialog.component';
    74import { RespondToAnswerDialogComponent } from '../components/question/respond-to-answer-dialog/respond-to-answer-dialog.component';
    85
     
    2522    return dialogRef.afterClosed();
    2623  }
    27 
    28   public editResponseToAnswer(questionUid: string, answerUid: string, answerResponseUid: string, text: string): Observable<any> {
    29     let dialogRef: MatDialogRef<EditAnswerResponseDialogComponent>;
    30     dialogRef = this.dialog.open(EditAnswerResponseDialogComponent, {
    31       width: '650px',
    32       height: 'auto'
    33     });
    34 
    35     dialogRef.componentInstance.questionUid = questionUid;
    36     dialogRef.componentInstance.answerUid = answerUid;
    37     dialogRef.componentInstance.answerResponseUid = answerResponseUid;
    38     dialogRef.componentInstance.textFieldValue = text;
    39 
    40     return dialogRef.afterClosed();
    41   }
    42 
    43   public editAnswer(questionUid: string, answerUid: string, text: string): Observable<any> {
    44     let dialogRef: MatDialogRef<EditAnswerDialogComponent>;
    45     dialogRef = this.dialog.open(EditAnswerDialogComponent, {
    46       width: '650px',
    47       height: 'auto'
    48     });
    49 
    50     dialogRef.componentInstance.questionUid = questionUid;
    51     dialogRef.componentInstance.answerUid = answerUid;
    52     dialogRef.componentInstance.textFieldValue = text;
    53 
    54     return dialogRef.afterClosed();
    55   }
    5624}
  • src/Clients/Angular/finki-chattery/src/assets/translations/en.json

    r53bebc0 r74ad056  
    6767  "answer-question-title": "Give your answer to the question",
    6868  "answer-question-button": "Answer",
    69   "success-edit-answer-response": "Successfully edited response to answer",
    70   "success-edit-answer": "Successfully edited answer",
    71   "edit-respond-to-answer-title": "Edit answer response",
    72   "edit-answer-title": "Edit answer",
    73   "question-preview-edit-answer": "Edit answer",
    74   "question-preview-edit-answer-response": "Edit response",
    7569  "StudentDoesNotOwnQuestion": "You do not own this question",
    7670  "AnswerAlreadyUpvoted": "You have already upvoted this answer",
  • src/FinkiChattery/FinkiChattery.Api/Controllers/v1/AnswerResponsesController.cs

    r53bebc0 r74ad056  
    3131            return Ok(answerResponse.ToAnswerResponseQuestionStateResponse());
    3232        }
    33 
    34         [HttpPut("{answerResponseUid:Guid}")]
    35         [Authorize(AuthenticationSchemes = IdentityServerAuthenticationDefaults.AuthenticationScheme, Policy = AuthenticationPolicy.Student)]
    36         public async Task<IActionResult> EditAnswerResponse([FromRoute] Guid questionUid, [FromRoute] Guid answerUid, [FromRoute] Guid answerResponseUid, [FromBody] AnswerResponseRequest request)
    37         {
    38             var answerResponse = await MediatorService.SendAsync(new EditAnswerResponseCommand(questionUid, answerUid, answerResponseUid, request.Text));
    39             return Ok(answerResponse.ToAnswerResponseQuestionStateResponse());
    40         }
    4133    }
    4234}
  • src/FinkiChattery/FinkiChattery.Api/Controllers/v1/AnswersController.cs

    r53bebc0 r74ad056  
    3232        }
    3333
    34         [HttpPut("{answerUid:Guid}")]
    35         [Authorize(AuthenticationSchemes = IdentityServerAuthenticationDefaults.AuthenticationScheme, Policy = AuthenticationPolicy.Student)]
    36         public async Task<IActionResult> EditAnswer([FromRoute] Guid questionUid, [FromRoute] Guid answerUid, [FromBody] AnswerQuestionRequest request)
    37         {
    38             var answer = await MediatorService.SendAsync(new EditAnswerCommand(questionUid, answerUid, request.Text));
    39             return Ok(answer.ToAnswerQuestionStateResponse());
    40         }
    41 
    4234        [HttpPut("{answerUid:Guid}/correct")]
    4335        [Authorize(AuthenticationSchemes = IdentityServerAuthenticationDefaults.AuthenticationScheme, Policy = AuthenticationPolicy.Student)]
  • src/FinkiChattery/FinkiChattery.Commands/Questioning/QuestioningErrorCodes.cs

    r53bebc0 r74ad056  
    1717        public const string AnswerInQuestionNotFound = "AnswerInQuestionNotFound";
    1818        public const string StudentDoesNotOwnQuestion = "StudentDoesNotOwnQuestion";
    19         public const string StudentDoesNotOwnAnswer = "StudentDoesNotOwnAnswer";
    20         public const string StudentDoesNotOwnAnswerResponse = "StudentDoesNotOwnAnswerResponse";
    2119        public const string AnswerIsAlreadyMarkedAsCorrect = "AnswerIsAlreadyMarkedAsCorrect";
    2220    }
  • src/FinkiChattery/FinkiChattery.Persistence/Repositories/Contracts/IAnswerRepo.cs

    r53bebc0 r74ad056  
    88    {
    99        Task<bool> AnswerInQuestionExists(Guid questionUid, Guid answerUid);
    10 
    11         Task<bool> AnswerIsOwnedByStudent(Guid answerUid, long applicationUserId);
    1210    }
    1311}
  • src/FinkiChattery/FinkiChattery.Persistence/Repositories/Contracts/IAnswerResponseRepo.cs

    r53bebc0 r74ad056  
    11using FinkiChattery.Persistence.Models;
    2 using System;
    3 using System.Threading.Tasks;
    42
    53namespace FinkiChattery.Persistence.Repositories
     
    75    public interface IAnswerResponseRepo : IRepository<AnswerResponse>
    86    {
    9         Task<bool> StudentIsOwnerOfAnswerResponse(Guid answerResponseUid, long applicationUserId);
    107    }
    118}
  • src/FinkiChattery/FinkiChattery.Persistence/Repositories/Implementations/AnswerRepo.cs

    r53bebc0 r74ad056  
    2121                .AnyAsync();
    2222        }
    23 
    24         public async Task<bool> AnswerIsOwnedByStudent(Guid answerUid, long applicationUserId)
    25         {
    26             return await DbSet
    27                 .AsNoTracking()
    28                 .Where(x => x.Uid == answerUid && x.Student.ApplicationUserFk == applicationUserId)
    29                 .AnyAsync();
    30         }
    3123    }
    3224}
  • src/FinkiChattery/FinkiChattery.Persistence/Repositories/Implementations/AnswerResponseRepo.cs

    r53bebc0 r74ad056  
    11using FinkiChattery.Persistence.Context;
    22using FinkiChattery.Persistence.Models;
    3 using Microsoft.EntityFrameworkCore;
    4 using System;
    5 using System.Linq;
    6 using System.Threading.Tasks;
    73
    84namespace FinkiChattery.Persistence.Repositories
     
    139        {
    1410        }
    15 
    16         public async Task<bool> StudentIsOwnerOfAnswerResponse(Guid answerResponseUid, long applicationUserId)
    17         {
    18             return await DbSet
    19                 .AsNoTracking()
    20                 .Where(x => x.Uid == answerResponseUid && x.Student.ApplicationUserFk == applicationUserId)
    21                 .AnyAsync();
    22         }
    2311    }
    2412}
Note: See TracChangeset for help on using the changeset viewer.