Skip to content

Commit

Permalink
Merge pull request #64 from 7ubi/refactor/responses
Browse files Browse the repository at this point in the history
Refactoring
  • Loading branch information
7ubi authored Aug 14, 2024
2 parents fc968ff + 79bdc25 commit ebf364c
Show file tree
Hide file tree
Showing 53 changed files with 696 additions and 1,010 deletions.
7 changes: 3 additions & 4 deletions .github/workflows/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ jobs:
deploy:
name: Deployment
runs-on: self-hosted
if: github.event_name != 'pull_request'
needs:
- build
steps:
Expand All @@ -59,19 +60,17 @@ jobs:
export DB_PASSWORD=${{ secrets.DB_PASSWORD }}
docker-compose down
docker-compose up --build -d
if: github.event_name != 'pull_request'
documentation:
name: Deploy documentation
if: github.event_name != 'pull_request'
runs-on: self-hosted
needs:
- deploy
steps:
- name: Checkout Code
uses: actions/checkout@v3
if: github.event_name != 'pull_request'
- name: Start docker-compose
run: |
cd indexcards-docu
docker-compose down
docker-compose up --build -d
if: github.event_name != 'pull_request'
docker-compose up --build -d
3 changes: 3 additions & 0 deletions indexcards-docu/indexcards-docu.iml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="WEB_MODULE" version="4">
<component name="CheckStyle-IDEA-Module" serialisationVersion="2">
<option name="activeLocationsIds" />
</component>
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$" />
Expand Down
23 changes: 1 addition & 22 deletions indexcards-ui/src/app/app.response.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,3 @@
export interface MessageResponse {
readonly message: string;
}

export interface ResultResponse {
readonly success: boolean;
readonly errorMessages: MessageResponse[];
}

export interface LoginResponse {
readonly token: string;
readonly type: string;
Expand All @@ -17,7 +8,7 @@ export interface LoginResponse {
export interface IndexCardResponse {
readonly indexCardId: number;
readonly question: string;
readonly answer:string;
readonly answer: string;
readonly assessment: Assessment;
}

Expand All @@ -27,18 +18,6 @@ export interface ProjectResponse {
readonly indexCardResponses: IndexCardResponse[];
}

export interface UserProjectsResponse extends ResultResponse {
readonly projectResponses: ProjectResponse[];
}

export interface UserProjectResponse extends ResultResponse {
readonly projectResponse: ProjectResponse;
}

export interface IndexCardResponses extends ResultResponse {
readonly indexCardResponses: IndexCardResponse[];
}

export enum Assessment {
UNRATED,
BAD,
Expand Down
31 changes: 9 additions & 22 deletions indexcards-ui/src/app/component/auth/login/login.component.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import {Component, OnInit} from '@angular/core';
import {FormBuilder, FormGroup, Validators} from '@angular/forms';
import { HttpClient } from "@angular/common/http";
import {LoginResponse} from "../../../app.response";
import {LoginService} from "./login.service";
import {Router} from "@angular/router";
import {MessageService} from "primeng/api";
import {TranslateService} from "@ngx-translate/core";
import {LoginResponse} from "../../../app.response";
import {HttpService} from "../../../services/http.service";

@Component({
selector: 'app-login',
Expand All @@ -17,7 +17,7 @@ export class LoginComponent implements OnInit {
public loginFormGroup: FormGroup;

constructor(
private http: HttpClient,
private httpService: HttpService,
private router: Router,
private loginService: LoginService,
private messageService: MessageService,
Expand All @@ -31,35 +31,22 @@ export class LoginComponent implements OnInit {
}

ngOnInit(): void {
if(this.loginService.isLoggedIn()) {
if (this.loginService.isLoggedIn()) {
this.router.navigate(['/']);
}
}

makeLogin() {

if(!this.loginFormGroup.valid) {
if (!this.loginFormGroup.valid) {
this.throwInvalidForm();
return;
}

this.http.post<LoginResponse>('/api/auth/login', this.getLoginRequestParameter())
.subscribe(
response => {
this.loginService.saveBearer(response);

this.router.navigate(['/']);
}, error => {
if(error.status === 401){
this.messageService.add({
key: 'tr',
severity: 'error',
summary: this.translateService.instant('common.error'),
detail: this.translateService.instant('auth.wrong_credentials')
});
}
}
);
this.httpService.post<LoginResponse>('/api/auth/login', this.getLoginRequestParameter(), response => {
this.loginService.saveBearer(response);
this.router.navigate(['/']).then();
});
}

private throwInvalidForm() {
Expand Down
43 changes: 15 additions & 28 deletions indexcards-ui/src/app/component/auth/signup/signup.component.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { HttpClient } from '@angular/common/http';
import { Component } from '@angular/core';
import {HttpClient} from '@angular/common/http';
import {Component} from '@angular/core';
import {FormBuilder, FormGroup, Validators} from '@angular/forms';
import {Router} from '@angular/router';
import {ResultResponse} from '../../../app.response';
import {MessageService} from 'primeng/api';
import {TranslateService} from "@ngx-translate/core";
import {HttpService} from "../../../services/http.service";

@Component({
selector: 'app-signup',
Expand All @@ -16,6 +16,7 @@ export class SignupComponent {

constructor(
private http: HttpClient,
private httpService: HttpService,
private router: Router,
private messageService: MessageService,
private formBuilder: FormBuilder,
Expand All @@ -29,8 +30,9 @@ export class SignupComponent {
repeatPassword: ['', Validators.required]
});
}

createAccount() {
if(!this.signUpFormGroup.valid) {
if (!this.signUpFormGroup.valid) {
this.messageService.add({
key: 'tr',
severity: 'error',
Expand All @@ -40,7 +42,7 @@ export class SignupComponent {
return;
}

if(this.signUpFormGroup.get('password')?.value !== this.signUpFormGroup.get('repeatPassword')?.value) {
if (this.signUpFormGroup.get('password')?.value !== this.signUpFormGroup.get('repeatPassword')?.value) {
this.messageService.add({
key: 'tr',
severity: 'error',
Expand All @@ -50,30 +52,15 @@ export class SignupComponent {
return;
}

this.http.post<ResultResponse>('/api/auth/signup', this.getCreateAccountParameter())
.subscribe((response) => {
if(response.success) {
this.messageService.add({
key: 'tr',
severity: 'success',
summary: this.translateService.instant('common.success'),
detail: this.translateService.instant('auth.account_created'),
});
this.router.navigate(['/login']);
}

}, err => {
const response: ResultResponse = err.error;

response.errorMessages.forEach((error) => {
this.messageService.add({
key: 'tr',
severity: 'error',
summary: this.translateService.instant('common.error'),
detail: this.translateService.instant(`backend.${error.message}`)
});
});
this.httpService.post<undefined>('/api/auth/signup', this.getCreateAccountParameter(), (_) => {

Check warning on line 55 in indexcards-ui/src/app/component/auth/signup/signup.component.ts

View workflow job for this annotation

GitHub Actions / Linting

'_' is defined but never used
this.messageService.add({
key: 'tr',
severity: 'success',
summary: this.translateService.instant('common.success'),
detail: this.translateService.instant('auth.account_created'),
});
this.router.navigate(['/login']).then();
});
}

getCreateAccountParameter() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import {Component, OnInit} from '@angular/core';
import {FormBuilder, FormGroup, Validators} from "@angular/forms";
import {HttpClient} from "@angular/common/http";
import {ResultResponse} from "../../../app.response";
import {LoginService} from "../../auth/login/login.service";
import {ActivatedRoute, Router} from "@angular/router";
import {MessageService} from "primeng/api";
Expand Down Expand Up @@ -36,29 +35,25 @@ export class CreateIndexcardComponent implements OnInit {
}

ngOnInit(): void {
this.id = this.route.snapshot.paramMap.get('id');
}
this.id = this.route.snapshot.paramMap.get('id');
}

createIndexcard() {
if(!this.createIndexCardFormGroup.valid) {
if (!this.createIndexCardFormGroup.valid) {
this.throwInvalidForm();
return;
}

this.httpService.post<ResultResponse>(
'/api/indexCard/create',
this.createRequest(),
(response) => {
if(response.success) {
this.httpService.post<undefined>('/api/indexCard/create', this.createRequest(),
(_) => {

Check warning on line 48 in indexcards-ui/src/app/component/indexcard/create-indexcard/create-indexcard.component.ts

View workflow job for this annotation

GitHub Actions / Linting

'_' is defined but never used
this.messageService.add({
key: 'tr',
severity: 'success',
summary: this.translateService.instant('common.success'),
detail: this.translateService.instant('indexcard.created'),
});
this.router.navigate(["/project", this.id]);
}
});
});
}

createRequest() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@

<div class="container">
<h1>{{ 'indexcard.stat' | translate }} {{ userProject?.projectResponse?.name }}</h1>
<h1>{{ 'indexcard.stat' | translate }} {{ userProject?.name }}</h1>
<div class="chart-container">
<p-chart type="pie" [data]="data" [options]="chartOptions"></p-chart>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import {Component, OnInit} from '@angular/core';
import {Assessment, UserProjectResponse} from "../../../app.response";
import {Assessment, ProjectResponse} from "../../../app.response";
import {ActivatedRoute, Router} from "@angular/router";
import {HttpClient} from "@angular/common/http";
import {MessageService} from "primeng/api";
import {LoginService} from "../../auth/login/login.service";
import {TranslateService} from "@ngx-translate/core";
import {HttpService} from "../../../services/http.service";

Expand All @@ -12,9 +9,9 @@ import {HttpService} from "../../../services/http.service";
templateUrl: './indexcard-quiz-stat.component.html',
styleUrls: ['./indexcard-quiz-stat.component.css']
})
export class IndexcardQuizStatComponent implements OnInit{
export class IndexcardQuizStatComponent implements OnInit {

userProject?: UserProjectResponse;
userProject?: ProjectResponse;

private id: string | null = '';

Expand All @@ -25,9 +22,6 @@ export class IndexcardQuizStatComponent implements OnInit{
constructor(
private route: ActivatedRoute,
private router: Router,
private http: HttpClient,
private messageService: MessageService,
private loginService: LoginService,
private translateService: TranslateService,
private httpService: HttpService
) {
Expand All @@ -36,11 +30,11 @@ export class IndexcardQuizStatComponent implements OnInit{
ngOnInit(): void {
this.id = this.route.snapshot.paramMap.get('id');

this.httpService.get<UserProjectResponse>(`/api/project/project?id=${this.id}`,
this.httpService.get<ProjectResponse>(`/api/project/project?id=${this.id}`,
response => {
this.userProject = response;
this.generateChartData();
}, () => this.router.navigate(['']));
this.userProject = response;
this.generateChartData();
}, () => this.router.navigate(['']));
}

generateChartData(): void {
Expand All @@ -57,15 +51,19 @@ export class IndexcardQuizStatComponent implements OnInit{
const datasets = [];
const colors = [];
const documentStyle = getComputedStyle(document.documentElement);
for(const assessment in Object.keys(Assessment).filter((item) => {return isNaN(Number(item));})) {
datasets.push( this.userProject?.projectResponse.indexCardResponses
.filter(v => Assessment[v.assessment].toString() === assessment).length
for (const assessment in Object.keys(Assessment).filter((item) => {
return isNaN(Number(item));
})) {
datasets.push(this.userProject!.indexCardResponses

Check warning on line 57 in indexcards-ui/src/app/component/indexcard/indexcard-quiz-stat/indexcard-quiz-stat.component.ts

View workflow job for this annotation

GitHub Actions / Linting

Forbidden non-null assertion
.filter(v => Assessment[v.assessment].toString() === assessment).length
);
colors.push(documentStyle.getPropertyValue(`--${Assessment[assessment].toString().toLowerCase()}`));
}

let labels = Object.keys(Assessment).filter((item) => {return isNaN(Number(item));})
labels = labels.map(label => this.translateService.instant(label.toLowerCase()));
let labels = Object.keys(Assessment).filter((item) => {
return isNaN(Number(item));
})
labels = labels.map(label => this.translateService.instant(label.toLowerCase()));

this.data = {
title: "Status",
Expand All @@ -80,10 +78,10 @@ export class IndexcardQuizStatComponent implements OnInit{
}

onClickQuizButton() {
this.router.navigate(['project', this.id, 'quiz']);
this.router.navigate(['project', this.id, 'quiz']).then();
}

onClickToProject() {
this.router.navigate(['project', this.id]);
this.router.navigate(['project', this.id]).then();
}
}
Loading

0 comments on commit ebf364c

Please sign in to comment.