From 3e6aae68d2894e8f19da887e0a6c8ada42f5dc9c Mon Sep 17 00:00:00 2001 From: sanchezvem Date: Sat, 25 Apr 2026 16:12:24 +0100 Subject: [PATCH] Added vue from groups --- .../components/groups/groups.component.html | 31 ++++ .../components/groups/groups.component.scss | 0 src/app/components/groups/groups.component.ts | 53 +++++++ src/app/services/api/api/posts.service.ts | 149 ++++++++++++++++++ src/app/services/api/model/get-post-dto.ts | 21 +++ 5 files changed, 254 insertions(+) create mode 100644 src/app/components/groups/groups.component.html create mode 100644 src/app/components/groups/groups.component.scss create mode 100644 src/app/components/groups/groups.component.ts create mode 100644 src/app/services/api/api/posts.service.ts create mode 100644 src/app/services/api/model/get-post-dto.ts diff --git a/src/app/components/groups/groups.component.html b/src/app/components/groups/groups.component.html new file mode 100644 index 0000000..5433939 --- /dev/null +++ b/src/app/components/groups/groups.component.html @@ -0,0 +1,31 @@ +
+ + @if (groups().length) { + @for (group of groups(); track group.id; let i = $index) { + @if (i == groups().length) { + +

{{ group.label }}

+ +
+ } @else { + +

{{ group.label }}

+ +
+ } + } + } @else { + +
+
+ +
+
+

Pas encore de groupes

+

Vos groupes apparaƮtront ici

+
+
+
+ } +
+
\ No newline at end of file diff --git a/src/app/components/groups/groups.component.scss b/src/app/components/groups/groups.component.scss new file mode 100644 index 0000000..e69de29 diff --git a/src/app/components/groups/groups.component.ts b/src/app/components/groups/groups.component.ts new file mode 100644 index 0000000..0032fac --- /dev/null +++ b/src/app/components/groups/groups.component.ts @@ -0,0 +1,53 @@ +import {Component, inject, OnInit, signal} from '@angular/core'; +import {IonicModule, LoadingController, ToastController} from "@ionic/angular"; +import {GetGroupDto, GroupsService} from "../../services/api"; +import {firstValueFrom} from "rxjs"; +import {addIcons} from "ionicons"; +import {chatbubblesOutline, chevronForwardOutline} from "ionicons/icons"; + +addIcons({ + 'group': chatbubblesOutline, + 'chevron': chevronForwardOutline, +}); + +@Component({ + selector: 'app-groups', + templateUrl: './groups.component.html', + styleUrls: ['./groups.component.scss'], + imports: [ + IonicModule + ] +}) +export class GroupsComponent implements OnInit { + private groupsService = inject(GroupsService); + private toastCtrl = inject(ToastController); + private loadCtrl = inject(LoadingController); + + groups = signal([]); + + async ngOnInit() { + await this.fetchGroups(); + } + + async fetchGroups() { + const loading = await this.loadCtrl.create({ + message: 'Chargement...', + spinner: 'lines-sharp-small' + }); + await loading.present(); + + try { + const groups = await firstValueFrom(this.groupsService.getAllGroupsEndpoint()); + this.groups.set(groups); + } + catch { + const toast = await this.toastCtrl.create({ + message: 'Impossible de charger les groupes du joueur', + duration: 2000, + color: 'danger' + }); + await toast.present(); + } + await loading.dismiss(); + } +} diff --git a/src/app/services/api/api/posts.service.ts b/src/app/services/api/api/posts.service.ts new file mode 100644 index 0000000..ef5a0d5 --- /dev/null +++ b/src/app/services/api/api/posts.service.ts @@ -0,0 +1,149 @@ +/** + * BeReadyBackend + * + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ +/* tslint:disable:no-unused-variable member-ordering */ + +import { Inject, Injectable, Optional } from '@angular/core'; +import { HttpClient, HttpHeaders, HttpParams, + HttpResponse, HttpEvent, HttpContext + } from '@angular/common/http'; +import { Observable } from 'rxjs'; +import { OpenApiHttpParams, QueryParamStyle } from '../query.params'; + +// @ts-ignore +import { GetPostDto } from '../model/get-post-dto'; + +// @ts-ignore +import { BASE_PATH, COLLECTION_FORMATS } from '../variables'; +import { Configuration } from '../configuration'; +import { BaseService } from '../api.base.service'; + + + +@Injectable({ + providedIn: 'root' +}) +export class PostsService extends BaseService { + + constructor(protected httpClient: HttpClient, @Optional() @Inject(BASE_PATH) basePath: string|string[], @Optional() configuration?: Configuration) { + super(basePath, configuration); + } + + /** + * @endpoint get /API/Posts + * @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 getAllPostsEndpoint(observe?: 'body', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean}): Observable>; + public getAllPostsEndpoint(observe?: 'response', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean}): Observable>>; + public getAllPostsEndpoint(observe?: 'events', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean}): Observable>>; + public getAllPostsEndpoint(observe: any = 'body', reportProgress: boolean = false, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean}): Observable { + + let localVarHeaders = this.defaultHeaders; + + // authentication (JWTBearerAuth) required + localVarHeaders = this.configuration.addCredentialToHeaders('JWTBearerAuth', 'Authorization', localVarHeaders, 'Bearer '); + + const localVarHttpHeaderAcceptSelected: string | undefined = options?.httpHeaderAccept ?? this.configuration.selectHeaderAccept([ + 'application/json' + ]); + 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/Posts`; + const { basePath, withCredentials } = this.configuration; + return this.httpClient.request>('get', `${basePath}${localVarPath}`, + { + context: localVarHttpContext, + responseType: responseType_, + ...(withCredentials ? { withCredentials } : {}), + headers: localVarHeaders, + observe: observe, + ...(localVarTransferCache !== undefined ? { transferCache: localVarTransferCache } : {}), + reportProgress: reportProgress + } + ); + } + + /** + * @endpoint patch /API/Posts/{postId}/Like + * @param postId + * @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 patchLikeEndpoint(postId: number, observe?: 'body', reportProgress?: boolean, options?: {httpHeaderAccept?: undefined, context?: HttpContext, transferCache?: boolean}): Observable; + public patchLikeEndpoint(postId: number, observe?: 'response', reportProgress?: boolean, options?: {httpHeaderAccept?: undefined, context?: HttpContext, transferCache?: boolean}): Observable>; + public patchLikeEndpoint(postId: number, observe?: 'events', reportProgress?: boolean, options?: {httpHeaderAccept?: undefined, context?: HttpContext, transferCache?: boolean}): Observable>; + public patchLikeEndpoint(postId: number, observe: any = 'body', reportProgress: boolean = false, options?: {httpHeaderAccept?: undefined, context?: HttpContext, transferCache?: boolean}): Observable { + if (postId === null || postId === undefined) { + throw new Error('Required parameter postId was null or undefined when calling patchLikeEndpoint.'); + } + + 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/Posts/${this.configuration.encodeParam({name: "postId", value: postId, in: "path", style: "simple", explode: false, dataType: "number", dataFormat: "int32"})}/Like`; + const { basePath, withCredentials } = this.configuration; + return this.httpClient.request('patch', `${basePath}${localVarPath}`, + { + context: localVarHttpContext, + responseType: responseType_, + ...(withCredentials ? { withCredentials } : {}), + headers: localVarHeaders, + observe: observe, + ...(localVarTransferCache !== undefined ? { transferCache: localVarTransferCache } : {}), + reportProgress: reportProgress + } + ); + } + +} diff --git a/src/app/services/api/model/get-post-dto.ts b/src/app/services/api/model/get-post-dto.ts new file mode 100644 index 0000000..d314b4a --- /dev/null +++ b/src/app/services/api/model/get-post-dto.ts @@ -0,0 +1,21 @@ +/** + * BeReadyBackend + * + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + + +export interface GetPostDto { + id?: number; + libelle?: string | null; + creationDate?: string; + likes?: number; + isLiked?: boolean; + userId?: number; + username?: string | null; +} +