Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
@@ -0,0 +1,20 @@
package com.shervinee.shop.products;

import org.springframework.context.annotation.Profile;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.List;

@Service @Profile("dev")
public class InMemoryProductsService implements ProductsService {

@Override
public List<ProductDto> getAllProducts() {
return List.of(
new ProductDto(1L, "desk", new BigDecimal("122.67"), true ),
new ProductDto(1L, "monitor", new BigDecimal("252.31"), true ),
new ProductDto(1L, "chair", new BigDecimal("50.31"), false )
);
}
}
5 changes: 5 additions & 0 deletions src/main/java/com/shervinee/shop/products/ProductDto.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.shervinee.shop.products;

import java.math.BigDecimal;

public record ProductDto(Long id, String name, BigDecimal price, boolean inStock) {}
21 changes: 21 additions & 0 deletions src/main/java/com/shervinee/shop/products/ProductsController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.shervinee.shop.products;

import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequiredArgsConstructor
@RequestMapping("api/products")
public class ProductsController {

private final ProductsService productsService;

@GetMapping
public List<ProductDto> list() {
return productsService.getAllProducts();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.shervinee.shop.products;

import java.util.List;


public interface ProductsService {
List<ProductDto> getAllProducts();
}
Loading