Skip to content

Commit

Permalink
proxy ready, message request ready
Browse files Browse the repository at this point in the history
  • Loading branch information
clementolive committed Jul 8, 2023
1 parent 2c6dba0 commit 2de80d0
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 8 deletions.
4 changes: 4 additions & 0 deletions frontend/angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
5 changes: 4 additions & 1 deletion frontend/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand All @@ -16,7 +17,9 @@ import { HTTP_INTERCEPTORS, HttpClientModule } from '@angular/common/http';
imports: [
BrowserModule,
AppRoutingModule,
HttpClientModule
HttpClientModule,
ReactiveFormsModule,
FormsModule
],
providers: [],
bootstrap: [AppComponent]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,25 @@ <h3>Service Client</h3>
<div class="card-body">
<p class="card-title h4">Chat service client</p>

<div *ngFor="let post of posts$ | async" class="col-12 col-md-6 col-lg-6">
<span class="d-flex col-4 mb-3 m-1">
<div class="m-2">{{post.createdAt | date: 'dd/MM/yyyy'}}</div>
<div class="m-2">{{post.author}}</div>
</span>
<p class="card-text">{{post.content}}</p>
<!-- Messages list-->
<div *ngFor="let post of posts$ | async" class="card-body bg-info col-12 col-md-6 col-lg-6">
<span class="d-flex col-4 mb-3 m-1">
<div class="m-2">{{post.createdAt | date: 'dd/MM/yyyy'}}</div>
<div class="m-2">{{post.author}}</div>
</span>
<p class="card-text">{{post.content}}</p>

</div>

<!-- Send message form -->
<form class="form-signin d-flex align-items-center flex-column text-center mt-3" [formGroup]="form" (ngSubmit)="submit()">

<textarea class="form-control" id="inputDescription" rows="10" placeholder="Contenu du message" formControlName="content">
</textarea>

<button class="btn btn-md btn-primary btn-block" type="submit" [disabled] = "form.invalid">Envoyer</button>
</form>

</div>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -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({
Expand All @@ -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<Message[]> = 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();
}
}
4 changes: 4 additions & 0 deletions frontend/src/app/payload/messageRequest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export interface MessageRequest {
content: String;
author: String;
}
5 changes: 5 additions & 0 deletions frontend/src/app/service/message.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -14,4 +15,8 @@ export class MessageService {
public getMessages(): Observable<Message[]> {
return this.httpClient.get<Message[]>(this.pathService);
}

public sendMessage(request: MessageRequest): Observable<Response> {
return this.httpClient.post<Response>(this.pathService, request);
}
}
6 changes: 6 additions & 0 deletions frontend/src/proxy.conf.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"/api/*": {
"target": "http://localhost:8080",
"secure": false
}
}

0 comments on commit 2de80d0

Please sign in to comment.