Skip to content

Commit cbb07dd

Browse files
committed
feat(product): add v2 implementation of product controller, service, and repository
introduces a new version of the product management components, including a paginated product retrieval endpoint and repository integration for improved data handling.
1 parent 9030477 commit cbb07dd

3 files changed

Lines changed: 69 additions & 0 deletions

File tree

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.example.store.product.application;
2+
3+
import com.example.store.product.domain.Product;
4+
import com.example.store.product.infrastructure.repository.implementation.ProductRepositoryImplV2;
5+
import lombok.RequiredArgsConstructor;
6+
import org.springframework.data.domain.Page;
7+
import org.springframework.data.domain.Pageable;
8+
import org.springframework.stereotype.Service;
9+
10+
@Service
11+
@RequiredArgsConstructor
12+
public class ProductServiceImplV2 {
13+
14+
private final ProductRepositoryImplV2 productRepositoryImplV2;
15+
16+
public Page<Product> findAll(Pageable pageable) {
17+
return productRepositoryImplV2.findAll(pageable);
18+
}
19+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package com.example.store.product.infrastructure;
2+
3+
import com.example.store.product.application.ProductServiceImplV2;
4+
import com.example.store.product.domain.Product;
5+
import io.swagger.v3.oas.annotations.Operation;
6+
import lombok.RequiredArgsConstructor;
7+
import org.springframework.data.domain.Page;
8+
import org.springframework.data.domain.Pageable;
9+
import org.springframework.data.web.PageableDefault;
10+
import org.springframework.http.HttpStatus;
11+
import org.springframework.http.ResponseEntity;
12+
import org.springframework.web.bind.annotation.GetMapping;
13+
import org.springframework.web.bind.annotation.RequestMapping;
14+
import org.springframework.web.bind.annotation.RestController;
15+
16+
@RestController
17+
@RequestMapping("/api/v2/products")
18+
@RequiredArgsConstructor
19+
public class ProductControllerImplV2 {
20+
21+
private final ProductServiceImplV2 productService;
22+
23+
@GetMapping
24+
@Operation(summary = "Returns a paginated list of products")
25+
public ResponseEntity<Page<Product>> findAll(@PageableDefault Pageable pageable) {
26+
return ResponseEntity.status(HttpStatus.OK).body(productService.findAll(pageable));
27+
}
28+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.example.store.product.infrastructure.repository.implementation;
2+
3+
import com.example.store.product.domain.Product;
4+
import com.example.store.product.infrastructure.mapper.ProductMapper;
5+
import com.example.store.product.infrastructure.repository.QueryProductRepository;
6+
import lombok.RequiredArgsConstructor;
7+
import org.springframework.data.domain.Page;
8+
import org.springframework.data.domain.Pageable;
9+
import org.springframework.stereotype.Repository;
10+
11+
@Repository
12+
@RequiredArgsConstructor
13+
public class ProductRepositoryImplV2 {
14+
15+
private final QueryProductRepository queryProductRepository;
16+
private final ProductMapper productMapper;
17+
18+
19+
public Page<Product> findAll(Pageable pageable) {
20+
return queryProductRepository.findAll(pageable).map(productMapper::productEntityToProduct);
21+
}
22+
}

0 commit comments

Comments
 (0)