From 660cb01ea10c2e76230d67dcc892f0deaf672f37 Mon Sep 17 00:00:00 2001 From: Denis Kolovorotnyi Date: Fri, 14 Jul 2023 13:31:52 +0200 Subject: [PATCH] [refactoring]: Changed the getUsersPhotos method --- .../com/rangiffler/service/PhotoService.java | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/rangiffler-gateway/src/main/java/com/rangiffler/service/PhotoService.java b/rangiffler-gateway/src/main/java/com/rangiffler/service/PhotoService.java index 43518b3..904c2dd 100644 --- a/rangiffler-gateway/src/main/java/com/rangiffler/service/PhotoService.java +++ b/rangiffler-gateway/src/main/java/com/rangiffler/service/PhotoService.java @@ -27,15 +27,17 @@ public PhotoJson addPhoto(PhotoJson photoJson) { } public List getAllUserPhotos(String username) { - List usersPhoto = new ArrayList<>(); List photos = photoService.getPhotosForUser(username); - if (!photos.isEmpty()) { - for (PhotoServiceJson photo : photos) { - CountryJson country = countryService.findById(photo.getCountryId()); - usersPhoto.add(PhotoServiceJson.fromPhotoServiceJson(photo, country)); - } + if (photos.isEmpty()) { + return new ArrayList<>(); } - return usersPhoto; + + return photos.stream() + .map(photo -> { + CountryJson country = countryService.findById(photo.getCountryId()); + return PhotoServiceJson.fromPhotoServiceJson(photo, country); + }) + .toList(); } public PhotoJson editPhoto(PhotoJson photoJson, UUID id) {