diff --git a/WebApp12Angular/src/app/advertisement/advertisement-single.component.html b/WebApp12Angular/src/app/advertisement/advertisement-single.component.html
index ef864b8..bfd82b1 100644
--- a/WebApp12Angular/src/app/advertisement/advertisement-single.component.html
+++ b/WebApp12Angular/src/app/advertisement/advertisement-single.component.html
@@ -13,6 +13,7 @@
-
+
-
-
-
{{comment}}
-
+
+
+
{{comment.author}}
+
{{comment.message}}
+
+
+
\ No newline at end of file
diff --git a/WebApp12Angular/src/app/comment.component.ts b/WebApp12Angular/src/app/comment.component.ts
index 0b3ba69..5f9d933 100644
--- a/WebApp12Angular/src/app/comment.component.ts
+++ b/WebApp12Angular/src/app/comment.component.ts
@@ -11,14 +11,17 @@ import {Comment} from './entity/comment';
})
export class commentComponent {
-
- comment : Comment;
+
+ comments : Comment[] = [];
message= "";
postComment=[];
isLogged : boolean= false;
+ id: number;
+ activatedRoute: ActivatedRoute
constructor(private router: Router, activatedRoute: ActivatedRoute, private commentService: CommentService) {
let id = activatedRoute.snapshot.params['id'];
+ this.id =id;
this.getComments(id);
}
@@ -36,12 +39,29 @@ export class commentComponent {
}
getComments(id: number){
- this.commentService.getComment(id).subscribe(
- comment => this.comment = comment,
- error => console.log(error)
+ this.commentService.getComments(id,0,50).subscribe(
+ comment => this.comments = comment,
+ error => console.log(error)
);
}
+ uploadComment(id: number){
+ let author= localStorage.getItem('name');
+ console.log("message= "+ this.message);
+ console.log("postcomment="+ this.postComment);
+ let comment = new Comment(author, this.message)
+ console.log(comment);
+ this.commentService.uploadComment(this.id, comment).subscribe(
+ () => this.router.navigate(['/advertisement',this.id]),
+ error => console.log(error)
+ );
+ }
+ deleteComment(idComment: number) {
+ this.commentService.deleteComment(this.id,idComment).subscribe(
+ () => window.location.reload(),
+ error => console.log(error)
+ );
+ }
}
\ No newline at end of file
diff --git a/WebApp12Angular/src/app/service/comment.service.ts b/WebApp12Angular/src/app/service/comment.service.ts
index 79e887d..0b26ad3 100644
--- a/WebApp12Angular/src/app/service/comment.service.ts
+++ b/WebApp12Angular/src/app/service/comment.service.ts
@@ -1,5 +1,5 @@
import { Injectable } from '@angular/core';
-import { HttpClient, HttpHeaders, HttpEvent } from '@angular/common/http';
+import { HttpClient, HttpHeaders, HttpEvent, HttpRequest } from '@angular/common/http';
import { Observable } from 'rxjs';
import { catchError, map } from 'rxjs/operators';
import { Comment } from '../entity/comment';
@@ -18,32 +18,41 @@ export class CommentService{
return Observable.throw('Server error (' + error.status + '): ' + error);
}
- getComment(id: number): Observable
{
- return this.http.get(this.urlEndPoint + id +'/comments' )
+ getComments(id: number,page: number, quantity: number): Observable{
+ return this.http.get(this.urlEndPoint + id +'/comments'+ "?page="+page+"&number="+quantity)
.pipe(
map(response => response),
catchError(error => this.handleError(error))
);
}
- uploadComment(comment: Comment): Observable>{
+ uploadComment(id: number,comment: Comment): Observable>{
const body = JSON.stringify(comment);
+ console.log(body);
let formData = new FormData();
formData.append("author", comment.author);
formData.append("message",comment.message);
- return
+ const headers = new HttpHeaders({
+ 'Content-Type': 'application/json',
+ });
+ const req = new HttpRequest('POST', this.urlEndPoint+id+"/comments", body, {headers,
+ reportProgress: true
+ });
+
+ return this.http.request(req);
}
+
editComment(comment: Comment){
return this.http.put(this.urlEndPoint + comment.id, comment)
.pipe(
catchError(error => this.handleError(error))
);
}
- deleteComment(id: number){
- return this.http.delete(this.urlEndPoint +id)
+ deleteComment(id: number, idComment: number){
+ return this.http.delete(this.urlEndPoint +id + "/comments/"+ idComment)
.pipe(
catchError(err =>this.handleError(err))
);
}
-}
+}
\ No newline at end of file
diff --git a/daw.webapp12/src/main/java/com/daw/webapp12/security/SecurityApiRest.java b/daw.webapp12/src/main/java/com/daw/webapp12/security/SecurityApiRest.java
index ddf974a..10e7c4a 100644
--- a/daw.webapp12/src/main/java/com/daw/webapp12/security/SecurityApiRest.java
+++ b/daw.webapp12/src/main/java/com/daw/webapp12/security/SecurityApiRest.java
@@ -39,7 +39,7 @@ protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests().antMatchers(HttpMethod.GET, "/api/advertisements/").permitAll();
http.authorizeRequests().antMatchers(HttpMethod.POST, "/api/advertisements/new").hasAnyRole("USER");
http.authorizeRequests().antMatchers(HttpMethod.GET, "/api/advertisements/{id}/comments").permitAll();
- http.authorizeRequests().antMatchers(HttpMethod.POST, "/api/advertisements/{id}/comments").hasAnyRole("USER");
+ http.authorizeRequests().antMatchers(HttpMethod.POST, "/api/advertisements/{id}/comments").hasAnyRole("USER","ADMIN");
http.authorizeRequests().antMatchers(HttpMethod.DELETE, "/api/advertisements/{id}/comments/{id}").hasAnyRole("USER","ADMIN");