From 1134eef3ad2ec7d3afb4b27af0b73f176b160e8d Mon Sep 17 00:00:00 2001 From: Andrew Lalis Date: Fri, 3 Feb 2023 22:12:26 +0100 Subject: [PATCH] Updated front-end to follow updated APIs. --- .../domains/api/service/GymService.java | 2 +- gymboard-app/quasar.config.js | 4 +- gymboard-app/src/api/main/auth.ts | 37 ++++++++--- gymboard-app/src/api/main/submission.ts | 65 +------------------ gymboard-app/src/boot/i18n.ts | 4 +- .../src/components/AccountMenuItem.vue | 6 +- .../components/ExerciseSubmissionListItem.vue | 3 +- gymboard-app/src/components/LocaleSelect.vue | 2 +- gymboard-app/src/i18n/de/index.ts | 47 +++++++------- gymboard-app/src/i18n/en-US/index.ts | 8 +-- gymboard-app/src/i18n/index.ts | 2 +- gymboard-app/src/i18n/nl-NL/index.ts | 8 +-- gymboard-app/src/pages/AboutPage.vue | 5 +- gymboard-app/src/pages/ErrorNotFound.vue | 12 +--- gymboard-app/src/pages/TestingPage.vue | 4 +- .../src/pages/auth/ActivationPage.vue | 12 ++-- gymboard-app/src/pages/auth/LoginPage.vue | 29 ++++++--- gymboard-app/src/pages/auth/RegisterPage.vue | 16 ++--- .../pages/auth/RegistrationSuccessPage.vue | 4 +- gymboard-app/src/pages/gym/GymHomePage.vue | 1 - .../src/pages/gym/GymSubmissionPage.vue | 21 +++--- gymboard-app/src/router/routes.ts | 8 +-- .../nl/andrewlalis/gymboardcdn/Config.java | 20 ++---- 23 files changed, 134 insertions(+), 186 deletions(-) diff --git a/gymboard-api/src/main/java/nl/andrewlalis/gymboard_api/domains/api/service/GymService.java b/gymboard-api/src/main/java/nl/andrewlalis/gymboard_api/domains/api/service/GymService.java index 2739408..dde78f1 100644 --- a/gymboard-api/src/main/java/nl/andrewlalis/gymboard_api/domains/api/service/GymService.java +++ b/gymboard-api/src/main/java/nl/andrewlalis/gymboard_api/domains/api/service/GymService.java @@ -44,9 +44,9 @@ public class GymService { query.orderBy(criteriaBuilder.desc(root.get("createdAt"))); query.distinct(true); + // TODO: Filter to only verified submissions. return PredicateBuilder.and(criteriaBuilder) .with(criteriaBuilder.equal(root.get("gym"), gym)) - .with(criteriaBuilder.isTrue(root.get("complete"))) .build(); }, PageRequest.of(0, 10)) .map(ExerciseSubmissionResponse::new) diff --git a/gymboard-app/quasar.config.js b/gymboard-app/quasar.config.js index 4a68346..d6f5cd1 100644 --- a/gymboard-app/quasar.config.js +++ b/gymboard-app/quasar.config.js @@ -111,9 +111,7 @@ module.exports = configure(function (ctx) { // directives: [], // Quasar plugins - plugins: [ - 'Notify' - ], + plugins: ['Notify'], }, // animations: 'all', // --- includes all animations diff --git a/gymboard-app/src/api/main/auth.ts b/gymboard-app/src/api/main/auth.ts index a51abad..f036b42 100644 --- a/gymboard-app/src/api/main/auth.ts +++ b/gymboard-app/src/api/main/auth.ts @@ -41,30 +41,49 @@ class AuthModule { clearTimeout(this.tokenRefreshTimer); } - public async register(payload: UserCreationPayload) { + public async register(payload: UserCreationPayload): Promise { const response = await api.post('/auth/register', payload); - console.log(response); - } - - public async activateUser(code: string): Promise { - const response = await api.post('/auth/activate', {code: code}); return response.data; } - private async fetchNewToken(credentials: TokenCredentials): Promise { + public async activateUser(code: string): Promise { + const response = await api.post('/auth/activate', { code: code }); + return response.data; + } + + public async fetchNewToken(credentials: TokenCredentials): Promise { const response = await api.post('/auth/token', credentials); return response.data.token; } - private async refreshToken(authStore: AuthStoreType) { + public async refreshToken(authStore: AuthStoreType) { const response = await api.get('/auth/token', authStore.axiosConfig); authStore.token = response.data.token; } - private async fetchMyUser(authStore: AuthStoreType): Promise { + public async fetchMyUser(authStore: AuthStoreType): Promise { const response = await api.get('/auth/me', authStore.axiosConfig); return response.data; } + + public async updatePassword(newPassword: string, authStore: AuthStoreType) { + await api.post( + '/auth/me/password', + { newPassword: newPassword }, + authStore.axiosConfig + ); + } + + public async generatePasswordResetCode(email: string) { + await api.get('/auth/reset-password', { params: { email: email } }); + } + + public async resetPassword(resetCode: string, newPassword: string) { + await api.post('/auth/reset-password', { + code: resetCode, + newPassword: newPassword, + }); + } } export default AuthModule; diff --git a/gymboard-app/src/api/main/submission.ts b/gymboard-app/src/api/main/submission.ts index dc2bebc..3d563a3 100644 --- a/gymboard-app/src/api/main/submission.ts +++ b/gymboard-app/src/api/main/submission.ts @@ -13,7 +13,7 @@ export interface ExerciseSubmissionPayload { weight: number; weightUnit: string; reps: number; - videoId: number; + videoFileId: string; } export interface ExerciseSubmission { @@ -21,7 +21,7 @@ export interface ExerciseSubmission { createdAt: string; gym: SimpleGym; exercise: Exercise; - status: ExerciseSubmissionStatus; + videoFileId: string; submitterName: string; rawWeight: number; weightUnit: string; @@ -29,14 +29,6 @@ export interface ExerciseSubmission { reps: number; } -export enum ExerciseSubmissionStatus { - WAITING = 'WAITING', - PROCESSING = 'PROCESSING', - FAILED = 'FAILED', - COMPLETED = 'COMPLETED', - VERIFIED = 'VERIFIED', -} - class SubmissionsModule { public async getSubmission( submissionId: string @@ -45,16 +37,6 @@ class SubmissionsModule { return response.data; } - public getSubmissionVideoUrl(submission: ExerciseSubmission): string | null { - if ( - submission.status !== ExerciseSubmissionStatus.COMPLETED && - submission.status !== ExerciseSubmissionStatus.VERIFIED - ) { - return null; - } - return BASE_URL + `/submissions/${submission.id}/video`; - } - public async createSubmission( gym: GymRoutable, payload: ExerciseSubmissionPayload @@ -63,49 +45,6 @@ class SubmissionsModule { const response = await api.post(`/gyms/${gymId}/submissions`, payload); return response.data; } - - public async uploadVideoFile(gym: GymRoutable, file: File): Promise { - const formData = new FormData(); - formData.append('file', file); - const gymId = getGymCompoundId(gym); - const response = await api.post( - `/gyms/${gymId}/submissions/upload`, - formData, - { - headers: { 'Content-Type': 'multipart/form-data' }, - } - ); - return response.data.id as number; - } - - /** - * Asynchronous method that waits until a submission is done processing. - * @param submissionId The submission's id. - */ - public async waitUntilSubmissionProcessed( - submissionId: string - ): Promise { - let failureCount = 0; - let attemptCount = 0; - while (failureCount < 5 && attemptCount < 60) { - await sleep(1000); - attemptCount++; - try { - const response = await this.getSubmission(submissionId); - failureCount = 0; - if ( - response.status !== ExerciseSubmissionStatus.WAITING && - response.status !== ExerciseSubmissionStatus.PROCESSING - ) { - return response; - } - } catch (error) { - console.log(error); - failureCount++; - } - } - throw new Error('Failed to wait for submission to complete.'); - } } export default SubmissionsModule; diff --git a/gymboard-app/src/boot/i18n.ts b/gymboard-app/src/boot/i18n.ts index 58f6716..5b86bf2 100644 --- a/gymboard-app/src/boot/i18n.ts +++ b/gymboard-app/src/boot/i18n.ts @@ -1,5 +1,5 @@ -import {boot} from 'quasar/wrappers'; -import {createI18n} from 'vue-i18n'; +import { boot } from 'quasar/wrappers'; +import { createI18n } from 'vue-i18n'; import messages from 'src/i18n'; diff --git a/gymboard-app/src/components/AccountMenuItem.vue b/gymboard-app/src/components/AccountMenuItem.vue index 8d7065b..6dfc2b1 100644 --- a/gymboard-app/src/components/AccountMenuItem.vue +++ b/gymboard-app/src/components/AccountMenuItem.vue @@ -29,7 +29,7 @@ diff --git a/gymboard-app/src/components/ExerciseSubmissionListItem.vue b/gymboard-app/src/components/ExerciseSubmissionListItem.vue index 057d092..ec5bf75 100644 --- a/gymboard-app/src/components/ExerciseSubmissionListItem.vue +++ b/gymboard-app/src/components/ExerciseSubmissionListItem.vue @@ -15,7 +15,7 @@