Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added some mappers #295

Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
2f250e6
added some mappers
ZiborovaVictoria May 9, 2024
bdb5527
fixed npe
ZiborovaVictoria May 9, 2024
a082e3f
issues/294 (incorrect data: rating and reviews count) was fixed
Sunagatov May 10, 2024
eb5e523
ProductReviewsStatisticsProvider was fixed
Sunagatov May 10, 2024
2b4eda1
ProductApi and ProductApiImpl were deleted
Sunagatov May 10, 2024
1130cc9
UserEntity was deleted in FavoriteListEntity
Sunagatov May 10, 2024
cd729c9
issues/291 (incorrect order of products when sorted by average rating…
Sunagatov May 10, 2024
8bba605
08.02.2024.part2.insert-product-review-table.sql was updated
Sunagatov May 10, 2024
17d2fae
28.07.2023.part6.insert-user-details-table-data.sql was updated
Sunagatov May 10, 2024
3b73355
added new addresses
Sunagatov May 10, 2024
8374128
Create dependabot.yml
Sunagatov May 10, 2024
77ab250
Update issue templates
Sunagatov May 11, 2024
265d8e8
Update dev-branch-pr-deployment-pipeline.yml
Sunagatov May 11, 2024
9d3f9c5
Create codacy.yml
Sunagatov May 11, 2024
2afeebf
Create codeql.yml
Sunagatov May 11, 2024
085ebef
Create sonarqube.yml
Sunagatov May 11, 2024
2d19887
Create greetings.yml
Sunagatov May 11, 2024
3e0d674
Update dependabot.yml
Sunagatov May 11, 2024
87cbfda
Update dependabot.yml
Sunagatov May 11, 2024
b2a347d
Update codeql.yml
Sunagatov May 11, 2024
a63f210
README.md was updated
Sunagatov May 11, 2024
12070a0
README.md was updated
Sunagatov May 11, 2024
8082116
fixed expressions -> @Named
ZiborovaVictoria May 13, 2024
f4b39d3
added tests for converters
ZiborovaVictoria May 13, 2024
f8a49f8
README.md was updated
Sunagatov May 14, 2024
a954692
Migration from Java 17 to Java 21 + fixed GOOGLE_AUTH error for local…
annstriganova May 16, 2024
9aadeb9
updated version in pom.xml
annstriganova May 16, 2024
49ec646
updated version in dev-branch-pr-build-and-test-pipeline.yaml
annstriganova May 17, 2024
eea40dc
Merge pull request #300 from Sunagatov/feature/java-21
Sunagatov May 17, 2024
3cefb0c
Update README.md
Sunagatov May 17, 2024
6528206
fixes
ZiborovaVictoria May 18, 2024
3ca1bc4
Update README.md
Sunagatov May 21, 2024
76cd7a4
added some mappers
ZiborovaVictoria May 9, 2024
f2f16fe
fixed npe
ZiborovaVictoria May 9, 2024
8444ba0
fixed expressions -> @Named
ZiborovaVictoria May 13, 2024
d61eb62
added tests for converters
ZiborovaVictoria May 13, 2024
f23b4db
fixes
ZiborovaVictoria May 18, 2024
dcfe493
Merge remote-tracking branch 'origin/feature/IL-287-custom-mappers-to…
ZiborovaVictoria May 26, 2024
5cb0e5f
tried to merge
ZiborovaVictoria May 26, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@
import com.zufar.icedlatte.openapi.dto.ProductInfoDto;
import com.zufar.icedlatte.product.entity.ProductInfo;
import com.zufar.icedlatte.user.entity.UserEntity;
import org.mapstruct.*;
import org.mapstruct.InjectionStrategy;
import org.mapstruct.Mapper;
import org.mapstruct.MappingConstants;
import org.mapstruct.ReportingPolicy;
import org.mapstruct.Mapping;
import org.mapstruct.Named;

import java.util.Optional;
import java.util.UUID;
Expand All @@ -16,22 +21,11 @@
uses = FavoriteItemDtoConverter.class, unmappedTargetPolicy = ReportingPolicy.IGNORE, injectionStrategy = InjectionStrategy.FIELD)
public interface FavoriteListDtoConverter {

@Mapping(target = "id", source = "id")
@Mapping(target = "userId", source = "user", qualifiedByName = "toUserId")
@Mapping(target = "updatedAt", source = "updatedAt")
@Mapping(target = "favoriteItems", source = "favoriteItems", qualifiedByName = "mapFavoriteItems")
FavoriteListDto toDto(final FavoriteListEntity favoriteListEntity);

@Mapping(target = "id", source = "productId")
@Mapping(target = "name", source = "name")
@Mapping(target = "description", source = "description")
@Mapping(target = "price", source = "price")
@Mapping(target = "quantity", source = "quantity")
@Mapping(target = "active", source = "active")
@Mapping(target = "averageRating", source = "averageRating")
@Mapping(target = "reviewsCount", source = "reviewsCount")
@Mapping(target = "brandName", source = "brandName")
@Mapping(target = "sellerName", source = "sellerName")
ProductInfoDto convertProductInfoDto(ProductInfo productInfo);

@Named("toUserId")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@
import com.zufar.icedlatte.favorite.dto.FavoriteListDto;
import com.zufar.icedlatte.openapi.dto.ListOfFavoriteProductsDto;
import com.zufar.icedlatte.openapi.dto.ProductInfoDto;
import org.mapstruct.*;
import org.mapstruct.InjectionStrategy;
import org.mapstruct.Mapper;
import org.mapstruct.MappingConstants;
import org.mapstruct.ReportingPolicy;
import org.mapstruct.Mapping;
import org.mapstruct.Named;

import java.util.List;
import java.util.Set;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Locale;
import java.util.UUID;

@Slf4j
Expand All @@ -37,7 +38,7 @@ public ProductReviewRatingStats getRatingAndReviewStat(final UUID productId) {
log.error("The product with productId = {} was not found.", productId);
throw new ProductNotFoundException(productId);
}
String formattedAvgRating = String.format("%.1f", avgRating);
String formattedAvgRating = String.format(Locale.US, "%.1f", avgRating);
Integer reviewsCount = reviewRepository.getReviewCountProductById(productId);
RatingMap productRatingMap = productReviewDtoConverter.convertToProductRatingMap(productRatingCountPairs);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@
import com.zufar.icedlatte.review.dto.ProductRatingCount;
import com.zufar.icedlatte.review.entity.ProductReview;
import com.zufar.icedlatte.user.entity.UserEntity;
import org.mapstruct.*;
import org.mapstruct.InjectionStrategy;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Named;
import org.mapstruct.MappingConstants;
import org.mapstruct.ReportingPolicy;
import org.springframework.data.domain.Page;

import java.util.List;
Expand All @@ -16,18 +21,12 @@
uses = ProductReviewDtoConverter.class, unmappedTargetPolicy = ReportingPolicy.IGNORE, injectionStrategy = InjectionStrategy.FIELD)
public interface ProductReviewDtoConverter {

ProductReviewDto EMPTY_PRODUCT_REVIEW_RESPONSE =
public static final ProductReviewDto EMPTY_PRODUCT_REVIEW_RESPONSE =
new ProductReviewDto(null, null, null, null, null, null, null, null, null);

@Mapping(target = "productReviewId", source = "id")
@Mapping(target = "productId", source = "productId")
@Mapping(target = "productRating", source = "productRating")
@Mapping(target = "text", source = "text")
@Mapping(target = "createdAt", source = "createdAt")
@Mapping(target = "userName", source = "user", qualifiedByName = "toUserName")
@Mapping(target = "userLastname", source = "user", qualifiedByName = "toUserLastName")
@Mapping(target = "likesCount", source = "likesCount")
@Mapping(target = "dislikesCount", source = "dislikesCount")
ProductReviewDto toProductReviewDto(ProductReview productReview);

@Mapping(target = "page", expression = "java(page.getTotalPages())")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.zufar.icedlatte.favorite.converter;

import com.zufar.icedlatte.favorite.dto.FavoriteItemDto;
import com.zufar.icedlatte.favorite.dto.FavoriteListDto;
import com.zufar.icedlatte.favorite.entity.FavoriteItemEntity;
import com.zufar.icedlatte.favorite.entity.FavoriteListEntity;
Expand All @@ -18,6 +19,7 @@
import java.util.UUID;

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;

public class FavoriteListDtoConverterTest {

Expand Down Expand Up @@ -47,12 +49,9 @@ void convertListEntityToDto() {

FavoriteListDto actualFavoriteListDto = converter.toDto(expectedFavoriteListEntity);

assertThat(actualFavoriteListDto.id()).isEqualTo(expectedFavoriteListEntity.getId());
assertThat(actualFavoriteListDto.updatedAt()).isEqualTo(expectedFavoriteListEntity.getUpdatedAt());
assertThat(actualFavoriteListDto.userId()).isEqualTo(Optional.of(expectedFavoriteListEntity.getUser()).get().getId());
// fIXME: how to test favoriteItems?
// assertThat(actualFavoriteListDto.favoriteItems()).isEqualTo(expectedFavoriteListEntity.getFavoriteItems());

assertEquals(actualFavoriteListDto.id(), expectedFavoriteListEntity.getId());
assertEquals(actualFavoriteListDto.updatedAt(), expectedFavoriteListEntity.getUpdatedAt());
assertEquals(actualFavoriteListDto.userId(), Optional.of(expectedFavoriteListEntity.getUser()).get().getId());
ZiborovaVictoria marked this conversation as resolved.
Show resolved Hide resolved
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import java.util.UUID;

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;

public class ListOfFavoriteProductsDtoConverterTest {

Expand Down Expand Up @@ -44,5 +45,7 @@ void toListProductDto() {
ListOfFavoriteProductsDto actualListOfFavoriteProductsDto = converter.toListProductDto(expectedFavoriteListDto);

assertThat(actualListOfFavoriteProductsDto.getProducts()).isEqualTo(converter.toProductInfoDto(expectedFavoriteListDto.favoriteItems()));
annstriganova marked this conversation as resolved.
Show resolved Hide resolved

assertEquals(actualListOfFavoriteProductsDto.getProducts().get(0), productInfoDto);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ void getRatingAndReviewStatsSuccessful() {
var reviewsCount = 0;

var expectedRatingMap = new RatingMap(1, 0, 0, 0, 0);
var expectedStats = new ProductReviewRatingStats(randomID, "0,0", reviewsCount, expectedRatingMap);
var expectedStats = new ProductReviewRatingStats(randomID, "0.0", reviewsCount, expectedRatingMap);
when(reviewRepository.getRatingsMapByProductId(randomID)).thenReturn(listOfMappings);
when(reviewRepository.getAvgRatingByProductId(randomID)).thenReturn(0.0);
when(reviewRepository.getReviewCountProductById(randomID)).thenReturn(reviewsCount);
Expand Down