-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCommentController.java
More file actions
40 lines (34 loc) · 1.46 KB
/
CommentController.java
File metadata and controls
40 lines (34 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package com.ecommerece.userinterface.controllers;
import com.ecommerece.userinterface.external.dtos.CommentDto;
import com.ecommerece.userinterface.external.dtos.GetProductDto;
import com.ecommerece.userinterface.external.dtos.PostProductDto;
import com.ecommerece.userinterface.external.services.ApiResponse;
import feign.FeignException;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;
@Controller
public class CommentController {
private final ApiResponse apiResponse;
public CommentController(ApiResponse apiResponse) {
this.apiResponse = apiResponse;
}
@PostMapping("/products/{productId}")
public String createComment(@PathVariable String productId, @ModelAttribute CommentDto comment){
CommentDto commentDto = new CommentDto();
try {
commentDto = apiResponse.createComment(productId, comment);
}catch (FeignException e){
System.out.println(e.getMessage());
return "redirect:/products/" + productId;
}
return "redirect:/products/" + productId;
}
@DeleteMapping("products/{productId}/comments/{commentId}")
public String deleteComment(@PathVariable String productId,@PathVariable String commentId){
apiResponse.deleteComment(commentId);
return ("redirect:/products/" + productId );
}
}