← Back
Show Markdown
Download Markdown
Ten moduł zapewnia funkcjonalność zarządzania zapasami, sprzedażą, zakupami, dostawcami, typami produktów i kategoriami dla firmy detalicznej.
@Service
public class ExampleService {
private final SaleService saleService;
public ExampleService(SaleService saleService) {
this.saleService = saleService;
}
public void registerNewSale() {
SaleDetailsRequestDto saleDetailsRequestDto = SaleDetailsRequestDto.builder()
.productsList(List.of(ProductPatchRequestDto.builder().name("Nazwa Produktu").build()))
.amount(new BigDecimal("100.00"))
.discount(new BigDecimal("0.10"))
.quantity(1L)
.build();
SaleResponseDto saleResponseDto = saleService.registerSale(saleDetailsRequestDto);
System.out.println("Sprzedaż zarejestrowana z ID: " + saleResponseDto.getId());
}
}
Aby zarejestrować sprzedaż, wyślij żądanie POST na adres /sales/register
z następującym ładunkiem JSON:
{
"productsList": [
{
"name": "Nazwa Produktu"
}
],
"amount": 100.00,
"discount": 0.10,
"quantity": 1
}
Przykład użycia curl
:
curl -X POST \
http://localhost:8080/sales/register \
-H 'Content-Type: application/json' \
-d '{
"productsList": [
{
"name": "Nazwa Produktu"
}
],
"amount": 100.00,
"discount": 0.10,
"quantity": 1
}'
Aby dodać produkt, wyślij żądanie POST na adres /products/add
z następującym ładunkiem JSON:
{
"name": "Nowy Produkt",
"description": "Opis Produktu",
"categoryId": 1,
"buyPrice": 50.00,
"salePrice": 100.00,
"stock": 100,
"supplierId": 1,
"productTypeId": 1
}
Przykład użycia curl
:
curl -X POST \
http://localhost:8080/products/add \
-H 'Content-Type: application/json' \
-d '{
"name": "Nowy Produkt",
"description": "Opis Produktu",
"categoryId": 1,
"buyPrice": 50.00,
"salePrice": 100.00,
"stock": 100,
"supplierId": 1,
"productTypeId": 1
}'
Moduł zawiera klasę CorsConfig
do konfigurowania współdzielenia zasobów między różnymi źródłami (CORS).
@Configuration
public class CorsConfig implements WebMvcConfigurer {
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**")
.allowedOrigins("http://localhost:5173")
.allowedMethods("*")
.allowedHeaders("*")
.allowCredentials(true);
}
}
Ta konfiguracja zezwala na żądania z http://localhost:5173
.
Aby użyć tego modułu, potrzebujesz następujących zależności w pliku pom.xml
:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
🌍 Ten plik README jest dostępny w wielu językach: 🔗 readme.maxpfeffer.de