tags language problem fixed
@@ -94,7 +94,7 @@ public class EcoNewsServiceImpl implements EcoNewsService {
public EcoNewsGenericDto saveEcoNews(AddEcoNewsDtoRequest addEcoNewsDtoRequest, MultipartFile image, String email) {
EcoNews toSave = genericSave(addEcoNewsDtoRequest, image, email);
- EcoNewsGenericDto ecoNewsDto = getEcoNewsGenericDto(toSave);
+ EcoNewsGenericDto ecoNewsDto = getEcoNewsGenericDtoWithTag(toSave);
sendEmailDto(ecoNewsDto, toSave.getAuthor());
CompletableFuture.runAsync(() -> achievementCalculation
.calculateAchievement(toSave.getAuthor().getId(), AchievementType.INCREMENT,
@@ -504,7 +504,7 @@ public class EcoNewsServiceImpl implements EcoNewsService {
}
enhanceWithNewData(toUpdate, updateEcoNewsDto, image);
ecoNewsRepo.save(toUpdate);
- return getEcoNewsGenericDto(toUpdate);
+ return getEcoNewsGenericDtoWithTag(toUpdate);
}
@Override
@@ -578,7 +578,7 @@ public class EcoNewsServiceImpl implements EcoNewsService {
*/
@Override
public String[] uploadImages(MultipartFile[] images) {
- return Arrays.stream(images).map(image -> fileService.upload(image)).toArray(String[]::new);
+ return Arrays.stream(images).map(fileService::upload).toArray(String[]::new);
}
/**
@@ -637,6 +637,28 @@ public class EcoNewsServiceImpl implements EcoNewsService {
.collect(Collectors.toList());
}
+ private EcoNewsGenericDto getEcoNewsGenericDtoWithTag(EcoNews ecoNews) {
+ User author = ecoNews.getAuthor();
+ var ecoNewsAuthorDto = new EcoNewsAuthorDto(author.getId(), author.getName());
+
+ List<String> tags = ecoNews.getTags().stream()
+ .flatMap(t -> t.getTagTranslations().stream())
+ .map(TagTranslation::getName)
+ .collect(Collectors.toList());
+
+ return EcoNewsGenericDto.builder()
+ .id(ecoNews.getId())
+ .imagePath(ecoNews.getImagePath())
+ .author(ecoNewsAuthorDto)
+ .tags(tags)
+ .shortInfo(ecoNews.getShortInfo())
+ .content(ecoNews.getText())
+ .title(ecoNews.getTitle())
+ .creationDate(ecoNews.getCreationDate())
+ .source(ecoNews.getSource())
+ .build();
+ }
+
private EcoNewsGenericDto getEcoNewsGenericDto(EcoNews ecoNews) {
User author = ecoNews.getAuthor();
var ecoNewsAuthorDto = new EcoNewsAuthorDto(author.getId(), author.getName());
