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

[product-4] Implement Product API for front-end: Get the list of all products #58

Closed

Conversation

UladzislauM
Copy link
Contributor

Implement Product API for front-end: Get the list of all products.

  • changed the controller according to business requirements;
  • added ProductInfoRequestResponseDto;
  • added Service;
  • corrected Repository.


public interface ProductInfoService {

Page<ProductInfoRequestResponseDto> getAllProducts(Pageable pageable);
Copy link
Owner

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

private final ProductInfoRepository productInfoRepository;
private final ProductInfoDtoConverter productInfoDtoConverter;
private final ProductInfoService productInfoService;

@GetMapping("/{id}")
public ResponseEntity<ProductInfoDto> getProductInfoById(@PathVariable("id") final String id) {
Copy link
Owner

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}")
Copy link
Owner

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));
Copy link
Owner

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);

@Slf4j
@RequiredArgsConstructor
@Service
public class ProductInfoServiceImpl implements ProductApi {

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) {
Copy link

@AiratGimaev AiratGimaev Jul 28, 2023

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) {
Copy link

@AiratGimaev AiratGimaev Jul 28, 2023

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> ?

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);
Copy link

@AiratGimaev AiratGimaev Jul 28, 2023

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;

@UladzislauM UladzislauM changed the title Feature/product 4 [product-4] Implement Product API for front-end: Get the list of all products Jul 31, 2023
Copy link
Contributor

@Sanya124 Sanya124 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed

Copy link

@AiratGimaev AiratGimaev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved

@Sunagatov Sunagatov closed this Aug 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants