diff --git a/src/app/components/challenge-card/challenge-card.component.ts b/src/app/components/challenge-card/challenge-card.component.ts index 47b94e1..c322fd4 100644 --- a/src/app/components/challenge-card/challenge-card.component.ts +++ b/src/app/components/challenge-card/challenge-card.component.ts @@ -1,10 +1,9 @@ -import {Component, inject, input, signal, viewChild} from '@angular/core'; +import {Component, inject, input, viewChild} from '@angular/core'; import {IonicModule, LoadingController, ToastController} from "@ionic/angular"; import {GetRandomChallengeDto, RandomchallengesService} from "../../services/api"; import {firstValueFrom} from "rxjs"; import {TooltipComponent} from "../tooltip/tooltip.component"; import {ProofFormComponent} from "../proof-form/proof-form.component"; -import {SignOnFormComponent} from "../sign-on-form/sign-on-form.component"; @Component({ selector: 'app-challenge-card', @@ -60,10 +59,10 @@ export class ChallengeCardComponent { color: 'success' }); await toast.present(); - } catch { + } catch (e) { this.isModalOpen = false; const toast = await this.toastCtrl.create({ - message: 'Tu as déjà déposé une preuve pour ce défi', + message: e.error ?? "Impossible de déposer une preuve", duration: 2000, color: 'danger' }); diff --git a/src/app/components/post/post.component.html b/src/app/components/post/post.component.html new file mode 100644 index 0000000..773e7c7 --- /dev/null +++ b/src/app/components/post/post.component.html @@ -0,0 +1,3 @@ +@for (post of posts(); track post.id) { + +} \ No newline at end of file diff --git a/src/app/components/post/post.component.scss b/src/app/components/post/post.component.scss new file mode 100644 index 0000000..e69de29 diff --git a/src/app/components/post/post.component.ts b/src/app/components/post/post.component.ts new file mode 100644 index 0000000..2cbc719 --- /dev/null +++ b/src/app/components/post/post.component.ts @@ -0,0 +1,42 @@ +import {Component, inject, input, OnInit, signal} from '@angular/core'; +import {FriendsService, GetFriendDto, GetPostDto} from "../../services/api"; +import {firstValueFrom} from "rxjs"; +import {LoadingController, ToastController} from "@ionic/angular"; + +@Component({ + selector: 'app-post', + templateUrl: './post.component.html', + styleUrls: ['./post.component.scss'], +}) +export class PostComponent implements OnInit { + private friendsService = inject(FriendsService); + private loadCtrl = inject(LoadingController); + private toastCtrl = inject(ToastController); + + friends = signal([]); + + posts = input.required(); + postsFriends = signal([]); + + async ngOnInit() { + const loading = await this.loadCtrl.create({ + message: 'Chargement...', + spinner: 'lines-sharp-small' + }); + await loading.present(); + + try { + const friends = await firstValueFrom(this.friendsService.getAllFriendsEndpoint()); + this.friends.set(friends); + this.postsFriends.set(this.posts().filter(post => this.friends().map(x => x.friendId).includes(post.userId))); + } catch { + const toast = await this.toastCtrl.create({ + message: 'Erreur lors du chargement des amis.', + duration: 2000, + color: 'danger' + }); + await toast.present(); + } + await loading.dismiss(); + } +} diff --git a/src/app/pages/publication/publication.component.html b/src/app/pages/publication/publication.component.html index f4ccc9a..c06b6ad 100644 --- a/src/app/pages/publication/publication.component.html +++ b/src/app/pages/publication/publication.component.html @@ -5,4 +5,5 @@ + diff --git a/src/app/pages/publication/publication.component.ts b/src/app/pages/publication/publication.component.ts index 5a0ce92..7a74d0f 100644 --- a/src/app/pages/publication/publication.component.ts +++ b/src/app/pages/publication/publication.component.ts @@ -1,13 +1,43 @@ -import {Component} from '@angular/core'; -import {IonicModule} from "@ionic/angular"; +import {Component, inject, signal} from '@angular/core'; +import {IonicModule, LoadingController, ToastController} from "@ionic/angular"; +import {GetPostDto, PostsService} from "../../services/api"; +import {firstValueFrom} from "rxjs"; +import {PostComponent} from "../../components/post/post.component"; @Component({ selector: 'app-publication', templateUrl: './publication.component.html', styleUrls: ['./publication.component.scss'], imports: [ - IonicModule + IonicModule, + PostComponent ] }) export class PublicationComponent { + private postsService = inject(PostsService); + private loadCtrl = inject(LoadingController); + private toastCtrl = inject(ToastController); + + posts = signal([]); + + async ionViewWillEnter() { + const loading = await this.loadCtrl.create({ + message: 'Chargement...', + spinner: 'lines-sharp-small' + }); + await loading.present(); + + try { + const posts = await firstValueFrom(this.postsService.getAllPostsEndpoint()); + this.posts.set(posts); + } catch { + const toast = await this.toastCtrl.create({ + message: 'Impossible de charger les publications.', + duration: 2000, + color: 'danger' + }); + await toast.present(); + } + await loading.dismiss(); + } } diff --git a/src/app/services/api/api/messages.service.ts b/src/app/services/api/api/messages.service.ts index bb14d82..cea16f6 100644 --- a/src/app/services/api/api/messages.service.ts +++ b/src/app/services/api/api/messages.service.ts @@ -39,67 +39,6 @@ export class MessagesService extends BaseService { super(basePath, configuration); } - /** - * @endpoint delete /API/Messages/{id}/Groups/{groupId} - * @param id - * @param groupId - * @param observe set whether or not to return the data Observable as the body, response or events. defaults to returning the body. - * @param reportProgress flag to report request and response progress. - * @param options additional options - */ - public deleteMessageEndpoint(id: number, groupId: number, observe?: 'body', reportProgress?: boolean, options?: {httpHeaderAccept?: undefined, context?: HttpContext, transferCache?: boolean}): Observable; - public deleteMessageEndpoint(id: number, groupId: number, observe?: 'response', reportProgress?: boolean, options?: {httpHeaderAccept?: undefined, context?: HttpContext, transferCache?: boolean}): Observable>; - public deleteMessageEndpoint(id: number, groupId: number, observe?: 'events', reportProgress?: boolean, options?: {httpHeaderAccept?: undefined, context?: HttpContext, transferCache?: boolean}): Observable>; - public deleteMessageEndpoint(id: number, groupId: number, observe: any = 'body', reportProgress: boolean = false, options?: {httpHeaderAccept?: undefined, context?: HttpContext, transferCache?: boolean}): Observable { - if (id === null || id === undefined) { - throw new Error('Required parameter id was null or undefined when calling deleteMessageEndpoint.'); - } - if (groupId === null || groupId === undefined) { - throw new Error('Required parameter groupId was null or undefined when calling deleteMessageEndpoint.'); - } - - let localVarHeaders = this.defaultHeaders; - - // authentication (JWTBearerAuth) required - localVarHeaders = this.configuration.addCredentialToHeaders('JWTBearerAuth', 'Authorization', localVarHeaders, 'Bearer '); - - const localVarHttpHeaderAcceptSelected: string | undefined = options?.httpHeaderAccept ?? this.configuration.selectHeaderAccept([ - ]); - if (localVarHttpHeaderAcceptSelected !== undefined) { - localVarHeaders = localVarHeaders.set('Accept', localVarHttpHeaderAcceptSelected); - } - - const localVarHttpContext: HttpContext = options?.context ?? new HttpContext(); - - const localVarTransferCache: boolean = options?.transferCache ?? true; - - - let responseType_: 'text' | 'json' | 'blob' = 'json'; - if (localVarHttpHeaderAcceptSelected) { - if (localVarHttpHeaderAcceptSelected.startsWith('text')) { - responseType_ = 'text'; - } else if (this.configuration.isJsonMime(localVarHttpHeaderAcceptSelected)) { - responseType_ = 'json'; - } else { - responseType_ = 'blob'; - } - } - - let localVarPath = `/API/Messages/${this.configuration.encodeParam({name: "id", value: id, in: "path", style: "simple", explode: false, dataType: "number", dataFormat: "int32"})}/Groups/${this.configuration.encodeParam({name: "groupId", value: groupId, in: "path", style: "simple", explode: false, dataType: "number", dataFormat: "int32"})}`; - const { basePath, withCredentials } = this.configuration; - return this.httpClient.request('delete', `${basePath}${localVarPath}`, - { - context: localVarHttpContext, - responseType: responseType_, - ...(withCredentials ? { withCredentials } : {}), - headers: localVarHeaders, - observe: observe, - ...(localVarTransferCache !== undefined ? { transferCache: localVarTransferCache } : {}), - reportProgress: reportProgress - } - ); - } - /** * @endpoint get /API/Messages/Groups/{groupId} * @param groupId diff --git a/src/app/services/api/api/randomchallenges.service.ts b/src/app/services/api/api/randomchallenges.service.ts index 71de7c7..e86bbb0 100644 --- a/src/app/services/api/api/randomchallenges.service.ts +++ b/src/app/services/api/api/randomchallenges.service.ts @@ -150,16 +150,15 @@ export class RandomchallengesService extends BaseService { /** * @endpoint patch /API/RandomChallenges/{randomChallengeId}/Proof * @param randomChallengeId - * @param libelle * @param proof * @param observe set whether or not to return the data Observable as the body, response or events. defaults to returning the body. * @param reportProgress flag to report request and response progress. * @param options additional options */ - public patchProofEndpoint(randomChallengeId: number, libelle?: string, proof?: Blob, observe?: 'body', reportProgress?: boolean, options?: {httpHeaderAccept?: undefined, context?: HttpContext, transferCache?: boolean}): Observable; - public patchProofEndpoint(randomChallengeId: number, libelle?: string, proof?: Blob, observe?: 'response', reportProgress?: boolean, options?: {httpHeaderAccept?: undefined, context?: HttpContext, transferCache?: boolean}): Observable>; - public patchProofEndpoint(randomChallengeId: number, libelle?: string, proof?: Blob, observe?: 'events', reportProgress?: boolean, options?: {httpHeaderAccept?: undefined, context?: HttpContext, transferCache?: boolean}): Observable>; - public patchProofEndpoint(randomChallengeId: number, libelle?: string, proof?: Blob, observe: any = 'body', reportProgress: boolean = false, options?: {httpHeaderAccept?: undefined, context?: HttpContext, transferCache?: boolean}): Observable { + public patchProofEndpoint(randomChallengeId: number, proof?: Blob, observe?: 'body', reportProgress?: boolean, options?: {httpHeaderAccept?: undefined, context?: HttpContext, transferCache?: boolean}): Observable; + public patchProofEndpoint(randomChallengeId: number, proof?: Blob, observe?: 'response', reportProgress?: boolean, options?: {httpHeaderAccept?: undefined, context?: HttpContext, transferCache?: boolean}): Observable>; + public patchProofEndpoint(randomChallengeId: number, proof?: Blob, observe?: 'events', reportProgress?: boolean, options?: {httpHeaderAccept?: undefined, context?: HttpContext, transferCache?: boolean}): Observable>; + public patchProofEndpoint(randomChallengeId: number, proof?: Blob, observe: any = 'body', reportProgress: boolean = false, options?: {httpHeaderAccept?: undefined, context?: HttpContext, transferCache?: boolean}): Observable { if (randomChallengeId === null || randomChallengeId === undefined) { throw new Error('Required parameter randomChallengeId was null or undefined when calling patchProofEndpoint.'); } @@ -198,9 +197,6 @@ export class RandomchallengesService extends BaseService { localVarFormParams = new HttpParams({encoder: this.encoder}); } - if (libelle !== undefined) { - localVarFormParams = localVarFormParams.append('libelle', libelle) as any || localVarFormParams; - } if (proof !== undefined) { localVarFormParams = localVarFormParams.append('proof', proof) as any || localVarFormParams; } diff --git a/src/app/services/api/model/get-post-dto.ts b/src/app/services/api/model/get-post-dto.ts index d314b4a..e0af290 100644 --- a/src/app/services/api/model/get-post-dto.ts +++ b/src/app/services/api/model/get-post-dto.ts @@ -15,6 +15,7 @@ export interface GetPostDto { creationDate?: string; likes?: number; isLiked?: boolean; + proof?: string | null; userId?: number; username?: string | null; }