Skip to content

Commit

Permalink
Update endpoint. (#381)
Browse files Browse the repository at this point in the history
* Done

* Edit userId -> author-id
  • Loading branch information
IliaWithHat authored Sep 4, 2024
1 parent d29733b commit 9d62e54
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 16 deletions.
11 changes: 6 additions & 5 deletions service-api/src/main/java/greencity/client/RestClient.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -65,12 +65,12 @@ public String uploadImage(MultipartFile image) {
headers.setContentType(MediaType.MULTIPART_FORM_DATA);
HttpEntity<LinkedMultiValueMap<String, Object>> 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);
}

/**
Expand Down Expand Up @@ -110,8 +110,9 @@ public SocialNetworkImageVO getSocialNetworkImageByUrl(String url) {
*/
public Long findAmountOfPublishedNews(Long userId) {
HttpEntity<String> 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();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
13 changes: 7 additions & 6 deletions service-api/src/test/java/greencity/client/RestClientTest.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -91,17 +91,17 @@ public String getFilename() {
}
};
LinkedMultiValueMap<String, Object> map = new LinkedMultiValueMap<>();
map.add(IMAGE, fileAsResource);
map.add(FILES, fileAsResource);
HttpEntity<LinkedMultiValueMap<String, Object>> 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);
}

Expand Down Expand Up @@ -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));
}
Expand Down
3 changes: 1 addition & 2 deletions service/src/main/java/greencity/service/UserServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down

0 comments on commit 9d62e54

Please sign in to comment.