-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d603526
commit 07eb4d3
Showing
11 changed files
with
129 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,9 @@ | |
# BlueJ files | ||
*.ctxt | ||
|
||
# Environment Variables | ||
.env | ||
|
||
# Mobile Tools for Java (J2ME) | ||
.mtj.tmp/ | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
src/main/java/dev/waltercrdz/api/ecommerce/products/application/ProductFinder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package dev.waltercrdz.api.ecommerce.products.application; | ||
|
||
import java.util.List; | ||
import java.util.UUID; | ||
|
||
import org.springframework.stereotype.Service; | ||
|
||
import dev.waltercrdz.api.ecommerce.products.domain.model.Product; | ||
import dev.waltercrdz.api.ecommerce.products.domain.repository.ProductQueryRepository; | ||
import dev.waltercrdz.api.ecommerce.shared.domain.exception.ProductNotFoundException; | ||
|
||
@Service | ||
public class ProductFinder { | ||
|
||
private final ProductQueryRepository reader; | ||
|
||
public ProductFinder(ProductQueryRepository reader) { | ||
this.reader = reader; | ||
} | ||
|
||
public Product find(UUID id) { | ||
return reader.findById(id).orElseThrow(() -> new ProductNotFoundException("Product not found", id)); | ||
} | ||
|
||
public List<Product> findAll() { | ||
return reader.findAll(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 1 addition & 6 deletions
7
...ava/dev/waltercrdz/api/ecommerce/products/domain/repository/ProductCommandRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,8 @@ | ||
package dev.waltercrdz.api.ecommerce.products.domain.repository; | ||
|
||
import java.util.Optional; | ||
import java.util.UUID; | ||
|
||
import dev.waltercrdz.api.ecommerce.products.domain.model.Product; | ||
|
||
public interface ProductCommandRepository { | ||
|
||
void save(Product product); | ||
|
||
Optional<Product> findById(UUID id); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
.../java/dev/waltercrdz/api/ecommerce/products/domain/repository/ProductQueryRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package dev.waltercrdz.api.ecommerce.products.domain.repository; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
import java.util.UUID; | ||
|
||
import dev.waltercrdz.api.ecommerce.products.domain.model.Product; | ||
|
||
public interface ProductQueryRepository { | ||
|
||
Optional<Product> findById(UUID id); | ||
List<Product> findAll(); | ||
} |
39 changes: 39 additions & 0 deletions
39
...dev/waltercrdz/api/ecommerce/products/infrastructure/in/controller/ProductController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package dev.waltercrdz.api.ecommerce.products.infrastructure.in.controller; | ||
|
||
import java.util.List; | ||
import java.util.UUID; | ||
import java.util.stream.Collectors; | ||
|
||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import dev.waltercrdz.api.ecommerce.products.application.ProductFinder; | ||
import dev.waltercrdz.api.ecommerce.products.infrastructure.in.dto.ProductResponse; | ||
import dev.waltercrdz.api.ecommerce.products.infrastructure.in.mapper.ProductMapper; | ||
|
||
@RestController | ||
@RequestMapping("/products") | ||
public class ProductController { | ||
|
||
private final ProductFinder finder; | ||
|
||
public ProductController(ProductFinder finder) { | ||
this.finder = finder; | ||
} | ||
|
||
@GetMapping("/{id}") | ||
public ProductResponse getProduct(UUID id) { | ||
final var product = this.finder.find(id); | ||
return ProductMapper.toResponse(product); | ||
} | ||
|
||
@GetMapping | ||
public List<ProductResponse> getProducts() { | ||
final var products = this.finder.findAll(); | ||
return products.stream() | ||
.map(ProductMapper::toResponse) | ||
.collect(Collectors.toList()); | ||
} | ||
|
||
} |
12 changes: 12 additions & 0 deletions
12
...ain/java/dev/waltercrdz/api/ecommerce/products/infrastructure/in/dto/ProductResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package dev.waltercrdz.api.ecommerce.products.infrastructure.in.dto; | ||
|
||
import java.math.BigDecimal; | ||
import java.util.UUID; | ||
|
||
public record ProductResponse( | ||
UUID id, | ||
String name, | ||
String description, | ||
BigDecimal price, | ||
Integer stock) { | ||
} |
16 changes: 16 additions & 0 deletions
16
...in/java/dev/waltercrdz/api/ecommerce/products/infrastructure/in/mapper/ProductMapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package dev.waltercrdz.api.ecommerce.products.infrastructure.in.mapper; | ||
|
||
import dev.waltercrdz.api.ecommerce.products.domain.model.Product; | ||
import dev.waltercrdz.api.ecommerce.products.infrastructure.in.dto.ProductResponse; | ||
|
||
public class ProductMapper { | ||
|
||
public static ProductResponse toResponse(Product product) { | ||
return new ProductResponse( | ||
product.getId(), | ||
product.getName(), | ||
product.getDescription(), | ||
product.getPrice(), | ||
product.getStock()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...ers/infrastructure/in/error/ApiError.java → ...red/infrastructure/in/error/ApiError.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters