Repository: ita-social-projects/greencity
Issue: [API][Add a comment]Adding a comment to an existing event 

**Environment:** All.
**Reproducible:** always.
**Build found:** 23.10.2022

**Preconditions**
1.Open Postman.
2.The user is authorised.
3.Event added

**Steps to reproduce**
1. Apply the POST method by using request URL https://greencity.testgreencity.ga/events/comments/{eventId}
2.Fill the request "body"e.g.
{
"text": "string"
}
3. Perform the request.

**Actual result**
Status Code : 500 Internal Server Error

**Expected result**

Status Code : 201 Created
"body" is :
{
  "text": "string"
}


**User story and test case links**
"User story #3208"

**Labels to be added**
"Bug", Priority ("Medium"), Severity ("Medium"), Type ("Functional"), "API" (for back-end bugs).


Changed files:
service-api/src/main/java/greencity/client/RestClient.java, service/src/test/java/greencity/service/EventCommentServiceImplTest.java, service-api/src/test/java/greencity/client/RestClientTest.java, core/src/main/java/greencity/controller/EventCommentController.java, service/src/main/java/greencity/service/EventCommentServiceImpl.java

diff --git a/core/src/main/java/greencity/controller/EventCommentController.java b/core/src/main/java/greencity/controller/EventCommentController.java
index 966639acd..f35963543 100644
--- a/core/src/main/java/greencity/controller/EventCommentController.java
+++ b/core/src/main/java/greencity/controller/EventCommentController.java
@@ -47,7 +47,7 @@ public class EventCommentController {
         @ApiResponse(code = 401, message = HttpStatuses.UNAUTHORIZED),
         @ApiResponse(code = 404, message = HttpStatuses.NOT_FOUND),
     })
-    @PostMapping("{eventId}")
+    @PostMapping("/{eventId}")
     public ResponseEntity<AddEventCommentDtoResponse> save(@PathVariable Long eventId,
         @Valid @RequestBody AddEventCommentDtoRequest request,
         @ApiIgnore @CurrentUser UserVO user) {
diff --git a/service-api/src/main/java/greencity/client/RestClient.java b/service-api/src/main/java/greencity/client/RestClient.java
index ff0236948..a8f0850b4 100644
--- a/service-api/src/main/java/greencity/client/RestClient.java
+++ b/service-api/src/main/java/greencity/client/RestClient.java
@@ -379,7 +379,7 @@ public class RestClient {
      * @author Inna Yashna
      */
     public void sendNewEventComment(EventCommentForSendEmailDto message) {
-        HttpHeaders headers = new HttpHeaders();
+        HttpHeaders headers = setHeader();
         headers.setContentType(MediaType.APPLICATION_JSON);
         HttpEntity<EventCommentForSendEmailDto> entity = new HttpEntity<>(message, headers);
         restTemplate.exchange(greenCityUserServerAddress
diff --git a/service-api/src/test/java/greencity/client/RestClientTest.java b/service-api/src/test/java/greencity/client/RestClientTest.java
index 4f2ced9b2..1b553944a 100644
--- a/service-api/src/test/java/greencity/client/RestClientTest.java
+++ b/service-api/src/test/java/greencity/client/RestClientTest.java
@@ -337,8 +337,11 @@ class RestClientTest {
     void sendNewEventComment() {
         EventCommentForSendEmailDto message = ModelUtils.getEventCommentForSendEmailDto();
         HttpHeaders httpHeaders = new HttpHeaders();
+        String accessToken = "accessToken";
         httpHeaders.setContentType(MediaType.APPLICATION_JSON);
+        httpHeaders.set(AUTHORIZATION, accessToken);
         HttpEntity<EventCommentForSendEmailDto> entity = new HttpEntity<>(message, httpHeaders);
+        when(httpServletRequest.getHeader(AUTHORIZATION)).thenReturn(accessToken);
         when(restTemplate.exchange(greenCityUserServerAddress
             + RestTemplateLinks.ADD_EVENT_COMMENT, HttpMethod.POST, entity, Object.class))
                 .thenReturn(ResponseEntity.ok(Object));
diff --git a/service/src/main/java/greencity/service/EventCommentServiceImpl.java b/service/src/main/java/greencity/service/EventCommentServiceImpl.java
index 8bb8a050c..207fdb17e 100644
--- a/service/src/main/java/greencity/service/EventCommentServiceImpl.java
+++ b/service/src/main/java/greencity/service/EventCommentServiceImpl.java
@@ -5,10 +5,7 @@ import greencity.constant.ErrorMessage;
 import greencity.dto.PageableDto;
 import greencity.dto.event.EventAuthorDto;
 import greencity.dto.event.EventVO;
-import greencity.dto.eventcomment.AddEventCommentDtoRequest;
-import greencity.dto.eventcomment.AddEventCommentDtoResponse;
-import greencity.dto.eventcomment.EventCommentDto;
-import greencity.dto.eventcomment.EventCommentForSendEmailDto;
+import greencity.dto.eventcomment.*;
 import greencity.dto.user.UserVO;
 import greencity.entity.User;
 import greencity.entity.event.Event;
@@ -58,6 +55,7 @@ public class EventCommentServiceImpl implements EventCommentService {
         eventComment.setEvent(modelMapper.map(eventVO, Event.class));
         AddEventCommentDtoResponse addEventCommentDtoResponse = modelMapper.map(
             eventCommentRepo.save(eventComment), AddEventCommentDtoResponse.class);
+        addEventCommentDtoResponse.setAuthor(modelMapper.map(userVO, EventCommentAuthorDto.class));
         sendEmailDto(addEventCommentDtoResponse);
         return addEventCommentDtoResponse;
     }
diff --git a/service/src/test/java/greencity/service/EventCommentServiceImplTest.java b/service/src/test/java/greencity/service/EventCommentServiceImplTest.java
index 673a69259..b81d83988 100644
--- a/service/src/test/java/greencity/service/EventCommentServiceImplTest.java
+++ b/service/src/test/java/greencity/service/EventCommentServiceImplTest.java
@@ -8,6 +8,7 @@ import greencity.dto.event.EventAuthorDto;
 import greencity.dto.event.EventVO;
 import greencity.dto.eventcomment.AddEventCommentDtoRequest;
 import greencity.dto.eventcomment.AddEventCommentDtoResponse;
+import greencity.dto.eventcomment.EventCommentAuthorDto;
 import greencity.dto.eventcomment.EventCommentDto;
 import greencity.dto.user.UserVO;
 import greencity.entity.User;
@@ -68,10 +69,12 @@ class EventCommentServiceImplTest {
         AddEventCommentDtoRequest addEventCommentDtoRequest = ModelUtils.getAddEventCommentDtoRequest();
         EventComment eventComment = ModelUtils.getEventComment();
         EventAuthorDto eventAuthorDto = ModelUtils.getEventAuthorDto();
+        EventCommentAuthorDto eventCommentAuthorDto = ModelUtils.getEventCommentAuthorDto();
 
         when(eventService.findById(anyLong())).thenReturn(eventVO);
         when(eventCommentRepo.save(any(EventComment.class))).then(AdditionalAnswers.returnsFirstArg());
         when(eventCommentRepo.findById(anyLong())).thenReturn(Optional.of(eventComment));
+        when(modelMapper.map(userVO, EventCommentAuthorDto.class)).thenReturn(eventCommentAuthorDto);
         when(modelMapper.map(user, EventAuthorDto.class)).thenReturn(eventAuthorDto);
         when(modelMapper.map(userVO, User.class)).thenReturn(user);
         when(modelMapper.map(eventVO, Event.class)).thenReturn(event);