From 2de80d056c1ffa10fdb292954433576f8f82fb3a Mon Sep 17 00:00:00 2001 From: Achmoye Date: Sat, 8 Jul 2023 17:28:33 +0200 Subject: [PATCH] proxy ready, message request ready --- frontend/angular.json | 4 ++++ frontend/src/app/app.module.ts | 5 +++- .../service-client.component.html | 23 ++++++++++++++----- .../service-client.component.ts | 21 ++++++++++++++++- frontend/src/app/payload/messageRequest.ts | 4 ++++ frontend/src/app/service/message.service.ts | 5 ++++ frontend/src/proxy.conf.json | 6 +++++ 7 files changed, 60 insertions(+), 8 deletions(-) create mode 100644 frontend/src/app/payload/messageRequest.ts create mode 100644 frontend/src/proxy.conf.json diff --git a/frontend/angular.json b/frontend/angular.json index 56f23cf..5cfc8e6 100644 --- a/frontend/angular.json +++ b/frontend/angular.json @@ -63,6 +63,10 @@ }, "serve": { "builder": "@angular-devkit/build-angular:dev-server", + "options": { + "browserTarget": "Proof_Of_Concept:build", + "proxyConfig": "src/proxy.conf.json" + }, "configurations": { "production": { "browserTarget": "frontend:build:production" diff --git a/frontend/src/app/app.module.ts b/frontend/src/app/app.module.ts index 3c2350d..a9211b8 100644 --- a/frontend/src/app/app.module.ts +++ b/frontend/src/app/app.module.ts @@ -6,6 +6,7 @@ import { AppComponent } from './app.component'; import { ServiceClientComponent } from './pages/service-client/service-client.component'; import { NavbarComponent } from './navbar/navbar.component'; import { HTTP_INTERCEPTORS, HttpClientModule } from '@angular/common/http'; +import { FormsModule, ReactiveFormsModule } from '@angular/forms'; @NgModule({ declarations: [ @@ -16,7 +17,9 @@ import { HTTP_INTERCEPTORS, HttpClientModule } from '@angular/common/http'; imports: [ BrowserModule, AppRoutingModule, - HttpClientModule + HttpClientModule, + ReactiveFormsModule, + FormsModule ], providers: [], bootstrap: [AppComponent] diff --git a/frontend/src/app/pages/service-client/service-client.component.html b/frontend/src/app/pages/service-client/service-client.component.html index 7d7345e..f064811 100644 --- a/frontend/src/app/pages/service-client/service-client.component.html +++ b/frontend/src/app/pages/service-client/service-client.component.html @@ -8,14 +8,25 @@

Service Client

Chat service client

-
- -
{{post.createdAt | date: 'dd/MM/yyyy'}}
-
{{post.author}}
-
-

{{post.content}}

+ +
+ +
{{post.createdAt | date: 'dd/MM/yyyy'}}
+
{{post.author}}
+
+

{{post.content}}

+
+ + +
diff --git a/frontend/src/app/pages/service-client/service-client.component.ts b/frontend/src/app/pages/service-client/service-client.component.ts index 8078777..d41edef 100644 --- a/frontend/src/app/pages/service-client/service-client.component.ts +++ b/frontend/src/app/pages/service-client/service-client.component.ts @@ -1,7 +1,9 @@ import { Component } from '@angular/core'; +import { FormBuilder, Validators } from '@angular/forms'; import { Router } from '@angular/router'; import { Observable } from 'rxjs'; import { Message } from 'src/app/interface/message'; +import { MessageRequest } from 'src/app/payload/messageRequest'; import { MessageService } from 'src/app/service/message.service'; @Component({ @@ -11,8 +13,25 @@ import { MessageService } from 'src/app/service/message.service'; }) export class ServiceClientComponent { constructor(private router: Router, - private messageService: MessageService) { } + private messageService: MessageService, + private fb: FormBuilder) { } // This is subscribed in DOM with async public posts$: Observable = this.messageService.getMessages(); + + public form = this.fb.group({ + content: ['', + [ Validators.required,] + ], + author: ['', + [ Validators.required,] + ] + }); + + public submit(): void{ + const request = this.form.value as MessageRequest; + request.author = "Utilisateur"; + //const createpostRequest = this.form.value as Message; + this.messageService.sendMessage(request).subscribe(); + } } diff --git a/frontend/src/app/payload/messageRequest.ts b/frontend/src/app/payload/messageRequest.ts new file mode 100644 index 0000000..0cad6ce --- /dev/null +++ b/frontend/src/app/payload/messageRequest.ts @@ -0,0 +1,4 @@ +export interface MessageRequest { + content: String; + author: String; +} diff --git a/frontend/src/app/service/message.service.ts b/frontend/src/app/service/message.service.ts index 84d6901..ce708a6 100644 --- a/frontend/src/app/service/message.service.ts +++ b/frontend/src/app/service/message.service.ts @@ -2,6 +2,7 @@ import { Injectable } from '@angular/core'; import { Observable } from 'rxjs'; import { Message } from '../interface/message'; import { HttpClient } from '@angular/common/http'; +import { MessageRequest } from '../payload/messageRequest'; @Injectable({ providedIn: 'root' @@ -14,4 +15,8 @@ export class MessageService { public getMessages(): Observable { return this.httpClient.get(this.pathService); } + + public sendMessage(request: MessageRequest): Observable { + return this.httpClient.post(this.pathService, request); + } } diff --git a/frontend/src/proxy.conf.json b/frontend/src/proxy.conf.json new file mode 100644 index 0000000..fc64443 --- /dev/null +++ b/frontend/src/proxy.conf.json @@ -0,0 +1,6 @@ +{ + "/api/*": { + "target": "http://localhost:8080", + "secure": false + } + } \ No newline at end of file