From f9a0b8b9ea39485c9e4ee63c0dc389a2d36511c0 Mon Sep 17 00:00:00 2001 From: kpekala Date: Sun, 1 Oct 2023 08:29:58 +0200 Subject: [PATCH 1/3] update --- .../frontend/src/app/quiz/quiz.component.html | 4 ++-- .../frontend/src/app/quiz/quiz.component.scss | 2 ++ .../frontend/src/app/quiz/quiz.service.ts | 20 +++++++++++-------- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/packages/frontend/src/app/quiz/quiz.component.html b/packages/frontend/src/app/quiz/quiz.component.html index 9dba187..5d5d872 100644 --- a/packages/frontend/src/app/quiz/quiz.component.html +++ b/packages/frontend/src/app/quiz/quiz.component.html @@ -3,7 +3,7 @@
- Question {{currentQuestion + 1}} of {{questions.length}} + Pytanie {{currentQuestion + 1}} z {{questions.length}}
{{questions[currentQuestion].description}}
@@ -40,7 +40,7 @@
{{questions[currentQuestion].description}}
class="btn btn-secondary btn-previous" style="margin-top: 1rem;" [disabled]="isPreviousButtonDisabled()" - (click)="onPreviousQuestionClick()">Previous + (click)="onPreviousQuestionClick()">Poprzednie
diff --git a/packages/frontend/src/app/quiz/quiz.component.scss b/packages/frontend/src/app/quiz/quiz.component.scss index e1dd87d..e4797e4 100644 --- a/packages/frontend/src/app/quiz/quiz.component.scss +++ b/packages/frontend/src/app/quiz/quiz.component.scss @@ -40,8 +40,10 @@ position: absolute; top: 50%; left: 50%; + width: 100%; transform: translateX(-50%) translateY(-50%); color: white; + padding: 0.5rem; } } \ No newline at end of file diff --git a/packages/frontend/src/app/quiz/quiz.service.ts b/packages/frontend/src/app/quiz/quiz.service.ts index 05f910b..c604131 100644 --- a/packages/frontend/src/app/quiz/quiz.service.ts +++ b/packages/frontend/src/app/quiz/quiz.service.ts @@ -1,5 +1,5 @@ import { Injectable } from "@angular/core"; -import { Observable, of, tap } from "rxjs"; +import { Observable, map, of, tap } from "rxjs"; import { Question } from "../dto"; import { HttpClient } from "@angular/common/http"; @@ -9,21 +9,25 @@ export class QuizService { private questions: Question[]; - private apiPath = 'localhost:3000/v1/quiz/'; + private apiPath = 'http://localhost:3000/v1/quiz/'; constructor(private http: HttpClient) {} fetchQuestions(): Observable{ - return this.http.get(`${this.apiPath}/questions`); + return this.http.get(`${this.apiPath}questions`) + .pipe( + map(result => result.questions), + tap((questions: []) => {this.questions = questions}) + ); return of([ { answers: [ - {description: 'Jabłkiem', answerId: '0'}, - {description: 'Parówką', answerId: '1'}, - {description: 'Sokiem', answerId: '2'}, - {description: 'Żwirkiem', answerId: '3'} + {description: 'Zdecydowanie tak', answerId: '0'}, + {description: 'Raczej tak', answerId: '1'}, + {description: 'Raczej nie', answerId: '2'}, + {description: 'Zdecydowanie nie', answerId: '3'} ], - description: 'Jakim warzywem chciałbyś być ?', + description: 'Czy lubisz zwierzęta ?', questionId: 0 }, { From 98cf10885115c3904ec861aa5ea1c0176ff83e82 Mon Sep 17 00:00:00 2001 From: kpekala Date: Sun, 1 Oct 2023 09:43:37 +0200 Subject: [PATCH 2/3] clean --- packages/frontend/src/app/dto/index.ts | 24 ++++----- .../frontend/src/app/quiz/quiz.component.html | 9 +--- .../frontend/src/app/quiz/quiz.component.ts | 47 +++++++----------- .../frontend/src/app/quiz/quiz.service.ts | 49 ++++++++++++------- 4 files changed, 63 insertions(+), 66 deletions(-) diff --git a/packages/frontend/src/app/dto/index.ts b/packages/frontend/src/app/dto/index.ts index 9513d47..9943093 100644 --- a/packages/frontend/src/app/dto/index.ts +++ b/packages/frontend/src/app/dto/index.ts @@ -3,26 +3,28 @@ export interface GetAllQuestionsDTO { size: number; } -export interface AnswerDTO { - questionId: string; // the same as param +export interface SubmitAnswerDTO { + questionId: string; answerId: string; } +export interface Answer { + answerId: string; + description: string; +} + + export interface Question { questionId: number; description: string; answers: Answer[]; -} +} -export interface Answer { - answerId: string; - description: string; -} -export type Endpoint = 'getAllQuestions' | 'postAnswer' | 'getResults'; +export type Endpoint = 'getAllQuestions' | 'postAnswers' | 'getResults'; export const ENDPOINTS: Record = { - getAllQuestions: '/v1/questions', - postAnswer: '/v1/answer/:questionId', - getResults: '/v1/results' + getAllQuestions: '/v1/quiz/questions', + postAnswers: '/v1/quiz/answers', + getResults: '/v1/quiz/results' }; \ No newline at end of file diff --git a/packages/frontend/src/app/quiz/quiz.component.html b/packages/frontend/src/app/quiz/quiz.component.html index 5d5d872..a222c64 100644 --- a/packages/frontend/src/app/quiz/quiz.component.html +++ b/packages/frontend/src/app/quiz/quiz.component.html @@ -3,7 +3,7 @@
- Pytanie {{currentQuestion + 1}} z {{questions.length}} + Pytanie {{currentQuestion + 1}} z 10
{{questions[currentQuestion].description}}
@@ -27,14 +27,7 @@
{{questions[currentQuestion].description}}
{{questions[currentQuestion].answers[3].description}}
-