From 9d62e542f0669e6d44fc186f6e959117ac8c13aa Mon Sep 17 00:00:00 2001 From: IliaWithHat <146325650+IliaWithHat@users.noreply.github.com> Date: Wed, 4 Sep 2024 18:05:15 +0300 Subject: [PATCH] Update endpoint. (#381) * Done * Edit userId -> author-id --- .../src/main/java/greencity/client/RestClient.java | 11 ++++++----- .../main/java/greencity/constant/AppConstant.java | 2 +- .../java/greencity/constant/RestTemplateLinks.java | 5 +++-- .../test/java/greencity/client/RestClientTest.java | 13 +++++++------ .../java/greencity/service/UserServiceImpl.java | 3 +-- 5 files changed, 18 insertions(+), 16 deletions(-) diff --git a/service-api/src/main/java/greencity/client/RestClient.java b/service-api/src/main/java/greencity/client/RestClient.java index c01fb4773..10d7b2c21 100644 --- a/service-api/src/main/java/greencity/client/RestClient.java +++ b/service-api/src/main/java/greencity/client/RestClient.java @@ -1,7 +1,7 @@ package greencity.client; import static greencity.constant.AppConstant.AUTHORIZATION; -import static greencity.constant.AppConstant.IMAGE; +import static greencity.constant.AppConstant.FILES; import greencity.constant.RestTemplateLinks; import greencity.dto.friends.FriendsChatDto; import greencity.dto.shoppinglist.CustomShoppingListItemResponseDto; @@ -65,12 +65,12 @@ public String uploadImage(MultipartFile image) { headers.setContentType(MediaType.MULTIPART_FORM_DATA); HttpEntity> requestEntity = new HttpEntity<>(map, headers); try { - map.add(IMAGE, convert(image)); + map.add(FILES, convert(image)); } catch (IOException e) { log.info("File did not convert to ByteArrayResource"); } return restTemplate.postForObject(greenCityServerAddress - + RestTemplateLinks.FILES_IMAGE, requestEntity, String.class); + + RestTemplateLinks.FILES, requestEntity, String.class); } /** @@ -110,8 +110,9 @@ public SocialNetworkImageVO getSocialNetworkImageByUrl(String url) { */ public Long findAmountOfPublishedNews(Long userId) { HttpEntity entity = new HttpEntity<>(setHeader()); - return restTemplate.exchange(greenCityServerAddress - + RestTemplateLinks.ECONEWS_COUNT + RestTemplateLinks.USER_ID + userId, HttpMethod.GET, entity, Long.class) + return restTemplate.exchange( + greenCityServerAddress + RestTemplateLinks.ECO_NEWS_COUNT + RestTemplateLinks.AUTHOR_ID + userId, + HttpMethod.GET, entity, Long.class) .getBody(); } diff --git a/service-api/src/main/java/greencity/constant/AppConstant.java b/service-api/src/main/java/greencity/constant/AppConstant.java index 048cae786..a0c80cfcf 100644 --- a/service-api/src/main/java/greencity/constant/AppConstant.java +++ b/service-api/src/main/java/greencity/constant/AppConstant.java @@ -24,7 +24,7 @@ public class AppConstant { public static final Double DEFAULT_RATING = 0.0; public static final String USERNAME = "name"; public static final String FACEBOOK_OBJECT_ID = "me"; - public static final String IMAGE = "image"; + public static final String FILES = "files"; public static final String DEFAULT_LANGUAGE_CODE = "en"; public static final String PASSWORD = "password"; public static final String USER_STATUS = "user_status"; diff --git a/service-api/src/main/java/greencity/constant/RestTemplateLinks.java b/service-api/src/main/java/greencity/constant/RestTemplateLinks.java index 844a5d024..f9d19160a 100644 --- a/service-api/src/main/java/greencity/constant/RestTemplateLinks.java +++ b/service-api/src/main/java/greencity/constant/RestTemplateLinks.java @@ -5,15 +5,16 @@ @UtilityClass public class RestTemplateLinks { public static final String CUSTOM_SHOPPING_LIST_ITEMS = "/custom/shopping-list-items/"; - public static final String FILES_IMAGE = "/files/image"; + public static final String FILES = "/files"; public static final String SOCIAL_NETWORKS_IMAGE = "/social-networks/image"; public static final String SOCIAL_NETWORKS = "/social-networks"; public static final String LANGUAGE = "/language"; - public static final String ECONEWS_COUNT = "/econews/count"; + public static final String ECO_NEWS_COUNT = "/eco-news/count"; public static final String HABIT_STATISTIC_ACQUIRED_COUNT = "/habit/statistic/acquired/count"; public static final String HABIT_STATISTIC_IN_PROGRESS_COUNT = "/habit/statistic/in-progress/count"; public static final String ID = "?id="; public static final String USER_ID = "?userId="; + public static final String AUTHOR_ID = "?author-id="; public static final String URL = "?url="; public static final String UBS_USER_PROFILE = "/ubs/userProfile"; public static final String EVENTS_ORGANIZED_OR_ATTENDED_BY_USER_COUNT = "/events/userEvents/count"; diff --git a/service-api/src/test/java/greencity/client/RestClientTest.java b/service-api/src/test/java/greencity/client/RestClientTest.java index 7eae2b27b..72ad711fa 100644 --- a/service-api/src/test/java/greencity/client/RestClientTest.java +++ b/service-api/src/test/java/greencity/client/RestClientTest.java @@ -1,7 +1,7 @@ package greencity.client; import static greencity.constant.AppConstant.AUTHORIZATION; -import static greencity.constant.AppConstant.IMAGE; +import static greencity.constant.AppConstant.FILES; import greencity.constant.RestTemplateLinks; import greencity.dto.friends.FriendsChatDto; import greencity.dto.shoppinglist.CustomShoppingListItemResponseDto; @@ -91,17 +91,17 @@ public String getFilename() { } }; LinkedMultiValueMap map = new LinkedMultiValueMap<>(); - map.add(IMAGE, fileAsResource); + map.add(FILES, fileAsResource); HttpEntity> requestEntity = new HttpEntity<>(map, headers); when(httpServletRequest.getHeader(AUTHORIZATION)).thenReturn(accessToken); when(restTemplate.postForObject(greenCityServerAddress + - RestTemplateLinks.FILES_IMAGE, requestEntity, + RestTemplateLinks.FILES, requestEntity, String.class)).thenReturn(imagePath); assertEquals(imagePath, restClient.uploadImage(image)); verify(httpServletRequest).getHeader(any()); verify(restTemplate).postForObject(greenCityServerAddress + - RestTemplateLinks.FILES_IMAGE, requestEntity, + RestTemplateLinks.FILES, requestEntity, String.class); } @@ -146,8 +146,9 @@ void findAmountOfPublishedNews() { Long publishedNews = 5L; Long userId = 1L; when(httpServletRequest.getHeader(AUTHORIZATION)).thenReturn(accessToken); - when(restTemplate.exchange(greenCityServerAddress - + RestTemplateLinks.ECONEWS_COUNT + RestTemplateLinks.USER_ID + userId, HttpMethod.GET, entity, Long.class)) + when(restTemplate.exchange( + greenCityServerAddress + RestTemplateLinks.ECO_NEWS_COUNT + RestTemplateLinks.AUTHOR_ID + userId, + HttpMethod.GET, entity, Long.class)) .thenReturn(ResponseEntity.ok(publishedNews)); assertEquals(publishedNews, restClient.findAmountOfPublishedNews(userId)); } diff --git a/service/src/main/java/greencity/service/UserServiceImpl.java b/service/src/main/java/greencity/service/UserServiceImpl.java index b0cfa6c8b..33b6a0074 100644 --- a/service/src/main/java/greencity/service/UserServiceImpl.java +++ b/service/src/main/java/greencity/service/UserServiceImpl.java @@ -525,8 +525,7 @@ public long getActivatedUsersAmount() { * @author Marian Datsko */ @Override - public UserVO updateUserProfilePicture(MultipartFile image, String email, - String base64) { + public UserVO updateUserProfilePicture(MultipartFile image, String email, String base64) { User user = userRepo .findByEmail(email) .orElseThrow(() -> new WrongEmailException(ErrorMessage.USER_NOT_FOUND_BY_EMAIL + email));