-
-
Notifications
You must be signed in to change notification settings - Fork 107
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
[product-4] Implement Product API for front-end: Get the list of all products #58
Conversation
src/main/java/com/zufar/onlinestore/product/converter/ProductInfoDtoConverter.java
Outdated
Show resolved
Hide resolved
src/main/java/com/zufar/onlinestore/product/converter/ProductInfoDtoConverter.java
Outdated
Show resolved
Hide resolved
|
||
public interface ProductInfoService { | ||
|
||
Page<ProductInfoRequestResponseDto> getAllProducts(Pageable pageable); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
did you test this?
does it work?
Please test
src/main/java/com/zufar/onlinestore/product/service/ProductInfoService.java
Outdated
Show resolved
Hide resolved
src/main/java/com/zufar/onlinestore/product/service/ProductInfoService.java
Outdated
Show resolved
Hide resolved
private final ProductInfoRepository productInfoRepository; | ||
private final ProductInfoDtoConverter productInfoDtoConverter; | ||
private final ProductInfoService productInfoService; | ||
|
||
@GetMapping("/{id}") | ||
public ResponseEntity<ProductInfoDto> getProductInfoById(@PathVariable("id") final String id) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rename id like productId
please
private final ProductInfoRepository productInfoRepository; | ||
private final ProductInfoDtoConverter productInfoDtoConverter; | ||
private final ProductInfoService productInfoService; | ||
|
||
@GetMapping("/{id}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rename id like productId
please
|
||
@GetMapping("/{id}") | ||
public ResponseEntity<ProductInfoDto> getProductInfoById(@PathVariable("id") final String id) { | ||
log.info("Received request to get the ProductInfo with id - {}.", id); | ||
Optional<ProductInfo> ProductInfo = productInfoRepository.findById(Integer.parseInt(id)); | ||
Optional<ProductInfo> ProductInfo = productInfoRepository.findById(UUID.fromString(id)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
create getProductById
method in ProductInfoService
and ProductInfoServiceImpl
and use this class here like productInfoService.getProductById(productId);
src/main/java/com/zufar/onlinestore/product/dto/ProductInfoRequestResponseDto.java
Outdated
Show resolved
Hide resolved
src/main/java/com/zufar/onlinestore/product/dto/ProductInfoRequestResponseDto.java
Outdated
Show resolved
Hide resolved
@Slf4j | ||
@RequiredArgsConstructor | ||
@Service | ||
public class ProductInfoServiceImpl implements ProductApi { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-Impl is redundant
public ResponseEntity<Collection<ProductInfoDto>> getAllProducts() { | ||
log.info("Received request to get all ProductInfos"); | ||
Collection<ProductInfo> productInfoCollection = productInfoRepository.findAll(); | ||
public ResponseEntity<Page<ProductResponseDto>> getAllProducts(Pageable pageable) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pageable is an interface not class. How do you want map json to this interface ? Parameters for page should be passed through /products?page=X&pageSize=N
public ResponseEntity<Collection<ProductInfoDto>> getAllProducts() { | ||
log.info("Received request to get all ProductInfos"); | ||
Collection<ProductInfo> productInfoCollection = productInfoRepository.findAll(); | ||
public ResponseEntity<Page<ProductResponseDto>> getAllProducts(Pageable pageable) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you return Page<ProductResponseDto>
instead of Collection<ProductResponseDto>
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pageable and Page is a data layer interfaces and should be used only in Service and Repository
|
||
public interface ProductApi { | ||
|
||
Page<ProductResponseDto> getProducts(Pageable pageable); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The same. Our API should be clear and not depend on org.springframework.data.domain.Page
and org.springframework.data.domain.Pageable;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approved
Implement Product API for front-end: Get the list of all products.