Link work dans l'url + fonc get workbylink et getlinklastworkbyiduser
continuous-integration/drone/push Build is passing Details

(à faire côté serv)
pull/15/head
Matis MAZINGUE 11 months ago
parent dfaf146cd5
commit 8518c75b36

@ -9,9 +9,10 @@ import { TranslationService } from '../../services/translation.service';
import { ThemeService } from '../../services/theme.service';
import { TranslateModule } from '@ngx-translate/core';
import { ReactiveFormsModule } from '@angular/forms';
import { RouterLink, RouterLinkActive } from '@angular/router';
import { Router, RouterLink, RouterLinkActive } from '@angular/router';
import { NgClass, NgOptimizedImage } from '@angular/common';
import { WorkService } from '../../services/work.service';
import { Observable } from 'rxjs';
@Component({
selector: 'app-header',
@ -32,12 +33,18 @@ export class HeaderComponent {
version: string = '1.0';
isMenuOpen: boolean = false;
isCheck: boolean = false;
linkLastWork: string = this.workService.getIdLastWorkByUserId("");
@ViewChild('menuRef') menuRef!: ElementRef;
@Input() themeClass!: string;
@Input() themeService!: ThemeService;
// Instanciation du service pour les actions de traduction
constructor(private translationService: TranslationService, private workService: WorkService) { }
constructor(
private router: Router,
private translationService: TranslationService,
private workService: WorkService)
{ }
// Méthode pour changer la langue
onLanguageChange(event: Event) {
@ -65,8 +72,9 @@ export class HeaderComponent {
}
}
getLastWorkLink() : string {
return 'work/'.concat(this.workService.getIdLastWorkByUserId(""))
onLastWorkLink() : void {
const url = `/work/${this.linkLastWork}`;
this.router.navigateByUrl(url);
}
}

@ -1,5 +1,5 @@
import { Component, OnInit } from '@angular/core';
import { Router, RouterLink } from '@angular/router';
import { RouterLink, ActivatedRoute } from '@angular/router';
import { ThemeService } from '../../services/theme.service';
import { NgClass } from '@angular/common';
import { TranslateModule } from '@ngx-translate/core';
@ -7,6 +7,7 @@ import {Work} from "../../models/work.model";
import {WorkService} from "../../services/work.service";
import {NgForOf} from "@angular/common";
import {FormsModule, NgForm} from "@angular/forms";
import { Observable } from 'rxjs';
@Component({
selector: 'app-work',
@ -27,9 +28,9 @@ export class WorkComponent implements OnInit {
themeClass!: string;
works: Work[] = [];
workEnCours: Observable<Work> = new Observable();
constructor(
private router: Router,
private route: ActivatedRoute,
private themeService: ThemeService,
protected workService: WorkService
) {}
@ -41,16 +42,13 @@ export class WorkComponent implements OnInit {
: (this.themeClass = 'light-theme');
});
this.workService.getWorks().subscribe((response: Work[]) => this.works = response);
const link = String(this.route.snapshot.paramMap.get('link'));
if (link) {
this.workEnCours = this.workService.getWorkByLink(link);
}
}
// Si click sur "Work", on redirige vers la page des travaux
onContinue(): void {
this.router.navigateByUrl('/work');
}
onSubmit(form: NgForm) {
this.workService.postWork(form);
this.workService.postWork(form);
}
}

@ -20,6 +20,16 @@ export class WorkService {
return this.http.get(`${this.API_URL}/works`);
}
//je veux return un work en fonction d'un link passé en param
getWorkByLink(link: string): Observable<any> {
return this.http.get(`${this.API_URL}/work/${link}`);
}
//je veux return le link du dernier work d'un user (en l'occurence celui connecté)
getLinkLastWorkByIdUser(id_user: string): Observable<any> {
return this.http.get(`${this.API_URL}/work/${id_user}`);
}
postWork(form: NgForm): void {
let body = {link: crypto.randomUUID(), id_user: 1, id_language: 1, code: form.value.content, saveDate: new Date()}
this.http.post<any>(`${this.API_URL}/works`, body).subscribe();

Loading…
Cancel
Save