From d29b6e771f86e2d975a398971b598c4bd303d2b0 Mon Sep 17 00:00:00 2001 From: viprko Date: Wed, 16 Aug 2023 13:00:47 +0300 Subject: [PATCH 1/2] Created simple app for working with products and its categories --- pom.xml | 59 ++++++++++++++++ .../datajpa/config/MapperConfig.java | 13 ++++ .../controller/CategoryController.java | 47 +++++++++++++ .../datajpa/controller/ProductController.java | 70 +++++++++++++++++++ .../datajpa/dto/CategoryRequestDto.java | 8 +++ .../datajpa/dto/CategoryResponseDto.java | 9 +++ .../datajpa/dto/ProductRequestDto.java | 11 +++ .../datajpa/dto/ProductResponseDto.java | 12 ++++ .../springboot/datajpa/model/Category.java | 18 +++++ .../springboot/datajpa/model/Product.java | 23 ++++++ .../repository/CategoryRepository.java | 9 +++ .../datajpa/repository/ProductRepository.java | 15 ++++ .../datajpa/service/CategoryService.java | 13 ++++ .../datajpa/service/CategoryServiceImpl.java | 40 +++++++++++ .../datajpa/service/ProductService.java | 20 ++++++ .../datajpa/service/ProductServiceImpl.java | 55 +++++++++++++++ .../service/mapper/CategoryMapper.java | 15 ++++ .../datajpa/service/mapper/DtoMapper.java | 7 ++ .../datajpa/service/mapper/ProductMapper.java | 17 +++++ src/main/resources/application.properties | 8 +++ 20 files changed, 469 insertions(+) create mode 100644 src/main/java/mate/academy/springboot/datajpa/config/MapperConfig.java create mode 100644 src/main/java/mate/academy/springboot/datajpa/controller/CategoryController.java create mode 100644 src/main/java/mate/academy/springboot/datajpa/controller/ProductController.java create mode 100644 src/main/java/mate/academy/springboot/datajpa/dto/CategoryRequestDto.java create mode 100644 src/main/java/mate/academy/springboot/datajpa/dto/CategoryResponseDto.java create mode 100644 src/main/java/mate/academy/springboot/datajpa/dto/ProductRequestDto.java create mode 100644 src/main/java/mate/academy/springboot/datajpa/dto/ProductResponseDto.java create mode 100644 src/main/java/mate/academy/springboot/datajpa/model/Category.java create mode 100644 src/main/java/mate/academy/springboot/datajpa/model/Product.java create mode 100644 src/main/java/mate/academy/springboot/datajpa/repository/CategoryRepository.java create mode 100644 src/main/java/mate/academy/springboot/datajpa/repository/ProductRepository.java create mode 100644 src/main/java/mate/academy/springboot/datajpa/service/CategoryService.java create mode 100644 src/main/java/mate/academy/springboot/datajpa/service/CategoryServiceImpl.java create mode 100644 src/main/java/mate/academy/springboot/datajpa/service/ProductService.java create mode 100644 src/main/java/mate/academy/springboot/datajpa/service/ProductServiceImpl.java create mode 100644 src/main/java/mate/academy/springboot/datajpa/service/mapper/CategoryMapper.java create mode 100644 src/main/java/mate/academy/springboot/datajpa/service/mapper/DtoMapper.java create mode 100644 src/main/java/mate/academy/springboot/datajpa/service/mapper/ProductMapper.java diff --git a/pom.xml b/pom.xml index cf704585..12c80437 100644 --- a/pom.xml +++ b/pom.xml @@ -19,7 +19,10 @@ https://raw.githubusercontent.com/mate-academy/style-guides/master/java/checkstyle.xml + 1.5.5.Final + 0.2.0 + org.springframework.boot @@ -30,7 +33,33 @@ org.springframework.boot spring-boot-autoconfigure + + org.springframework.boot + spring-boot-starter-data-jpa + + + org.springframework.boot + spring-boot-starter-web + + + com.h2database + h2 + + + org.projectlombok + lombok + + + org.springframework.boot + spring-boot-devtools + + + org.mapstruct + mapstruct + ${org.mapstruct.version} + + @@ -58,6 +87,10 @@ + + **/target/generated-sources/** + **/target/generated-test-sources + ${maven.checkstyle.plugin.configLocation} UTF-8 true @@ -65,6 +98,32 @@ false + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.1 + + ${java.version} + ${java.version} + + + org.projectlombok + lombok + ${lombok.version} + + + org.mapstruct + mapstruct-processor + ${org.mapstruct.version} + + + org.projectlombok + lombok-mapstruct-binding + ${lombok.mapstruct.binding.version} + + + + diff --git a/src/main/java/mate/academy/springboot/datajpa/config/MapperConfig.java b/src/main/java/mate/academy/springboot/datajpa/config/MapperConfig.java new file mode 100644 index 00000000..12c61c92 --- /dev/null +++ b/src/main/java/mate/academy/springboot/datajpa/config/MapperConfig.java @@ -0,0 +1,13 @@ +package mate.academy.springboot.datajpa.config; + +import org.mapstruct.InjectionStrategy; +import org.mapstruct.NullValueCheckStrategy; + +@org.mapstruct.MapperConfig( + componentModel = "spring", + injectionStrategy = InjectionStrategy.CONSTRUCTOR, + nullValueCheckStrategy = NullValueCheckStrategy.ALWAYS, + implementationPackage = ".impl" +) +public class MapperConfig { +} diff --git a/src/main/java/mate/academy/springboot/datajpa/controller/CategoryController.java b/src/main/java/mate/academy/springboot/datajpa/controller/CategoryController.java new file mode 100644 index 00000000..92e66fc1 --- /dev/null +++ b/src/main/java/mate/academy/springboot/datajpa/controller/CategoryController.java @@ -0,0 +1,47 @@ +package mate.academy.springboot.datajpa.controller; + +import lombok.AllArgsConstructor; +import mate.academy.springboot.datajpa.dto.CategoryRequestDto; +import mate.academy.springboot.datajpa.dto.CategoryResponseDto; +import mate.academy.springboot.datajpa.model.Category; +import mate.academy.springboot.datajpa.service.CategoryService; +import mate.academy.springboot.datajpa.service.mapper.DtoMapper; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PatchMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("/categories") +@AllArgsConstructor +public class CategoryController { + private final CategoryService categoryService; + private final DtoMapper dtoMapper; + + @PostMapping + public CategoryResponseDto add(@RequestBody CategoryRequestDto categoryRequestDto) { + return dtoMapper.toDto( + categoryService.create(dtoMapper.toEntity(categoryRequestDto))); + } + + @GetMapping("/{id}") + public CategoryResponseDto findById(@PathVariable Long id) { + return dtoMapper.toDto(categoryService.findById(id)); + } + + @PatchMapping("/{id}") + public CategoryResponseDto update(@PathVariable Long id, + @RequestBody CategoryRequestDto categoryRequestDto) { + return dtoMapper.toDto(categoryService.update(id, + dtoMapper.toEntity(categoryRequestDto))); + } + + @DeleteMapping("/{id}") + public void deleteById(@PathVariable Long id) { + categoryService.deleteById(id); + } +} diff --git a/src/main/java/mate/academy/springboot/datajpa/controller/ProductController.java b/src/main/java/mate/academy/springboot/datajpa/controller/ProductController.java new file mode 100644 index 00000000..1eca4cce --- /dev/null +++ b/src/main/java/mate/academy/springboot/datajpa/controller/ProductController.java @@ -0,0 +1,70 @@ +package mate.academy.springboot.datajpa.controller; + +import java.math.BigDecimal; +import java.util.List; +import java.util.Set; +import java.util.stream.Collectors; +import lombok.AllArgsConstructor; +import mate.academy.springboot.datajpa.dto.ProductRequestDto; +import mate.academy.springboot.datajpa.dto.ProductResponseDto; +import mate.academy.springboot.datajpa.model.Product; +import mate.academy.springboot.datajpa.service.ProductService; +import mate.academy.springboot.datajpa.service.mapper.DtoMapper; +import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PatchMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.ResponseStatus; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@AllArgsConstructor +@RequestMapping("/products") +public class ProductController { + private final ProductService productService; + private final DtoMapper dtoMapper; + + @PostMapping + public ProductResponseDto create(@RequestBody ProductRequestDto productRequestDto) { + return dtoMapper.toDto( + productService.create(dtoMapper.toEntity(productRequestDto))); + } + + @GetMapping("/{id}") + public ProductResponseDto get(@PathVariable Long id) { + return dtoMapper.toDto(productService.findById(id)); + } + + @PatchMapping("/{id}") + public ProductResponseDto update(@PathVariable Long id, + @RequestBody ProductRequestDto productRequestDto) { + return dtoMapper.toDto(productService.update(id, + dtoMapper.toEntity(productRequestDto))); + } + + @DeleteMapping("/{id}") + @ResponseStatus(HttpStatus.OK) + public void delete(@PathVariable Long id) { + productService.deleteById(id); + } + + @GetMapping("/by-price") + public List getAllByPriceBetween(@RequestParam BigDecimal priceFrom, + @RequestParam BigDecimal priceTo) { + return productService.getAllByPriceBetween(priceFrom, priceTo).stream() + .map(dtoMapper::toDto) + .collect(Collectors.toList()); + } + + @GetMapping("/by-categories") + public List getAllByCategoryIds(@RequestParam Set categoryIds) { + List allByCategoryIds = productService.getAllByCategoryIds(categoryIds); + return allByCategoryIds.stream() + .map(dtoMapper::toDto).collect(Collectors.toList()); + } +} diff --git a/src/main/java/mate/academy/springboot/datajpa/dto/CategoryRequestDto.java b/src/main/java/mate/academy/springboot/datajpa/dto/CategoryRequestDto.java new file mode 100644 index 00000000..7a0c33a5 --- /dev/null +++ b/src/main/java/mate/academy/springboot/datajpa/dto/CategoryRequestDto.java @@ -0,0 +1,8 @@ +package mate.academy.springboot.datajpa.dto; + +import lombok.Data; + +@Data +public class CategoryRequestDto { + private String name; +} diff --git a/src/main/java/mate/academy/springboot/datajpa/dto/CategoryResponseDto.java b/src/main/java/mate/academy/springboot/datajpa/dto/CategoryResponseDto.java new file mode 100644 index 00000000..4c817782 --- /dev/null +++ b/src/main/java/mate/academy/springboot/datajpa/dto/CategoryResponseDto.java @@ -0,0 +1,9 @@ +package mate.academy.springboot.datajpa.dto; + +import lombok.Data; + +@Data +public class CategoryResponseDto { + private Long id; + private String name; +} diff --git a/src/main/java/mate/academy/springboot/datajpa/dto/ProductRequestDto.java b/src/main/java/mate/academy/springboot/datajpa/dto/ProductRequestDto.java new file mode 100644 index 00000000..2df315f9 --- /dev/null +++ b/src/main/java/mate/academy/springboot/datajpa/dto/ProductRequestDto.java @@ -0,0 +1,11 @@ +package mate.academy.springboot.datajpa.dto; + +import java.math.BigDecimal; +import lombok.Data; + +@Data +public class ProductRequestDto { + private String title; + private BigDecimal price; + private Long categoryId; +} diff --git a/src/main/java/mate/academy/springboot/datajpa/dto/ProductResponseDto.java b/src/main/java/mate/academy/springboot/datajpa/dto/ProductResponseDto.java new file mode 100644 index 00000000..cd71254e --- /dev/null +++ b/src/main/java/mate/academy/springboot/datajpa/dto/ProductResponseDto.java @@ -0,0 +1,12 @@ +package mate.academy.springboot.datajpa.dto; + +import java.math.BigDecimal; +import lombok.Data; + +@Data +public class ProductResponseDto { + private Long id; + private String title; + private BigDecimal price; + private Long categoryId; +} diff --git a/src/main/java/mate/academy/springboot/datajpa/model/Category.java b/src/main/java/mate/academy/springboot/datajpa/model/Category.java new file mode 100644 index 00000000..a8a4b3b4 --- /dev/null +++ b/src/main/java/mate/academy/springboot/datajpa/model/Category.java @@ -0,0 +1,18 @@ +package mate.academy.springboot.datajpa.model; + +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.Table; +import lombok.Data; + +@Data +@Entity +@Table(name = "categories") +public class Category { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + private String name; +} diff --git a/src/main/java/mate/academy/springboot/datajpa/model/Product.java b/src/main/java/mate/academy/springboot/datajpa/model/Product.java new file mode 100644 index 00000000..8c2502b6 --- /dev/null +++ b/src/main/java/mate/academy/springboot/datajpa/model/Product.java @@ -0,0 +1,23 @@ +package mate.academy.springboot.datajpa.model; + +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.ManyToOne; +import jakarta.persistence.Table; +import java.math.BigDecimal; +import lombok.Data; + +@Data +@Entity +@Table(name = "products") +public class Product { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + private String title; + private BigDecimal price; + @ManyToOne + private Category category; +} diff --git a/src/main/java/mate/academy/springboot/datajpa/repository/CategoryRepository.java b/src/main/java/mate/academy/springboot/datajpa/repository/CategoryRepository.java new file mode 100644 index 00000000..ed06bf2b --- /dev/null +++ b/src/main/java/mate/academy/springboot/datajpa/repository/CategoryRepository.java @@ -0,0 +1,9 @@ +package mate.academy.springboot.datajpa.repository; + +import mate.academy.springboot.datajpa.model.Category; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +@Repository +public interface CategoryRepository extends JpaRepository { +} diff --git a/src/main/java/mate/academy/springboot/datajpa/repository/ProductRepository.java b/src/main/java/mate/academy/springboot/datajpa/repository/ProductRepository.java new file mode 100644 index 00000000..52cc4855 --- /dev/null +++ b/src/main/java/mate/academy/springboot/datajpa/repository/ProductRepository.java @@ -0,0 +1,15 @@ +package mate.academy.springboot.datajpa.repository; + +import java.math.BigDecimal; +import java.util.Collection; +import java.util.List; +import mate.academy.springboot.datajpa.model.Product; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +@Repository +public interface ProductRepository extends JpaRepository { + List getAllByPriceBetween(BigDecimal priceFrom, BigDecimal priceTo); + + List getAllByCategoryIdIn(Collection categoryId); +} diff --git a/src/main/java/mate/academy/springboot/datajpa/service/CategoryService.java b/src/main/java/mate/academy/springboot/datajpa/service/CategoryService.java new file mode 100644 index 00000000..14177d35 --- /dev/null +++ b/src/main/java/mate/academy/springboot/datajpa/service/CategoryService.java @@ -0,0 +1,13 @@ +package mate.academy.springboot.datajpa.service; + +import mate.academy.springboot.datajpa.model.Category; + +public interface CategoryService { + Category create(Category category); + + Category findById(Long id); + + Category update(Long id, Category category); + + void deleteById(Long id); +} diff --git a/src/main/java/mate/academy/springboot/datajpa/service/CategoryServiceImpl.java b/src/main/java/mate/academy/springboot/datajpa/service/CategoryServiceImpl.java new file mode 100644 index 00000000..a78d34a6 --- /dev/null +++ b/src/main/java/mate/academy/springboot/datajpa/service/CategoryServiceImpl.java @@ -0,0 +1,40 @@ +package mate.academy.springboot.datajpa.service; + +import java.util.NoSuchElementException; +import lombok.AllArgsConstructor; +import mate.academy.springboot.datajpa.model.Category; +import mate.academy.springboot.datajpa.repository.CategoryRepository; +import org.springframework.stereotype.Service; + +@Service +@AllArgsConstructor +public class CategoryServiceImpl implements CategoryService { + private final CategoryRepository categoryRepository; + + @Override + public Category create(Category category) { + return categoryRepository.save(category); + } + + @Override + public Category findById(Long id) { + return categoryRepository.findById(id).orElseThrow(() -> + new NoSuchElementException("Can't get category with id " + id)); + } + + @Override + public Category update(Long id, Category category) { + if (category == null) { + throw new IllegalArgumentException("Category cannot be null"); + } + Category categoryFromDb = categoryRepository.findById(id).orElseThrow(() -> + new NoSuchElementException("Can't get category with id " + id)); + categoryFromDb.setName(category.getName()); + return categoryRepository.save(categoryFromDb); + } + + @Override + public void deleteById(Long id) { + categoryRepository.deleteById(id); + } +} diff --git a/src/main/java/mate/academy/springboot/datajpa/service/ProductService.java b/src/main/java/mate/academy/springboot/datajpa/service/ProductService.java new file mode 100644 index 00000000..e178a0fd --- /dev/null +++ b/src/main/java/mate/academy/springboot/datajpa/service/ProductService.java @@ -0,0 +1,20 @@ +package mate.academy.springboot.datajpa.service; + +import java.math.BigDecimal; +import java.util.List; +import java.util.Set; +import mate.academy.springboot.datajpa.model.Product; + +public interface ProductService { + Product create(Product product); + + Product findById(Long id); + + Product update(Long id, Product product); + + void deleteById(Long id); + + List getAllByPriceBetween(BigDecimal priceFrom, BigDecimal priceTo); + + List getAllByCategoryIds(Set categoryIds); +} diff --git a/src/main/java/mate/academy/springboot/datajpa/service/ProductServiceImpl.java b/src/main/java/mate/academy/springboot/datajpa/service/ProductServiceImpl.java new file mode 100644 index 00000000..f224fde2 --- /dev/null +++ b/src/main/java/mate/academy/springboot/datajpa/service/ProductServiceImpl.java @@ -0,0 +1,55 @@ +package mate.academy.springboot.datajpa.service; + +import java.math.BigDecimal; +import java.util.List; +import java.util.NoSuchElementException; +import java.util.Set; +import lombok.AllArgsConstructor; +import mate.academy.springboot.datajpa.model.Product; +import mate.academy.springboot.datajpa.repository.ProductRepository; +import org.springframework.stereotype.Service; + +@Service +@AllArgsConstructor +public class ProductServiceImpl implements ProductService { + private final ProductRepository productRepository; + + @Override + public Product create(Product product) { + return productRepository.save(product); + } + + @Override + public Product findById(Long id) { + return productRepository.findById(id).orElseThrow(() -> + new NoSuchElementException("Can't find product with id " + id)); + } + + @Override + public Product update(Long id, Product product) { + if (product == null) { + throw new IllegalArgumentException("Product can't be null"); + } + Product productFromDb = productRepository.findById(id).orElseThrow(() -> + new NoSuchElementException("Can't find product with id " + id)); + productFromDb.setCategory(product.getCategory()); + productFromDb.setTitle(product.getTitle()); + productFromDb.setPrice(product.getPrice()); + return productRepository.save(productFromDb); + } + + @Override + public void deleteById(Long id) { + productRepository.deleteById(id); + } + + @Override + public List getAllByPriceBetween(BigDecimal priceFrom, BigDecimal priceTo) { + return productRepository.getAllByPriceBetween(priceFrom, priceTo); + } + + @Override + public List getAllByCategoryIds(Set categoryIds) { + return productRepository.getAllByCategoryIdIn(categoryIds); + } +} diff --git a/src/main/java/mate/academy/springboot/datajpa/service/mapper/CategoryMapper.java b/src/main/java/mate/academy/springboot/datajpa/service/mapper/CategoryMapper.java new file mode 100644 index 00000000..716cd7c1 --- /dev/null +++ b/src/main/java/mate/academy/springboot/datajpa/service/mapper/CategoryMapper.java @@ -0,0 +1,15 @@ +package mate.academy.springboot.datajpa.service.mapper; + +import mate.academy.springboot.datajpa.config.MapperConfig; +import mate.academy.springboot.datajpa.dto.CategoryRequestDto; +import mate.academy.springboot.datajpa.dto.CategoryResponseDto; +import mate.academy.springboot.datajpa.model.Category; +import org.mapstruct.Mapper; + +@Mapper(config = MapperConfig.class) +public interface CategoryMapper extends DtoMapper< + CategoryResponseDto, Category, CategoryRequestDto> { + CategoryResponseDto toDto(Category category); + + Category toEntity(CategoryRequestDto categoryRequestDto); +} diff --git a/src/main/java/mate/academy/springboot/datajpa/service/mapper/DtoMapper.java b/src/main/java/mate/academy/springboot/datajpa/service/mapper/DtoMapper.java new file mode 100644 index 00000000..5459eb33 --- /dev/null +++ b/src/main/java/mate/academy/springboot/datajpa/service/mapper/DtoMapper.java @@ -0,0 +1,7 @@ +package mate.academy.springboot.datajpa.service.mapper; + +public interface DtoMapper { + ResponseT toDto(EntityT entity); + + EntityT toEntity(RequestT request); +} diff --git a/src/main/java/mate/academy/springboot/datajpa/service/mapper/ProductMapper.java b/src/main/java/mate/academy/springboot/datajpa/service/mapper/ProductMapper.java new file mode 100644 index 00000000..dc533b94 --- /dev/null +++ b/src/main/java/mate/academy/springboot/datajpa/service/mapper/ProductMapper.java @@ -0,0 +1,17 @@ +package mate.academy.springboot.datajpa.service.mapper; + +import mate.academy.springboot.datajpa.config.MapperConfig; +import mate.academy.springboot.datajpa.dto.ProductRequestDto; +import mate.academy.springboot.datajpa.dto.ProductResponseDto; +import mate.academy.springboot.datajpa.model.Product; +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; + +@Mapper(config = MapperConfig.class) +public interface ProductMapper extends DtoMapper { + @Mapping(target = "categoryId", source = "category.id") + ProductResponseDto toDto(Product product); + + @Mapping(source = "categoryId", target = "category.id") + Product toEntity(ProductRequestDto productRequestDto); +} diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 8b137891..6df03fa1 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -1 +1,9 @@ +spring.datasource.url=jdbc:h2:mem:testdb +spring.datasource.driverClassName=org.h2.Driver +spring.datasource.username=sa +spring.datasource.password=password +spring.jpa.show-sql=true +spring.jpa.properties.hibernate.format_sql=true +spring.jpa.database-platform=org.hibernate.dialect.H2Dialect +spring.h2.console.enabled=true From 7c79043b6b125b61eddcabb4fe9394038f902c8b Mon Sep 17 00:00:00 2001 From: viprko Date: Wed, 16 Aug 2023 13:25:29 +0300 Subject: [PATCH 2/2] removed unnecessary code --- .../mate/academy/springboot/datajpa/model/Category.java | 6 ++++-- .../java/mate/academy/springboot/datajpa/model/Product.java | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/main/java/mate/academy/springboot/datajpa/model/Category.java b/src/main/java/mate/academy/springboot/datajpa/model/Category.java index a8a4b3b4..736f76c1 100644 --- a/src/main/java/mate/academy/springboot/datajpa/model/Category.java +++ b/src/main/java/mate/academy/springboot/datajpa/model/Category.java @@ -5,9 +5,11 @@ import jakarta.persistence.GenerationType; import jakarta.persistence.Id; import jakarta.persistence.Table; -import lombok.Data; +import lombok.Getter; +import lombok.Setter; -@Data +@Getter +@Setter @Entity @Table(name = "categories") public class Category { diff --git a/src/main/java/mate/academy/springboot/datajpa/model/Product.java b/src/main/java/mate/academy/springboot/datajpa/model/Product.java index 8c2502b6..8b6eaa09 100644 --- a/src/main/java/mate/academy/springboot/datajpa/model/Product.java +++ b/src/main/java/mate/academy/springboot/datajpa/model/Product.java @@ -7,9 +7,11 @@ import jakarta.persistence.ManyToOne; import jakarta.persistence.Table; import java.math.BigDecimal; -import lombok.Data; +import lombok.Getter; +import lombok.Setter; -@Data +@Getter +@Setter @Entity @Table(name = "products") public class Product {