From 79e97340cc7f840b767716bd71b07452c834f94f Mon Sep 17 00:00:00 2001 From: TugbaDalmaz <89070914+TugbaDalmaz@users.noreply.github.com> Date: Mon, 30 Aug 2021 09:11:21 +0200 Subject: [PATCH 1/9] Change Animal to Product --- .../domain/model/AnimalSearchCriteria.java | 17 --- .../domain/repo/AnimalFragment.java | 16 -- .../domain/repo/AnimalFragmentImpl.java | 93 ------------ .../domain/repo/AnimalRepository.java | 16 -- .../demoquarkus/logic/UcFindAnimal.java | 23 --- .../demoquarkus/logic/UcFindAnimalImpl.java | 93 ------------ .../demoquarkus/logic/UcManageAnimal.java | 10 -- .../demoquarkus/logic/UcManageAnimalImpl.java | 38 ----- .../service/v1/AnimalRestService.java | 132 ---------------- .../service/v1/mapper/AnimalMapper.java | 21 --- .../service/v1/model/AnimalDto.java | 18 --- .../v1/model/AnimalSearchCriteriaDto.java | 26 ---- .../service/v1/model/NewAnimalDto.java | 22 --- .../productmanagement/ApplicationEntity.java | 8 + .../ApplicationPersistenceEntity.java | 87 +++++++++++ .../productmanagement}/DemoApplication.java | 4 +- .../productmanagement/GenericEntity.java | 81 ++++++++++ .../domain/model/ProductEntity.java} | 21 ++- .../domain/model/ProductSearchCriteria.java | 23 +++ .../domain/repo/ProductFragment.java | 16 ++ .../domain/repo/ProductFragmentImpl.java | 117 ++++++++++++++ .../domain/repo/ProductRepository.java | 20 +++ .../logic/UcFindProduct.java | 28 ++++ .../logic/UcFindProductImpl.java | 103 +++++++++++++ .../logic/UcManageProduct.java | 10 ++ .../logic/UcManageProductImpl.java | 38 +++++ .../service/v1/ProductRestService.java | 143 ++++++++++++++++++ .../service/v1/mapper/ProductMapper.java | 21 +++ .../service/v1/model/NewProductDto.java | 23 +++ .../service/v1/model/ProductDto.java | 24 +++ .../v1/model/ProductSearchCriteriaDto.java | 40 +++++ ...eTest.java => ProductRestServiceTest.java} | 53 ++++--- 32 files changed, 826 insertions(+), 559 deletions(-) delete mode 100644 src/main/java/com/devonfw/demoquarkus/domain/model/AnimalSearchCriteria.java delete mode 100644 src/main/java/com/devonfw/demoquarkus/domain/repo/AnimalFragment.java delete mode 100644 src/main/java/com/devonfw/demoquarkus/domain/repo/AnimalFragmentImpl.java delete mode 100644 src/main/java/com/devonfw/demoquarkus/domain/repo/AnimalRepository.java delete mode 100644 src/main/java/com/devonfw/demoquarkus/logic/UcFindAnimal.java delete mode 100644 src/main/java/com/devonfw/demoquarkus/logic/UcFindAnimalImpl.java delete mode 100644 src/main/java/com/devonfw/demoquarkus/logic/UcManageAnimal.java delete mode 100644 src/main/java/com/devonfw/demoquarkus/logic/UcManageAnimalImpl.java delete mode 100644 src/main/java/com/devonfw/demoquarkus/service/v1/AnimalRestService.java delete mode 100644 src/main/java/com/devonfw/demoquarkus/service/v1/mapper/AnimalMapper.java delete mode 100644 src/main/java/com/devonfw/demoquarkus/service/v1/model/AnimalDto.java delete mode 100644 src/main/java/com/devonfw/demoquarkus/service/v1/model/AnimalSearchCriteriaDto.java delete mode 100644 src/main/java/com/devonfw/demoquarkus/service/v1/model/NewAnimalDto.java create mode 100644 src/main/java/com/devonfw/quarkus/productmanagement/ApplicationEntity.java create mode 100644 src/main/java/com/devonfw/quarkus/productmanagement/ApplicationPersistenceEntity.java rename src/main/java/com/devonfw/{demoquarkus => quarkus/productmanagement}/DemoApplication.java (69%) create mode 100644 src/main/java/com/devonfw/quarkus/productmanagement/GenericEntity.java rename src/main/java/com/devonfw/{demoquarkus/domain/model/AnimalEntity.java => quarkus/productmanagement/domain/model/ProductEntity.java} (52%) create mode 100644 src/main/java/com/devonfw/quarkus/productmanagement/domain/model/ProductSearchCriteria.java create mode 100644 src/main/java/com/devonfw/quarkus/productmanagement/domain/repo/ProductFragment.java create mode 100644 src/main/java/com/devonfw/quarkus/productmanagement/domain/repo/ProductFragmentImpl.java create mode 100644 src/main/java/com/devonfw/quarkus/productmanagement/domain/repo/ProductRepository.java create mode 100644 src/main/java/com/devonfw/quarkus/productmanagement/logic/UcFindProduct.java create mode 100644 src/main/java/com/devonfw/quarkus/productmanagement/logic/UcFindProductImpl.java create mode 100644 src/main/java/com/devonfw/quarkus/productmanagement/logic/UcManageProduct.java create mode 100644 src/main/java/com/devonfw/quarkus/productmanagement/logic/UcManageProductImpl.java create mode 100644 src/main/java/com/devonfw/quarkus/productmanagement/service/v1/ProductRestService.java create mode 100644 src/main/java/com/devonfw/quarkus/productmanagement/service/v1/mapper/ProductMapper.java create mode 100644 src/main/java/com/devonfw/quarkus/productmanagement/service/v1/model/NewProductDto.java create mode 100644 src/main/java/com/devonfw/quarkus/productmanagement/service/v1/model/ProductDto.java create mode 100644 src/main/java/com/devonfw/quarkus/productmanagement/service/v1/model/ProductSearchCriteriaDto.java rename src/test/java/com/devonfw/demoquarkus/service/v1/{AnimalRestServiceTest.java => ProductRestServiceTest.java} (61%) diff --git a/src/main/java/com/devonfw/demoquarkus/domain/model/AnimalSearchCriteria.java b/src/main/java/com/devonfw/demoquarkus/domain/model/AnimalSearchCriteria.java deleted file mode 100644 index 5e52f9fc..00000000 --- a/src/main/java/com/devonfw/demoquarkus/domain/model/AnimalSearchCriteria.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.devonfw.demoquarkus.domain.model; - -import lombok.Getter; -import lombok.Setter; - -@Getter -@Setter -public class AnimalSearchCriteria { - - private String name; - - private Integer numberOfLegs; - - private Integer pageNumber; - - private Integer pageSize; -} diff --git a/src/main/java/com/devonfw/demoquarkus/domain/repo/AnimalFragment.java b/src/main/java/com/devonfw/demoquarkus/domain/repo/AnimalFragment.java deleted file mode 100644 index 4bdc967b..00000000 --- a/src/main/java/com/devonfw/demoquarkus/domain/repo/AnimalFragment.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.devonfw.demoquarkus.domain.repo; - -import org.springframework.data.domain.Page; - -import com.devonfw.demoquarkus.domain.model.AnimalEntity; -import com.devonfw.demoquarkus.service.v1.model.AnimalSearchCriteriaDto; - -public interface AnimalFragment { - public Page findAllCriteriaApi(AnimalSearchCriteriaDto dto); - - public Page findAllQueryDsl(AnimalSearchCriteriaDto dto); - - public Page findByNameNativeQuery(AnimalSearchCriteriaDto dto); - - public Page findByNameQuery(AnimalSearchCriteriaDto dto); -} diff --git a/src/main/java/com/devonfw/demoquarkus/domain/repo/AnimalFragmentImpl.java b/src/main/java/com/devonfw/demoquarkus/domain/repo/AnimalFragmentImpl.java deleted file mode 100644 index e96b4a55..00000000 --- a/src/main/java/com/devonfw/demoquarkus/domain/repo/AnimalFragmentImpl.java +++ /dev/null @@ -1,93 +0,0 @@ -package com.devonfw.demoquarkus.domain.repo; - -import java.util.ArrayList; -import java.util.List; - -import javax.inject.Inject; -import javax.persistence.EntityManager; -import javax.persistence.Query; -import javax.persistence.TypedQuery; -import javax.persistence.criteria.CriteriaBuilder; -import javax.persistence.criteria.CriteriaQuery; -import javax.persistence.criteria.Predicate; -import javax.persistence.criteria.Root; - -import org.springframework.data.domain.Page; -import org.springframework.data.domain.PageImpl; -import org.springframework.data.domain.PageRequest; - -import com.devonfw.demoquarkus.domain.model.AnimalEntity; -import com.devonfw.demoquarkus.domain.model.AnimalEntity_; -import com.devonfw.demoquarkus.domain.model.QAnimalEntity; -import com.devonfw.demoquarkus.service.v1.model.AnimalSearchCriteriaDto; -import com.querydsl.jpa.impl.JPAQuery; - -public class AnimalFragmentImpl implements AnimalFragment { - - @Inject - EntityManager em; - - @Override - public Page findAllCriteriaApi(AnimalSearchCriteriaDto dto) { - - CriteriaQuery cq = this.em.getCriteriaBuilder().createQuery(AnimalEntity.class); - Root root = cq.from(AnimalEntity.class); - List predicates = new ArrayList<>(); - CriteriaBuilder cb = this.em.getCriteriaBuilder(); - if (dto.getName() != null && !dto.getName().isEmpty()) { - predicates.add(cb.like(root.get(AnimalEntity_.NAME), dto.getName())); - } - if (dto.getNumberOfLegs() != null) { - predicates.add(cb.equal(root.get(AnimalEntity_.NUMBER_OF_LEGS), dto.getNumberOfLegs())); - } - if (!predicates.isEmpty()) { - cq.where(predicates.toArray(new Predicate[0])); - } - - // Order by name - cq.orderBy(cb.desc(root.get(AnimalEntity_.NAME))); - - TypedQuery animals = this.em.createQuery(cq).setFirstResult(dto.getPageNumber() * dto.getPageSize()) - .setMaxResults(dto.getPageSize()); - return new PageImpl(animals.getResultList(), PageRequest.of(dto.getPageNumber(), dto.getPageSize()), - animals.getResultList().size()); - } - - @Override - public Page findAllQueryDsl(AnimalSearchCriteriaDto dto) { - - QAnimalEntity animal = QAnimalEntity.animalEntity; - JPAQuery query = new JPAQuery(this.em); - query.from(animal); - if (dto.getName() != null && !dto.getName().isEmpty()) { - query.where(animal.name.eq(dto.getName())); - } - if (dto.getNumberOfLegs() != null) { - query.where(animal.numberOfLegs.eq(dto.getNumberOfLegs())); - } - - // Order by name - query.orderBy(animal.name.desc()); - - List animals = query.limit(dto.getPageSize()).offset(dto.getPageNumber() * dto.getPageSize()).fetch(); - return new PageImpl<>(animals, PageRequest.of(dto.getPageNumber(), dto.getPageSize()), animals.size()); - } - - @Override - public Page findByNameQuery(AnimalSearchCriteriaDto dto) { - - Query query = this.em.createQuery("select a from AnimalEntity a where a.name = :name"); - query.setParameter("name", dto.getName()); - List animals = query.getResultList(); - return new PageImpl<>(animals, PageRequest.of(dto.getPageNumber(), dto.getPageSize()), animals.size()); - } - - @Override - public Page findByNameNativeQuery(AnimalSearchCriteriaDto dto) { - - Query query = this.em.createNativeQuery("select * from AnimalEntity where name = :name", AnimalEntity.class); - query.setParameter("name", dto.getName()); - List animals = query.getResultList(); - return new PageImpl<>(animals, PageRequest.of(dto.getPageNumber(), dto.getPageSize()), animals.size()); - } -} diff --git a/src/main/java/com/devonfw/demoquarkus/domain/repo/AnimalRepository.java b/src/main/java/com/devonfw/demoquarkus/domain/repo/AnimalRepository.java deleted file mode 100644 index 11151c8a..00000000 --- a/src/main/java/com/devonfw/demoquarkus/domain/repo/AnimalRepository.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.devonfw.demoquarkus.domain.repo; - -import org.springframework.data.domain.Page; -import org.springframework.data.jpa.repository.Query; -import org.springframework.data.repository.CrudRepository; -import org.springframework.data.repository.query.Param; - -import com.devonfw.demoquarkus.domain.model.AnimalEntity; - -public interface AnimalRepository extends CrudRepository, AnimalFragment { - - @Query("select a from AnimalEntity a where name = :name") - AnimalEntity findByName(@Param("name") String name); - - Page findAllByOrderByName(); -} diff --git a/src/main/java/com/devonfw/demoquarkus/logic/UcFindAnimal.java b/src/main/java/com/devonfw/demoquarkus/logic/UcFindAnimal.java deleted file mode 100644 index f45c0954..00000000 --- a/src/main/java/com/devonfw/demoquarkus/logic/UcFindAnimal.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.devonfw.demoquarkus.logic; - -import com.devonfw.demoquarkus.service.v1.model.AnimalDto; -import com.devonfw.demoquarkus.service.v1.model.AnimalSearchCriteriaDto; -import org.springframework.data.domain.Page; - -public interface UcFindAnimal { - Page findAnimals(AnimalSearchCriteriaDto dto); - - Page findAnimalsByCriteriaApi(AnimalSearchCriteriaDto dto); - - Page findAnimalsByQueryDsl(AnimalSearchCriteriaDto dto); - - Page findAnimalsByNameQuery(AnimalSearchCriteriaDto dto); - - Page findAnimalsByNameNativeQuery(AnimalSearchCriteriaDto dto); - - Page findAnimalsOrderedByName(); - - AnimalDto findAnimal(String id); - - AnimalDto findAnimalByName(String name); -} diff --git a/src/main/java/com/devonfw/demoquarkus/logic/UcFindAnimalImpl.java b/src/main/java/com/devonfw/demoquarkus/logic/UcFindAnimalImpl.java deleted file mode 100644 index 086f854f..00000000 --- a/src/main/java/com/devonfw/demoquarkus/logic/UcFindAnimalImpl.java +++ /dev/null @@ -1,93 +0,0 @@ -package com.devonfw.demoquarkus.logic; - -import com.devonfw.demoquarkus.domain.model.AnimalEntity; -import com.devonfw.demoquarkus.domain.repo.AnimalRepository; -import com.devonfw.demoquarkus.service.v1.mapper.AnimalMapper; -import com.devonfw.demoquarkus.service.v1.model.AnimalDto; -import com.devonfw.demoquarkus.service.v1.model.AnimalSearchCriteriaDto; -import lombok.extern.slf4j.Slf4j; -import org.springframework.data.domain.Page; -import org.springframework.data.domain.PageImpl; -import org.springframework.data.domain.PageRequest; - -import javax.inject.Inject; -import javax.inject.Named; -import javax.transaction.Transactional; -import java.util.ArrayList; -import java.util.List; - -@Named -@Transactional -@Slf4j -public class UcFindAnimalImpl implements UcFindAnimal { - @Inject - AnimalRepository animalRepository; - - @Inject - AnimalMapper mapper; - - @Override - public Page findAnimals(AnimalSearchCriteriaDto dto) { - Iterable animalsIterator = this.animalRepository.findAll(); - List animals = new ArrayList(); - animalsIterator.forEach(animals::add); - List animalsDto = this.mapper.map(animals); - return new PageImpl<>(animalsDto, PageRequest.of(dto.getPageNumber(), dto.getPageSize()), animalsDto.size()); - } - - @Override - public Page findAnimalsByCriteriaApi(AnimalSearchCriteriaDto dto) { - List animals = this.animalRepository.findAllCriteriaApi(dto).getContent(); - List animalsDto = this.mapper.map(animals); - return new PageImpl<>(animalsDto, PageRequest.of(dto.getPageNumber(), dto.getPageSize()), animalsDto.size()); - } - - @Override - public Page findAnimalsByQueryDsl(AnimalSearchCriteriaDto dto) { - List animals = this.animalRepository.findAllQueryDsl(dto).getContent(); - List animalsDto = this.mapper.map(animals); - return new PageImpl<>(animalsDto, PageRequest.of(dto.getPageNumber(), dto.getPageSize()), animalsDto.size()); - } - - @Override - public Page findAnimalsByNameQuery(AnimalSearchCriteriaDto dto) { - List animals = this.animalRepository.findByNameQuery(dto).getContent(); - List animalsDto = this.mapper.map(animals); - return new PageImpl<>(animalsDto, PageRequest.of(dto.getPageNumber(), dto.getPageSize()), animalsDto.size()); - } - - @Override - public Page findAnimalsByNameNativeQuery(AnimalSearchCriteriaDto dto) { - List animals = this.animalRepository.findByNameNativeQuery(dto).getContent(); - List animalsDto = this.mapper.map(animals); - return new PageImpl<>(animalsDto, PageRequest.of(dto.getPageNumber(), dto.getPageSize()), animalsDto.size()); - } - - @Override - public Page findAnimalsOrderedByName() { - List animals = this.animalRepository.findAllByOrderByName().getContent(); - List animalsDto = this.mapper.map(animals); - return new PageImpl<>(animalsDto); - } - - @Override - public AnimalDto findAnimal(String id) { - AnimalEntity animal = this.animalRepository.findById(Long.valueOf(id)).get(); - if (animal != null) { - return this.mapper.map(animal); - } else { - return null; - } - } - - @Override - public AnimalDto findAnimalByName(String name) { - AnimalEntity animal = this.animalRepository.findByName(name); - if (animal != null) { - return this.mapper.map(animal); - } else { - return null; - } - } - -} diff --git a/src/main/java/com/devonfw/demoquarkus/logic/UcManageAnimal.java b/src/main/java/com/devonfw/demoquarkus/logic/UcManageAnimal.java deleted file mode 100644 index 0e65dc64..00000000 --- a/src/main/java/com/devonfw/demoquarkus/logic/UcManageAnimal.java +++ /dev/null @@ -1,10 +0,0 @@ -package com.devonfw.demoquarkus.logic; - -import com.devonfw.demoquarkus.service.v1.model.AnimalDto; -import com.devonfw.demoquarkus.service.v1.model.NewAnimalDto; - -public interface UcManageAnimal { - AnimalDto saveAnimal(NewAnimalDto dto); - - AnimalDto deleteAnimal(String id); -} diff --git a/src/main/java/com/devonfw/demoquarkus/logic/UcManageAnimalImpl.java b/src/main/java/com/devonfw/demoquarkus/logic/UcManageAnimalImpl.java deleted file mode 100644 index 38047b1c..00000000 --- a/src/main/java/com/devonfw/demoquarkus/logic/UcManageAnimalImpl.java +++ /dev/null @@ -1,38 +0,0 @@ -package com.devonfw.demoquarkus.logic; - -import com.devonfw.demoquarkus.domain.model.AnimalEntity; -import com.devonfw.demoquarkus.domain.repo.AnimalRepository; -import com.devonfw.demoquarkus.service.v1.mapper.AnimalMapper; -import com.devonfw.demoquarkus.service.v1.model.AnimalDto; -import com.devonfw.demoquarkus.service.v1.model.NewAnimalDto; - -import javax.inject.Inject; -import javax.inject.Named; -import javax.transaction.Transactional; - -@Named -@Transactional -public class UcManageAnimalImpl implements UcManageAnimal { - @Inject - AnimalRepository animalRepository; - - @Inject - AnimalMapper mapper; - - @Override - public AnimalDto saveAnimal(NewAnimalDto dto) { - AnimalEntity created = this.animalRepository.save(this.mapper.create(dto)); - return this.mapper.map(created); - } - - @Override - public AnimalDto deleteAnimal(String id) { - AnimalEntity animal = this.animalRepository.findById(Long.valueOf(id)).get(); - if (animal != null) { - this.animalRepository.delete(animal); - return this.mapper.map(animal); - } else { - return null; - } - } -} diff --git a/src/main/java/com/devonfw/demoquarkus/service/v1/AnimalRestService.java b/src/main/java/com/devonfw/demoquarkus/service/v1/AnimalRestService.java deleted file mode 100644 index 350bb165..00000000 --- a/src/main/java/com/devonfw/demoquarkus/service/v1/AnimalRestService.java +++ /dev/null @@ -1,132 +0,0 @@ -package com.devonfw.demoquarkus.service.v1; - -import javax.inject.Inject; -import javax.ws.rs.BeanParam; -import javax.ws.rs.Consumes; -import javax.ws.rs.DELETE; -import javax.ws.rs.GET; -import javax.ws.rs.POST; -import javax.ws.rs.Path; -import javax.ws.rs.PathParam; -import javax.ws.rs.Produces; -import javax.ws.rs.core.Context; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.UriInfo; - -import com.devonfw.demoquarkus.logic.UcFindAnimal; -import com.devonfw.demoquarkus.logic.UcManageAnimal; -import com.devonfw.demoquarkus.service.v1.model.AnimalDto; -import com.devonfw.demoquarkus.service.v1.model.AnimalSearchCriteriaDto; -import com.devonfw.demoquarkus.service.v1.model.NewAnimalDto; -import org.eclipse.microprofile.openapi.annotations.Operation; -import org.eclipse.microprofile.openapi.annotations.media.Content; -import org.eclipse.microprofile.openapi.annotations.media.Schema; -import org.eclipse.microprofile.openapi.annotations.parameters.Parameter; -import org.eclipse.microprofile.openapi.annotations.responses.APIResponse; -import org.eclipse.microprofile.openapi.annotations.responses.APIResponses; -import org.springframework.data.domain.PageImpl; -import org.tkit.quarkus.rs.models.PageResultDTO; - -//In Quarkus all JAX-RS resources are treated as CDI beans -//default is Singleton scope -@Path("/animals") -// how we serialize response -@Produces(MediaType.APPLICATION_JSON) -// how we deserialize params -@Consumes(MediaType.APPLICATION_JSON) -public class AnimalRestService { - - // using @Context we can inject contextual info from JAXRS(e.g. http request, current uri info, endpoint info...) - @Context - UriInfo uriInfo; - - @Inject - UcFindAnimal ucFindAnimal; - - @Inject - UcManageAnimal ucManageAnimal; - - @APIResponses({ - @APIResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = PagedAnimalResponse.class))), - @APIResponse(responseCode = "500")}) - @Operation(operationId = "Get Animals", description = "Returns list of animals matching given criteria, uses pagination") - @GET - // REST service methods should not declare exceptions, any thrown error will be transformed by exceptionMapper in - // tkit-rest - // We did not define custom @Path - so it will use class level path - public PageImpl getAll(@BeanParam AnimalSearchCriteriaDto dto) { - return (PageImpl) ucFindAnimal.findAnimals(dto); - } - - @GET - @Path("criteriaApi") - public PageImpl getAllCriteriaApi(@BeanParam AnimalSearchCriteriaDto dto) { - return (PageImpl) ucFindAnimal.findAnimalsByCriteriaApi(dto); - } - - @GET - @Path("queryDsl") - public PageImpl getAllQueryDsl(@BeanParam AnimalSearchCriteriaDto dto) { - return (PageImpl) ucFindAnimal.findAnimalsByQueryDsl(dto); - } - - @GET - @Path("query") - public PageImpl getAllQuery(@BeanParam AnimalSearchCriteriaDto dto) { - return (PageImpl) ucFindAnimal.findAnimalsByNameQuery(dto); - } - - @GET - @Path("nativeQuery") - public PageImpl getAllNativeQuery(@BeanParam AnimalSearchCriteriaDto dto) { - return (PageImpl) ucFindAnimal.findAnimalsByNameNativeQuery(dto); - } - - @GET - @Path("ordered") - public PageImpl getAllOrderedByName() { - return (PageImpl) ucFindAnimal.findAnimalsOrderedByName(); - } - - @APIResponses({ - @APIResponse(responseCode = "201", description = "OK, New animal created", content = @Content(schema = @Schema(implementation = NewAnimalDto.class))), - @APIResponse(responseCode = "400", description = "Client side error, invalid request"), - @APIResponse(responseCode = "500")}) - @Operation(operationId = "createNewAnimal", description = "Stores new animal in DB") - @POST - // We did not define custom @Path - so it will use class level path. - // Although we now have 2 methods with same path, it is ok, because it is a different method (get vs post) - public AnimalDto createNewAnimal(NewAnimalDto dto) { - return ucManageAnimal.saveAnimal(dto); - } - - @APIResponses({ - @APIResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = AnimalDto.class))), - @APIResponse(responseCode = "404", description = "Animal not found"), @APIResponse(responseCode = "500")}) - @Operation(operationId = "getAnimalById", description = "Returns animal with given id") - @GET - @Path("{id}") - public AnimalDto getAnimalById(@Parameter(description = "Animal unique id") @PathParam("id") String id) { - return ucFindAnimal.findAnimal(id); - } - - @GET - @Path("name/{name}") - public AnimalDto getAnimalByName(@PathParam("name") String name) { - return ucFindAnimal.findAnimalByName(name); - } - - @APIResponses({ - @APIResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = AnimalDto.class))), - @APIResponse(responseCode = "404", description = "Animal not found"), @APIResponse(responseCode = "500")}) - @Operation(operationId = "deleteAnimalById", description = "Deletes the animal with given id") - @DELETE - @Path("{id}") - public AnimalDto deleteAnimalById(@Parameter(description = "Animal unique id") @PathParam("id") String id) { - return ucManageAnimal.deleteAnimal(id); - } - - private static class PagedAnimalResponse extends PageResultDTO { - } - -} diff --git a/src/main/java/com/devonfw/demoquarkus/service/v1/mapper/AnimalMapper.java b/src/main/java/com/devonfw/demoquarkus/service/v1/mapper/AnimalMapper.java deleted file mode 100644 index 32e9a02b..00000000 --- a/src/main/java/com/devonfw/demoquarkus/service/v1/mapper/AnimalMapper.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.devonfw.demoquarkus.service.v1.mapper; - -import java.util.List; - -import org.mapstruct.Mapper; -import org.tkit.quarkus.rs.mappers.OffsetDateTimeMapper; - -import com.devonfw.demoquarkus.domain.model.AnimalEntity; -import com.devonfw.demoquarkus.service.v1.model.AnimalDto; -import com.devonfw.demoquarkus.service.v1.model.NewAnimalDto; - -//mapstruct will generate an impl class(CDI bean, see pom.xml) from this interface at compile time -@Mapper(uses = OffsetDateTimeMapper.class) -public interface AnimalMapper { - - AnimalDto map(AnimalEntity model); - - AnimalEntity create(NewAnimalDto dto); - - List map(List animals); -} diff --git a/src/main/java/com/devonfw/demoquarkus/service/v1/model/AnimalDto.java b/src/main/java/com/devonfw/demoquarkus/service/v1/model/AnimalDto.java deleted file mode 100644 index dffa5b28..00000000 --- a/src/main/java/com/devonfw/demoquarkus/service/v1/model/AnimalDto.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.devonfw.demoquarkus.service.v1.model; - -import lombok.Getter; -import lombok.Setter; - -@Getter -@Setter -public class AnimalDto { - - private Long id; - - private String name; - - private String basicInfo; - - private int numberOfLegs; - -} diff --git a/src/main/java/com/devonfw/demoquarkus/service/v1/model/AnimalSearchCriteriaDto.java b/src/main/java/com/devonfw/demoquarkus/service/v1/model/AnimalSearchCriteriaDto.java deleted file mode 100644 index eb9868bb..00000000 --- a/src/main/java/com/devonfw/demoquarkus/service/v1/model/AnimalSearchCriteriaDto.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.devonfw.demoquarkus.service.v1.model; - -import javax.ws.rs.DefaultValue; -import javax.ws.rs.QueryParam; - -import lombok.Getter; -import lombok.Setter; - -@Getter -@Setter -public class AnimalSearchCriteriaDto { - - @QueryParam("name") - private String name; - - @QueryParam("legs") - private Integer numberOfLegs; - - @QueryParam("page") - @DefaultValue("0") - private int pageNumber = 0; - - @QueryParam("size") - @DefaultValue("10") - private int pageSize = 10; -} diff --git a/src/main/java/com/devonfw/demoquarkus/service/v1/model/NewAnimalDto.java b/src/main/java/com/devonfw/demoquarkus/service/v1/model/NewAnimalDto.java deleted file mode 100644 index 2075515d..00000000 --- a/src/main/java/com/devonfw/demoquarkus/service/v1/model/NewAnimalDto.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.devonfw.demoquarkus.service.v1.model; - -import org.eclipse.microprofile.openapi.annotations.enums.SchemaType; -import org.eclipse.microprofile.openapi.annotations.media.Schema; - -import lombok.Getter; -import lombok.Setter; - -@Getter -@Setter -public class NewAnimalDto { - - @Schema(nullable = false, description = "Animal name", minLength = 3, maxLength = 50) - private String name; - - @Schema(description = "Animal tag line", minLength = 3, maxLength = 50) - private String basicInfo; - - @Schema(type = SchemaType.INTEGER, description = "How many legs does the animal have", example = "3") - private int numberOfLegs; - -} diff --git a/src/main/java/com/devonfw/quarkus/productmanagement/ApplicationEntity.java b/src/main/java/com/devonfw/quarkus/productmanagement/ApplicationEntity.java new file mode 100644 index 00000000..728f3f10 --- /dev/null +++ b/src/main/java/com/devonfw/quarkus/productmanagement/ApplicationEntity.java @@ -0,0 +1,8 @@ +package com.devonfw.quarkus.productmanagement; + +/** + * This is the abstract interface for a {@link GenericEntity}. We are using {@link Long} for all {@link #getId() primary + * keys}. + */ +public abstract interface ApplicationEntity extends GenericEntity { +} \ No newline at end of file diff --git a/src/main/java/com/devonfw/quarkus/productmanagement/ApplicationPersistenceEntity.java b/src/main/java/com/devonfw/quarkus/productmanagement/ApplicationPersistenceEntity.java new file mode 100644 index 00000000..68b0cdce --- /dev/null +++ b/src/main/java/com/devonfw/quarkus/productmanagement/ApplicationPersistenceEntity.java @@ -0,0 +1,87 @@ +package com.devonfw.quarkus.productmanagement; +//package com.devonfw.application.jtqj.general.dataaccess.api; + +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.MappedSuperclass; +import javax.persistence.Transient; +import javax.persistence.Version; + +//import com.devonfw.application.jtqj.general.common.api.ApplicationEntity; +//import com.devonfw.module.basic.common.api.entity.PersistenceEntity; + +/** + * Abstract base class for all {@link PersistenceEntity persistence entities} with an {@link #getId() id} and a + * {@link #getModificationCounter() modificationCounter} (version) field. All persistence entities of this application + * should inherit from this class. It is using JPA annotations at the getters what has several advantages but also + * implies that you have to annotate transient getter methods with the {@link Transient} annotation. + */ +@MappedSuperclass +public abstract class ApplicationPersistenceEntity implements ApplicationEntity { + + private static final long serialVersionUID = 1L; + + private Long id; + + private int modificationCounter; + + /** + * The constructor. + */ + public ApplicationPersistenceEntity() { + + super(); + } + + @Override + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + public Long getId() { + + return this.id; + } + + @Override + public void setId(Long id) { + + this.id = id; + } + + @Override + @Version + public int getModificationCounter() { + + return this.modificationCounter; + } + + @Override + public void setModificationCounter(int version) { + + this.modificationCounter = version; + } + + @Override + public String toString() { + + StringBuilder buffer = new StringBuilder(); + toString(buffer); + return buffer.toString(); + } + + /** + * Method to extend {@link #toString()} logic. + * + * @param buffer is the {@link StringBuilder} where to {@link StringBuilder#append(Object) append} the string + * representation. + */ + protected void toString(StringBuilder buffer) { + + buffer.append(getClass().getSimpleName()); + if (this.id != null) { + buffer.append("[id="); + buffer.append(this.id); + buffer.append("]"); + } + } +} \ No newline at end of file diff --git a/src/main/java/com/devonfw/demoquarkus/DemoApplication.java b/src/main/java/com/devonfw/quarkus/productmanagement/DemoApplication.java similarity index 69% rename from src/main/java/com/devonfw/demoquarkus/DemoApplication.java rename to src/main/java/com/devonfw/quarkus/productmanagement/DemoApplication.java index 4a5bd688..ddece7d8 100644 --- a/src/main/java/com/devonfw/demoquarkus/DemoApplication.java +++ b/src/main/java/com/devonfw/quarkus/productmanagement/DemoApplication.java @@ -1,4 +1,4 @@ -package com.devonfw.demoquarkus; +package com.devonfw.quarkus.productmanagement; import javax.ws.rs.core.Application; @@ -8,7 +8,7 @@ import org.eclipse.microprofile.openapi.annotations.tags.Tag; @OpenAPIDefinition(tags = { -@Tag(name = "animal", description = "Animal API.") }, info = @Info(title = "My Demo App RESTful API", version = "1.0.0", contact = @Contact(name = "API Support", email = "support@acme.com"))) +@Tag(name = "Product", description = "Product API.") }, info = @Info(title = "My Demo App RESTful API", version = "1.0.0", contact = @Contact(name = "API Support", email = "support@acme.com"))) /** * JaxRS application is not required in quarkus, but it is useful to place central API docs somewhere. We could also use * package-info.java for this. diff --git a/src/main/java/com/devonfw/quarkus/productmanagement/GenericEntity.java b/src/main/java/com/devonfw/quarkus/productmanagement/GenericEntity.java new file mode 100644 index 00000000..d76a9045 --- /dev/null +++ b/src/main/java/com/devonfw/quarkus/productmanagement/GenericEntity.java @@ -0,0 +1,81 @@ +package com.devonfw.quarkus.productmanagement; + +import java.io.Serializable; + +/** + * This is the interface for an entity, which is an object that is potentially stored in a persistent store (typically a + * database via JPA). Every non-abstract implementation of this interface is simply called an entity. It is + * supposed to be a simple java bean.
+ * This interface makes the following assumptions: + *
    + *
  • A {@link GenericEntity} is identified by a {@link #getId() primary key}.
  • + *
  • A {@link GenericEntity} has a {@link #getModificationCounter() modification counter} for optimistic locking (even + * though not strictly required - you could statically return 0).
  • + *
+ * ATTENTION:
+ * An instance of this interface is typically one of the following: + *
    + *
  • a JPA {@link javax.persistence.Entity}
    + *
  • a {@link com.devonfw.module.basic.common.api.to.AbstractEto entity transfer-object}
    + *
+ * In order to distinguish the above cases an application has an architecture that organizes the code in technical + * layers (see multilayered architecture) and + * business oriented slices (business components). Therefore within the persistence layer instances should always be + * {@link javax.persistence.Entity persistence entities}. On the other hand the higher layers always need to use + * {@link com.devonfw.module.basic.common.api.to.AbstractTo transfer-objects}. Our recommendation is to map between + * these two in the logic-layer using the {@code BeanMapper} component from the {@code devon4j-beanmapping} module. + * + * @see javax.persistence.Entity + * + * @param is the type of the {@link #getId() primary key}. + * + * @since 3.0.0 + */ +public interface GenericEntity extends Serializable { + + /** + * @return the primary key (unique identifier) of this entity. May be {@code null} if this entity is transient (not + * yet {@link javax.persistence.EntityManager#persist(Object) saved} in the database). While this method is + * initially defined in a generic way, it is strongly recommended to use {@link Long} as datatype for IDs. + *
+ * Even if you want to have a {@link String}-based business-oriented identifier it is best practice to use a + * {@link Long} as primary key and add the business identifier as additional field (with a unique constraint). + * This way references to the entity will be a lot more compact and improve your performance in JOINs or the + * like. However, there may be reasons to use other datatypes for the ID. In any case the unique ID should be + * an immutable java-object that can be rebuild from its {@link Object#toString() string-representation}.
+ * Please note that if your ID has a specific syntax, semantic, formatting rules, etc. you should create a + * custom datatype for it. If it can easily be mapped to a {@link Long} value you can still use {@link Long} + * here and provide a transient getter method that returns the your custom datatype from the {@link Long}. + * @see javax.persistence.Id + */ + ID getId(); + + /** + * @param id the new {@link #getId() primary key}. This method shall typically only be used by technical frameworks + * such as hibernate. + */ + void setId(ID id); + + /** + * This method gets the current modification-counter of this entity. Whenever the object gets modified and + * {@link javax.persistence.EntityManager#persist(Object) persisted}, this counter will be increased (typically after + * the transaction is closed). The initial value after construction is {@code 0}.
+ * This property is often simply called {@link javax.persistence.Version version}. However, as this sometimes causes + * confusion or may conflict with a business property "version", we use the more technical and self-explanatory name + * {@code modificationCounter}.
+ * If this feature is NOT supported for some reason, this method should always return {@code 0}. + * + * @see javax.persistence.Version + * + * @return the current modification-counter. + * @see javax.persistence.Version + */ + int getModificationCounter(); + + /** + * @param modificationCounter the new {@link #getModificationCounter() modification counter}. This method shall + * typically only be used by technical frameworks such as hibernate. + */ + void setModificationCounter(int modificationCounter); + +} \ No newline at end of file diff --git a/src/main/java/com/devonfw/demoquarkus/domain/model/AnimalEntity.java b/src/main/java/com/devonfw/quarkus/productmanagement/domain/model/ProductEntity.java similarity index 52% rename from src/main/java/com/devonfw/demoquarkus/domain/model/AnimalEntity.java rename to src/main/java/com/devonfw/quarkus/productmanagement/domain/model/ProductEntity.java index 967f347f..fc333987 100644 --- a/src/main/java/com/devonfw/demoquarkus/domain/model/AnimalEntity.java +++ b/src/main/java/com/devonfw/quarkus/productmanagement/domain/model/ProductEntity.java @@ -1,30 +1,37 @@ -package com.devonfw.demoquarkus.domain.model; +package com.devonfw.quarkus.productmanagement.domain.model; + +import java.math.BigDecimal; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; import javax.persistence.Table; +import com.devonfw.quarkus.productmanagement.ApplicationPersistenceEntity; + import lombok.Getter; import lombok.Setter; @Getter @Setter @Entity -@Table(name="Animal") +@Table(name = "Product") // A JPA entity requires at least 2 things @Entity annotation and an ID // by default, the DB table will have the same name as our class -public class AnimalEntity { +public class ProductEntity extends ApplicationPersistenceEntity { @Id @GeneratedValue - private Long id; + // private Long id; - private String name; + private String title; - // every primitive attribute on this class will be represented as column in animal table + // every primitive attribute on this class will be represented as column in Product table private String basicInfo; - private int numberOfLegs; + // private int numberOfLegs; + + private String description; + private BigDecimal price; } diff --git a/src/main/java/com/devonfw/quarkus/productmanagement/domain/model/ProductSearchCriteria.java b/src/main/java/com/devonfw/quarkus/productmanagement/domain/model/ProductSearchCriteria.java new file mode 100644 index 00000000..c7b1eead --- /dev/null +++ b/src/main/java/com/devonfw/quarkus/productmanagement/domain/model/ProductSearchCriteria.java @@ -0,0 +1,23 @@ +package com.devonfw.quarkus.productmanagement.domain.model; + +import java.math.BigDecimal; + +import lombok.Getter; +import lombok.Setter; + +@Getter +@Setter +public class ProductSearchCriteria { + + private String title; + + // private Integer numberOfLegs; + + private Integer pageNumber; + + private Integer pageSize; + + private String description; + + private BigDecimal price, priceMin, priceMax; +} diff --git a/src/main/java/com/devonfw/quarkus/productmanagement/domain/repo/ProductFragment.java b/src/main/java/com/devonfw/quarkus/productmanagement/domain/repo/ProductFragment.java new file mode 100644 index 00000000..576fba29 --- /dev/null +++ b/src/main/java/com/devonfw/quarkus/productmanagement/domain/repo/ProductFragment.java @@ -0,0 +1,16 @@ +package com.devonfw.quarkus.productmanagement.domain.repo; + +import org.springframework.data.domain.Page; + +import com.devonfw.quarkus.productmanagement.domain.model.ProductEntity; +import com.devonfw.quarkus.productmanagement.service.v1.model.ProductSearchCriteriaDto; + +public interface ProductFragment { + public Page findAllCriteriaApi(ProductSearchCriteriaDto dto); + + public Page findAllQueryDsl(ProductSearchCriteriaDto dto); + + public Page findByTitleNativeQuery(ProductSearchCriteriaDto dto); + + public Page findByTitleQuery(ProductSearchCriteriaDto dto); +} diff --git a/src/main/java/com/devonfw/quarkus/productmanagement/domain/repo/ProductFragmentImpl.java b/src/main/java/com/devonfw/quarkus/productmanagement/domain/repo/ProductFragmentImpl.java new file mode 100644 index 00000000..be45196e --- /dev/null +++ b/src/main/java/com/devonfw/quarkus/productmanagement/domain/repo/ProductFragmentImpl.java @@ -0,0 +1,117 @@ +package com.devonfw.quarkus.productmanagement.domain.repo; + +import java.math.BigDecimal; +import java.util.ArrayList; +import java.util.List; + +import javax.inject.Inject; +import javax.persistence.EntityManager; +import javax.persistence.Query; +import javax.persistence.TypedQuery; +import javax.persistence.criteria.CriteriaBuilder; +import javax.persistence.criteria.CriteriaQuery; +import javax.persistence.criteria.Predicate; +import javax.persistence.criteria.Root; + +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageImpl; +import org.springframework.data.domain.PageRequest; + +import com.devonfw.quarkus.productmanagement.domain.model.ProductEntity; +import com.devonfw.quarkus.productmanagement.domain.model.ProductEntity_; +import com.devonfw.quarkus.productmanagement.domain.model.QProductEntity; +import com.devonfw.quarkus.productmanagement.service.v1.model.ProductSearchCriteriaDto; +import com.querydsl.jpa.impl.JPAQuery; + +public class ProductFragmentImpl implements ProductFragment { + + @Inject + EntityManager em; + + @Override + public Page findAllCriteriaApi(ProductSearchCriteriaDto dto) { + + CriteriaQuery cq = this.em.getCriteriaBuilder().createQuery(ProductEntity.class); + Root root = cq.from(ProductEntity.class); + List predicates = new ArrayList<>(); + CriteriaBuilder cb = this.em.getCriteriaBuilder(); + if (dto.getTitle() != null && !dto.getTitle().isEmpty()) { + predicates.add(cb.like(root.get(ProductEntity_.TITLE), dto.getTitle())); + } + // if (dto.getNumberOfLegs() != null) { + // predicates.add(cb.equal(root.get(ProductEntity_.NUMBER_OF_LEGS), dto.getNumberOfLegs())); + // } + + BigDecimal price, priceMin, priceMax, x; + if (dto.getPriceMin() != null | dto.getPriceMax() != null) { + if (priceMin.compareTo(x) == 0 | priceMax.compareTo(x) == 0) { + price = x; + predicates.add(cb.equal(root.get(ProductEntity_.PRICE), dto.getPrice())); + } else if ((price.compareTo(priceMin) == 1) & (price.compareTo(priceMax) == -1)) { + predicates.add(cb.equal(root.get(ProductEntity_.PRICE), dto.getPrice())); + } + } + + if (!predicates.isEmpty()) { + cq.where(predicates.toArray(new Predicate[0])); + } + + // Order by title + cq.orderBy(cb.desc(root.get(ProductEntity_.TITLE))); + + TypedQuery Products = this.em.createQuery(cq).setFirstResult(dto.getPageNumber() * dto.getPageSize()) + .setMaxResults(dto.getPageSize()); + return new PageImpl(Products.getResultList(), PageRequest.of(dto.getPageNumber(), dto.getPageSize()), + Products.getResultList().size()); + } + + @Override + public Page findAllQueryDsl(ProductSearchCriteriaDto dto) { + + QProductEntity Product = QProductEntity.ProductEntity; + JPAQuery query = new JPAQuery(this.em); + query.from(Product); + if (dto.getTitle() != null && !dto.getTitle().isEmpty()) { + query.where(Product.title.eq(dto.getTitle())); + } + // if (dto.getNumberOfLegs() != null) { + // query.where(Product.numberOfLegs.eq(dto.getNumberOfLegs())); + // } + + BigDecimal price, priceMin, priceMax, x; + if (dto.getPriceMin() != null | dto.getPriceMax() != null) { + if (getPriceMin().compareTo(x) == 0 | priceMax.compareTo(x) == 0) { + price = x; + query.where(Product.price.eq(dto.getPrice())); + } else if ((price.compareTo(priceMin) == 1) & (price.compareTo(priceMax) == -1)) { + query.where(Product.price.eq(dto.getPrice())); + } + } + + // Order by title + query.orderBy(Product.title.desc()); + + List Products = query.limit(dto.getPageSize()).offset(dto.getPageNumber() * dto.getPageSize()) + .fetch(); + return new PageImpl<>(Products, PageRequest.of(dto.getPageNumber(), dto.getPageSize()), Products.size()); + } + + @Override + public Page findByTitleQuery(ProductSearchCriteriaDto dto) { + + Query query = this.em.createQuery("select a from ProductEntity a where a.title = :title"); + query.setParameter("title", dto.getTitle()); + List Products = query.getResultList(); + return new PageImpl<>(Products, PageRequest.of(dto.getPageNumber(), dto.getPageSize()), Products.size()); + } + + @Override + public Page findByTitleNativeQuery(ProductSearchCriteriaDto dto) { + + Query query = this.em.createNativeQuery("select * from ProductEntity where title = :title", ProductEntity.class); + query.setParameter("title", dto.getTitle()); + List Products = query.getResultList(); + return new PageImpl<>(Products, PageRequest.of(dto.getPageNumber(), dto.getPageSize()), Products.size()); + } + +} diff --git a/src/main/java/com/devonfw/quarkus/productmanagement/domain/repo/ProductRepository.java b/src/main/java/com/devonfw/quarkus/productmanagement/domain/repo/ProductRepository.java new file mode 100644 index 00000000..63ab9381 --- /dev/null +++ b/src/main/java/com/devonfw/quarkus/productmanagement/domain/repo/ProductRepository.java @@ -0,0 +1,20 @@ +package com.devonfw.quarkus.productmanagement.domain.repo; + +import java.math.BigDecimal; + +import org.springframework.data.domain.Page; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.CrudRepository; +import org.springframework.data.repository.query.Param; + +import com.devonfw.quarkus.productmanagement.domain.model.ProductEntity; + +public interface ProductRepository extends CrudRepository, ProductFragment { + + @Query("select a from ProductEntity a where title = :title") + ProductEntity findByTitle(@Param("title") String title); + + Page findAllByOrderByTitle(); + + ProductEntity findByPrice(@Param("price") BigDecimal price); +} \ No newline at end of file diff --git a/src/main/java/com/devonfw/quarkus/productmanagement/logic/UcFindProduct.java b/src/main/java/com/devonfw/quarkus/productmanagement/logic/UcFindProduct.java new file mode 100644 index 00000000..c8ea3e32 --- /dev/null +++ b/src/main/java/com/devonfw/quarkus/productmanagement/logic/UcFindProduct.java @@ -0,0 +1,28 @@ +package com.devonfw.quarkus.productmanagement.logic; + +import java.math.BigDecimal; + +import org.springframework.data.domain.Page; + +import com.devonfw.quarkus.productmanagement.service.v1.model.ProductDto; +import com.devonfw.quarkus.productmanagement.service.v1.model.ProductSearchCriteriaDto; + +public interface UcFindProduct { + Page findProducts(ProductSearchCriteriaDto dto); + + Page findProductsByCriteriaApi(ProductSearchCriteriaDto dto); + + Page findProductsByQueryDsl(ProductSearchCriteriaDto dto); + + Page findProductsByTitleQuery(ProductSearchCriteriaDto dto); + + Page findProductsByTitleNativeQuery(ProductSearchCriteriaDto dto); + + Page findProductsOrderedByTitle(); + + ProductDto findProduct(String id); + + ProductDto findProductByTitle(String title); + + ProductDto sortProductByPrice(BigDecimal priceMin, BigDecimal priceMax); +} diff --git a/src/main/java/com/devonfw/quarkus/productmanagement/logic/UcFindProductImpl.java b/src/main/java/com/devonfw/quarkus/productmanagement/logic/UcFindProductImpl.java new file mode 100644 index 00000000..92b71f63 --- /dev/null +++ b/src/main/java/com/devonfw/quarkus/productmanagement/logic/UcFindProductImpl.java @@ -0,0 +1,103 @@ +package com.devonfw.quarkus.productmanagement.logic; + +import java.util.ArrayList; +import java.util.List; + +import javax.inject.Inject; +import javax.inject.Named; +import javax.transaction.Transactional; + +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageImpl; +import org.springframework.data.domain.PageRequest; + +import com.devonfw.quarkus.productmanagement.domain.model.ProductEntity; +import com.devonfw.quarkus.productmanagement.domain.repo.ProductRepository; +import com.devonfw.quarkus.productmanagement.service.v1.mapper.ProductMapper; +import com.devonfw.quarkus.productmanagement.service.v1.model.ProductDto; +import com.devonfw.quarkus.productmanagement.service.v1.model.ProductSearchCriteriaDto; + +import lombok.extern.slf4j.Slf4j; + +@Named +@Transactional +@Slf4j +public class UcFindProductImpl implements UcFindProduct { + @Inject + ProductRepository ProductRepository; + + @Inject + ProductMapper mapper; + + @Override + public Page findProducts(ProductSearchCriteriaDto dto) { + + Iterable ProductsIterator = this.ProductRepository.findAll(); + List Products = new ArrayList(); + ProductsIterator.forEach(Products::add); + List ProductsDto = this.mapper.map(Products); + return new PageImpl<>(ProductsDto, PageRequest.of(dto.getPageNumber(), dto.getPageSize()), ProductsDto.size()); + } + + @Override + public Page findProductsByCriteriaApi(ProductSearchCriteriaDto dto) { + + List Products = this.ProductRepository.findAllCriteriaApi(dto).getContent(); + List ProductsDto = this.mapper.map(Products); + return new PageImpl<>(ProductsDto, PageRequest.of(dto.getPageNumber(), dto.getPageSize()), ProductsDto.size()); + } + + @Override + public Page findProductsByQueryDsl(ProductSearchCriteriaDto dto) { + + List Products = this.ProductRepository.findAllQueryDsl(dto).getContent(); + List ProductsDto = this.mapper.map(Products); + return new PageImpl<>(ProductsDto, PageRequest.of(dto.getPageNumber(), dto.getPageSize()), ProductsDto.size()); + } + + @Override + public Page findProductsByTitleQuery(ProductSearchCriteriaDto dto) { + + List Products = this.ProductRepository.findByTitleQuery(dto).getContent(); + List ProductsDto = this.mapper.map(Products); + return new PageImpl<>(ProductsDto, PageRequest.of(dto.getPageNumber(), dto.getPageSize()), ProductsDto.size()); + } + + @Override + public Page findProductsByTitleNativeQuery(ProductSearchCriteriaDto dto) { + + List Products = this.ProductRepository.findByTitleNativeQuery(dto).getContent(); + List ProductsDto = this.mapper.map(Products); + return new PageImpl<>(ProductsDto, PageRequest.of(dto.getPageNumber(), dto.getPageSize()), ProductsDto.size()); + } + + @Override + public Page findProductsOrderedByTitle() { + + List Products = this.ProductRepository.findAllByOrderByTitle().getContent(); + List ProductsDto = this.mapper.map(Products); + return new PageImpl<>(ProductsDto); + } + + @Override + public ProductDto findProduct(String id) { + + ProductEntity Product = this.ProductRepository.findById(Long.valueOf(id)).get(); + if (Product != null) { + return this.mapper.map(Product); + } else { + return null; + } + } + + @Override + public ProductDto findProductByTitle(String title) { + + ProductEntity Product = this.ProductRepository.findByTitle(title); + if (Product != null) { + return this.mapper.map(Product); + } else { + return null; + } + } +} \ No newline at end of file diff --git a/src/main/java/com/devonfw/quarkus/productmanagement/logic/UcManageProduct.java b/src/main/java/com/devonfw/quarkus/productmanagement/logic/UcManageProduct.java new file mode 100644 index 00000000..1b8cf630 --- /dev/null +++ b/src/main/java/com/devonfw/quarkus/productmanagement/logic/UcManageProduct.java @@ -0,0 +1,10 @@ +package com.devonfw.quarkus.productmanagement.logic; + +import com.devonfw.quarkus.productmanagement.service.v1.model.NewProductDto; +import com.devonfw.quarkus.productmanagement.service.v1.model.ProductDto; + +public interface UcManageProduct { + ProductDto saveProduct(NewProductDto dto); + + ProductDto deleteProduct(String id); +} diff --git a/src/main/java/com/devonfw/quarkus/productmanagement/logic/UcManageProductImpl.java b/src/main/java/com/devonfw/quarkus/productmanagement/logic/UcManageProductImpl.java new file mode 100644 index 00000000..2eadc9bf --- /dev/null +++ b/src/main/java/com/devonfw/quarkus/productmanagement/logic/UcManageProductImpl.java @@ -0,0 +1,38 @@ +package com.devonfw.quarkus.productmanagement.logic; + +import javax.inject.Inject; +import javax.inject.Named; +import javax.transaction.Transactional; + +import com.devonfw.quarkus.productmanagement.domain.model.ProductEntity; +import com.devonfw.quarkus.productmanagement.domain.repo.ProductRepository; +import com.devonfw.quarkus.productmanagement.service.v1.mapper.ProductMapper; +import com.devonfw.quarkus.productmanagement.service.v1.model.ProductDto; +import com.devonfw.quarkus.productmanagement.service.v1.model.NewProductDto; + +@Named +@Transactional +public class UcManageProductImpl implements UcManageProduct { + @Inject + ProductRepository ProductRepository; + + @Inject + ProductMapper mapper; + + @Override + public ProductDto saveProduct(NewProductDto dto) { + ProductEntity created = this.ProductRepository.save(this.mapper.create(dto)); + return this.mapper.map(created); + } + + @Override + public ProductDto deleteProduct(String id) { + ProductEntity Product = this.ProductRepository.findById(Long.valueOf(id)).get(); + if (Product != null) { + this.ProductRepository.delete(Product); + return this.mapper.map(Product); + } else { + return null; + } + } +} diff --git a/src/main/java/com/devonfw/quarkus/productmanagement/service/v1/ProductRestService.java b/src/main/java/com/devonfw/quarkus/productmanagement/service/v1/ProductRestService.java new file mode 100644 index 00000000..cd412731 --- /dev/null +++ b/src/main/java/com/devonfw/quarkus/productmanagement/service/v1/ProductRestService.java @@ -0,0 +1,143 @@ +package com.devonfw.quarkus.productmanagement.service.v1; + +import javax.inject.Inject; +import javax.ws.rs.BeanParam; +import javax.ws.rs.Consumes; +import javax.ws.rs.DELETE; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.UriInfo; + +import org.eclipse.microprofile.openapi.annotations.Operation; +import org.eclipse.microprofile.openapi.annotations.media.Content; +import org.eclipse.microprofile.openapi.annotations.media.Schema; +import org.eclipse.microprofile.openapi.annotations.parameters.Parameter; +import org.eclipse.microprofile.openapi.annotations.responses.APIResponse; +import org.eclipse.microprofile.openapi.annotations.responses.APIResponses; +import org.springframework.data.domain.PageImpl; +import org.tkit.quarkus.rs.models.PageResultDTO; + +import com.devonfw.quarkus.productmanagement.logic.UcFindProduct; +import com.devonfw.quarkus.productmanagement.logic.UcManageProduct; +import com.devonfw.quarkus.productmanagement.service.v1.model.NewProductDto; +import com.devonfw.quarkus.productmanagement.service.v1.model.ProductDto; +import com.devonfw.quarkus.productmanagement.service.v1.model.ProductSearchCriteriaDto; + +//In Quarkus all JAX-RS resources are treated as CDI beans +//default is Singleton scope +@Path("/Products") +// how we serialize response +@Produces(MediaType.APPLICATION_JSON) +// how we deserialize params +@Consumes(MediaType.APPLICATION_JSON) +public class ProductRestService { + + // using @Context we can inject contextual info from JAXRS(e.g. http request, current uri info, endpoint info...) + @Context + UriInfo uriInfo; + + @Inject + UcFindProduct ucFindProduct; + + @Inject + UcManageProduct ucManageProduct; + + @APIResponses({ + @APIResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = PagedProductResponse.class))), + @APIResponse(responseCode = "500") }) + @Operation(operationId = "Get Products", description = "Returns list of Products matching given criteria, uses pagination") + @GET + // REST service methods should not declare exceptions, any thrown error will be transformed by exceptionMapper in + // tkit-rest + // We did not define custom @Path - so it will use class level path + public PageImpl getAll(@BeanParam ProductSearchCriteriaDto dto) { + + return (PageImpl) this.ucFindProduct.findProducts(dto); + } + + @GET + @Path("criteriaApi") + public PageImpl getAllCriteriaApi(@BeanParam ProductSearchCriteriaDto dto) { + + return (PageImpl) this.ucFindProduct.findProductsByCriteriaApi(dto); + } + + @GET + @Path("queryDsl") + public PageImpl getAllQueryDsl(@BeanParam ProductSearchCriteriaDto dto) { + + return (PageImpl) this.ucFindProduct.findProductsByQueryDsl(dto); + } + + @GET + @Path("query") + public PageImpl getAllQuery(@BeanParam ProductSearchCriteriaDto dto) { + + return (PageImpl) this.ucFindProduct.findProductsByTitleQuery(dto); + } + + @GET + @Path("nativeQuery") + public PageImpl getAllNativeQuery(@BeanParam ProductSearchCriteriaDto dto) { + + return (PageImpl) this.ucFindProduct.findProductsByTitleNativeQuery(dto); + } + + @GET + @Path("ordered") + public PageImpl getAllOrderedByTitle() { + + return (PageImpl) this.ucFindProduct.findProductsOrderedByTitle(); + } + + @APIResponses({ + @APIResponse(responseCode = "201", description = "OK, New Product created", content = @Content(schema = @Schema(implementation = NewProductDto.class))), + @APIResponse(responseCode = "400", description = "Client side error, invalid request"), + @APIResponse(responseCode = "500") }) + @Operation(operationId = "createNewProduct", description = "Stores new Product in DB") + @POST + // We did not define custom @Path - so it will use class level path. + // Although we now have 2 methods with same path, it is ok, because it is a different method (get vs post) + public ProductDto createNewProduct(NewProductDto dto) { + + return this.ucManageProduct.saveProduct(dto); + } + + @APIResponses({ + @APIResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = ProductDto.class))), + @APIResponse(responseCode = "404", description = "Product not found"), @APIResponse(responseCode = "500") }) + @Operation(operationId = "getProductById", description = "Returns Product with given id") + @GET + @Path("{id}") + public ProductDto getProductById(@Parameter(description = "Product unique id") @PathParam("id") String id) { + + return this.ucFindProduct.findProduct(id); + } + + @GET + @Path("title/{title}") + public ProductDto getProductByTitle(@PathParam("title") String title) { + + return this.ucFindProduct.findProductByTitle(title); + } + + @APIResponses({ + @APIResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = ProductDto.class))), + @APIResponse(responseCode = "404", description = "Product not found"), @APIResponse(responseCode = "500") }) + @Operation(operationId = "deleteProductById", description = "Deletes the Product with given id") + @DELETE + @Path("{id}") + public ProductDto deleteProductById(@Parameter(description = "Product unique id") @PathParam("id") String id) { + + return this.ucManageProduct.deleteProduct(id); + } + + private static class PagedProductResponse extends PageResultDTO { + } + +} diff --git a/src/main/java/com/devonfw/quarkus/productmanagement/service/v1/mapper/ProductMapper.java b/src/main/java/com/devonfw/quarkus/productmanagement/service/v1/mapper/ProductMapper.java new file mode 100644 index 00000000..b7d797b9 --- /dev/null +++ b/src/main/java/com/devonfw/quarkus/productmanagement/service/v1/mapper/ProductMapper.java @@ -0,0 +1,21 @@ +package com.devonfw.quarkus.productmanagement.service.v1.mapper; + +import java.util.List; + +import org.mapstruct.Mapper; +import org.tkit.quarkus.rs.mappers.OffsetDateTimeMapper; + +import com.devonfw.quarkus.productmanagement.domain.model.ProductEntity; +import com.devonfw.quarkus.productmanagement.service.v1.model.ProductDto; +import com.devonfw.quarkus.productmanagement.service.v1.model.NewProductDto; + +//mapstruct will generate an impl class(CDI bean, see pom.xml) from this interface at compile time +@Mapper(uses = OffsetDateTimeMapper.class) +public interface ProductMapper { + + ProductDto map(ProductEntity model); + + ProductEntity create(NewProductDto dto); + + List map(List Products); +} diff --git a/src/main/java/com/devonfw/quarkus/productmanagement/service/v1/model/NewProductDto.java b/src/main/java/com/devonfw/quarkus/productmanagement/service/v1/model/NewProductDto.java new file mode 100644 index 00000000..d6d6171b --- /dev/null +++ b/src/main/java/com/devonfw/quarkus/productmanagement/service/v1/model/NewProductDto.java @@ -0,0 +1,23 @@ +package com.devonfw.quarkus.productmanagement.service.v1.model; + +import org.eclipse.microprofile.openapi.annotations.media.Schema; + +import lombok.Getter; +import lombok.Setter; + +@Getter +@Setter +public class NewProductDto { + + @Schema(nullable = false, description = "Product title", minLength = 3, maxLength = 50) + private String title; + + @Schema(description = "Product tag line", minLength = 3, maxLength = 50) + private String basicInfo; + + // @Schema(type = SchemaType.INTEGER, description = "How many legs does the Product have", example = "3") + // private int numberOfLegs; + + @Schema(nullable = false, description = "Product description", minLength = 3, maxLength = 50) + private String description; +} diff --git a/src/main/java/com/devonfw/quarkus/productmanagement/service/v1/model/ProductDto.java b/src/main/java/com/devonfw/quarkus/productmanagement/service/v1/model/ProductDto.java new file mode 100644 index 00000000..55c3151c --- /dev/null +++ b/src/main/java/com/devonfw/quarkus/productmanagement/service/v1/model/ProductDto.java @@ -0,0 +1,24 @@ +package com.devonfw.quarkus.productmanagement.service.v1.model; + +import java.math.BigDecimal; + +import lombok.Getter; +import lombok.Setter; + +@Getter +@Setter +public class ProductDto { + + private Long id; + + private String title; + + private String basicInfo; + + // private int numberOfLegs; + + private String description; + + private BigDecimal price; + +} diff --git a/src/main/java/com/devonfw/quarkus/productmanagement/service/v1/model/ProductSearchCriteriaDto.java b/src/main/java/com/devonfw/quarkus/productmanagement/service/v1/model/ProductSearchCriteriaDto.java new file mode 100644 index 00000000..23d0c530 --- /dev/null +++ b/src/main/java/com/devonfw/quarkus/productmanagement/service/v1/model/ProductSearchCriteriaDto.java @@ -0,0 +1,40 @@ +package com.devonfw.quarkus.productmanagement.service.v1.model; + +import java.math.BigDecimal; + +import javax.ws.rs.DefaultValue; +import javax.ws.rs.QueryParam; + +import lombok.Getter; +import lombok.Setter; + +@Getter +@Setter +public class ProductSearchCriteriaDto { + + @QueryParam("title") + private String title; + + // @QueryParam("legs") + // private Integer numberOfLegs; + + @QueryParam("page") + @DefaultValue("0") + private int pageNumber = 0; + + @QueryParam("size") + @DefaultValue("10") + private int pageSize = 10; + + @QueryParam("description") + private String description; + + @QueryParam("priceMin") + private BigDecimal priceMin; + + @QueryParam("priceMax") + private BigDecimal priceMax; + + @QueryParam("price") + private BigDecimal price; +} diff --git a/src/test/java/com/devonfw/demoquarkus/service/v1/AnimalRestServiceTest.java b/src/test/java/com/devonfw/demoquarkus/service/v1/ProductRestServiceTest.java similarity index 61% rename from src/test/java/com/devonfw/demoquarkus/service/v1/AnimalRestServiceTest.java rename to src/test/java/com/devonfw/demoquarkus/service/v1/ProductRestServiceTest.java index 30f6e853..92c80af1 100644 --- a/src/test/java/com/devonfw/demoquarkus/service/v1/AnimalRestServiceTest.java +++ b/src/test/java/com/devonfw/demoquarkus/service/v1/ProductRestServiceTest.java @@ -8,12 +8,13 @@ import javax.ws.rs.core.MediaType; -import com.devonfw.demoquarkus.service.v1.model.AnimalDto; import org.junit.jupiter.api.Test; import org.tkit.quarkus.rs.models.PageResultDTO; import org.tkit.quarkus.test.WithDBData; import org.tkit.quarkus.test.docker.DockerComposeTestResource; +import com.devonfw.quarkus.productmanagement.service.v1.model.ProductDto; + import io.quarkus.test.common.QuarkusTestResource; import io.quarkus.test.junit.QuarkusTest; import io.restassured.common.mapper.TypeRef; @@ -23,75 +24,77 @@ //we get a real postgresdb for our tests which will be stopped after tests. No manual test setup is needed. @QuarkusTest @QuarkusTestResource(DockerComposeTestResource.class) -class AnimalRestServiceTest {// extends AbstractTest { +class ProductRestServiceTest {// extends AbstractTest { @Test // we also started a micro container, that can populated DB with data from excel // annotating class or method with @WithDBData allows us to scope data for each test even if we use the same DB - @WithDBData(value = "data/animal.xls", deleteBeforeInsert = true) + @WithDBData(value = "data/product.xls", deleteBeforeInsert = true) void getAll() { - Response response = given().when().contentType(MediaType.APPLICATION_JSON).get("/animals").then().statusCode(200) + Response response = given().when().contentType(MediaType.APPLICATION_JSON).get("/products").then().statusCode(200) // .body("$.size()", equalTo(2)) .extract().response(); - PageResultDTO animalsReturned = response.as(new TypeRef>() { + PageResultDTO productsReturned = response.as(new TypeRef>() { }); // we import data from /import.sql - ergo expect 1 result - assertEquals(2, animalsReturned.getTotalElements()); + assertEquals(2, productsReturned.getTotalElements()); } @Test void getNonExistingTest() { - Response response = given().when().contentType(MediaType.APPLICATION_JSON).get("/animals/doesnoexist").then().log() + Response response = given().when().contentType(MediaType.APPLICATION_JSON).get("/products/doesnoexist").then().log() .all().statusCode(404).extract().response(); } @Test @WithDBData(value = "data/empty.xls", deleteBeforeInsert = true) - void createNewAnimal() { + void createNewProduct() { + + ProductDto product = new ProductDto(); + product.setTitle("Dog"); + product.setBasicInfo("Live"); + product.setPrice(1, 50); - AnimalDto animal = new AnimalDto(); - animal.setName("Dog"); - animal.setBasicInfo("Live"); - animal.setNumberOfLegs(4); + // product.setNumberOfLegs(4); - Response response = given().when().body(animal).contentType(MediaType.APPLICATION_JSON).post("/animals").then() + Response response = given().when().body(product).contentType(MediaType.APPLICATION_JSON).post("/products").then() .log().all().statusCode(201).header("Location", notNullValue()).extract().response(); assertEquals(201, response.statusCode()); - response = given().when().contentType(MediaType.APPLICATION_JSON).get("/animals").then().log().all().statusCode(200) - .extract().response(); + response = given().when().contentType(MediaType.APPLICATION_JSON).get("/products").then().log().all() + .statusCode(200).extract().response(); - PageResultDTO animalsReturned = response.as(new TypeRef<>() { + PageResultDTO productsReturned = response.as(new TypeRef<>() { }); - assertEquals(1, animalsReturned.getTotalElements()); - AnimalDto created = animalsReturned.getStream().get(0); + assertEquals(1, productsReturned.getTotalElements()); + ProductDto created = productsReturned.getStream().get(0); assertNotNull(created); - assertEquals(animal.getName(), created.getName()); + assertEquals(product.getTitle(), created.getTitle()); } @Test - @WithDBData(value = "data/animal.xls", deleteBeforeInsert = true) + @WithDBData(value = "data/product.xls", deleteBeforeInsert = true) public void testGetById() { - given().when().log().all().contentType(MediaType.APPLICATION_JSON).get("/animals/1").then().statusCode(200) + given().when().log().all().contentType(MediaType.APPLICATION_JSON).get("/products/1").then().statusCode(200) .body("basicInfo", equalTo("Cat")); } @Test - @WithDBData(value = "data/animal.xls", deleteBeforeInsert = true) + @WithDBData(value = "data/product.xls", deleteBeforeInsert = true) public void deleteById() { // delete - given().when().log().all().contentType(MediaType.APPLICATION_JSON).delete("/animals/1").then().statusCode(200) - .body("name", equalTo("Kitty")); + given().when().log().all().contentType(MediaType.APPLICATION_JSON).delete("/products/1").then().statusCode(200) + .body("title", equalTo("Kitty")); // after deletion it should be deleted - given().when().log().all().contentType(MediaType.APPLICATION_JSON).get("/animals/1").then().statusCode(404); + given().when().log().all().contentType(MediaType.APPLICATION_JSON).get("/products/1").then().statusCode(404); } From 8d2df68d886bc20df6e44bec3d2a0c20e8162133 Mon Sep 17 00:00:00 2001 From: TugbaDalmaz <89070914+TugbaDalmaz@users.noreply.github.com> Date: Thu, 2 Sep 2021 19:06:20 +0200 Subject: [PATCH 2/9] Change Animal to Product --- .../quarkus/productmanagement/ApplicationEntity.java | 8 -------- .../ApplicationPersistenceEntity.java | 8 ++------ .../quarkus/productmanagement/DemoApplication.java | 2 -- .../productmanagement/domain/model/ProductEntity.java | 8 -------- .../domain/model/ProductSearchCriteria.java | 2 -- .../domain/repo/ProductFragmentImpl.java | 10 ++-------- .../quarkus/productmanagement/logic/UcFindProduct.java | 4 ---- .../service/v1/model/NewProductDto.java | 3 --- .../productmanagement/service/v1/model/ProductDto.java | 2 -- .../service/v1/model/ProductSearchCriteriaDto.java | 3 --- 10 files changed, 4 insertions(+), 46 deletions(-) delete mode 100644 src/main/java/com/devonfw/quarkus/productmanagement/ApplicationEntity.java diff --git a/src/main/java/com/devonfw/quarkus/productmanagement/ApplicationEntity.java b/src/main/java/com/devonfw/quarkus/productmanagement/ApplicationEntity.java deleted file mode 100644 index 728f3f10..00000000 --- a/src/main/java/com/devonfw/quarkus/productmanagement/ApplicationEntity.java +++ /dev/null @@ -1,8 +0,0 @@ -package com.devonfw.quarkus.productmanagement; - -/** - * This is the abstract interface for a {@link GenericEntity}. We are using {@link Long} for all {@link #getId() primary - * keys}. - */ -public abstract interface ApplicationEntity extends GenericEntity { -} \ No newline at end of file diff --git a/src/main/java/com/devonfw/quarkus/productmanagement/ApplicationPersistenceEntity.java b/src/main/java/com/devonfw/quarkus/productmanagement/ApplicationPersistenceEntity.java index 68b0cdce..fd764509 100644 --- a/src/main/java/com/devonfw/quarkus/productmanagement/ApplicationPersistenceEntity.java +++ b/src/main/java/com/devonfw/quarkus/productmanagement/ApplicationPersistenceEntity.java @@ -1,5 +1,4 @@ -package com.devonfw.quarkus.productmanagement; -//package com.devonfw.application.jtqj.general.dataaccess.api; +package com.devonfw.quarkus.general.domain.model; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; @@ -8,9 +7,6 @@ import javax.persistence.Transient; import javax.persistence.Version; -//import com.devonfw.application.jtqj.general.common.api.ApplicationEntity; -//import com.devonfw.module.basic.common.api.entity.PersistenceEntity; - /** * Abstract base class for all {@link PersistenceEntity persistence entities} with an {@link #getId() id} and a * {@link #getModificationCounter() modificationCounter} (version) field. All persistence entities of this application @@ -18,7 +14,7 @@ * implies that you have to annotate transient getter methods with the {@link Transient} annotation. */ @MappedSuperclass -public abstract class ApplicationPersistenceEntity implements ApplicationEntity { +public abstract class ApplicationPersistenceEntity { private static final long serialVersionUID = 1L; diff --git a/src/main/java/com/devonfw/quarkus/productmanagement/DemoApplication.java b/src/main/java/com/devonfw/quarkus/productmanagement/DemoApplication.java index ddece7d8..e548b96d 100644 --- a/src/main/java/com/devonfw/quarkus/productmanagement/DemoApplication.java +++ b/src/main/java/com/devonfw/quarkus/productmanagement/DemoApplication.java @@ -1,5 +1,3 @@ -package com.devonfw.quarkus.productmanagement; - import javax.ws.rs.core.Application; import org.eclipse.microprofile.openapi.annotations.OpenAPIDefinition; diff --git a/src/main/java/com/devonfw/quarkus/productmanagement/domain/model/ProductEntity.java b/src/main/java/com/devonfw/quarkus/productmanagement/domain/model/ProductEntity.java index fc333987..c056873e 100644 --- a/src/main/java/com/devonfw/quarkus/productmanagement/domain/model/ProductEntity.java +++ b/src/main/java/com/devonfw/quarkus/productmanagement/domain/model/ProductEntity.java @@ -3,8 +3,6 @@ import java.math.BigDecimal; import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.Id; import javax.persistence.Table; import com.devonfw.quarkus.productmanagement.ApplicationPersistenceEntity; @@ -20,17 +18,11 @@ // by default, the DB table will have the same name as our class public class ProductEntity extends ApplicationPersistenceEntity { - @Id - @GeneratedValue - // private Long id; - private String title; // every primitive attribute on this class will be represented as column in Product table private String basicInfo; - // private int numberOfLegs; - private String description; private BigDecimal price; diff --git a/src/main/java/com/devonfw/quarkus/productmanagement/domain/model/ProductSearchCriteria.java b/src/main/java/com/devonfw/quarkus/productmanagement/domain/model/ProductSearchCriteria.java index c7b1eead..ae679575 100644 --- a/src/main/java/com/devonfw/quarkus/productmanagement/domain/model/ProductSearchCriteria.java +++ b/src/main/java/com/devonfw/quarkus/productmanagement/domain/model/ProductSearchCriteria.java @@ -11,8 +11,6 @@ public class ProductSearchCriteria { private String title; - // private Integer numberOfLegs; - private Integer pageNumber; private Integer pageSize; diff --git a/src/main/java/com/devonfw/quarkus/productmanagement/domain/repo/ProductFragmentImpl.java b/src/main/java/com/devonfw/quarkus/productmanagement/domain/repo/ProductFragmentImpl.java index be45196e..f1ed4c77 100644 --- a/src/main/java/com/devonfw/quarkus/productmanagement/domain/repo/ProductFragmentImpl.java +++ b/src/main/java/com/devonfw/quarkus/productmanagement/domain/repo/ProductFragmentImpl.java @@ -38,13 +38,10 @@ public Page findAllCriteriaApi(ProductSearchCriteriaDto dto) { if (dto.getTitle() != null && !dto.getTitle().isEmpty()) { predicates.add(cb.like(root.get(ProductEntity_.TITLE), dto.getTitle())); } - // if (dto.getNumberOfLegs() != null) { - // predicates.add(cb.equal(root.get(ProductEntity_.NUMBER_OF_LEGS), dto.getNumberOfLegs())); - // } BigDecimal price, priceMin, priceMax, x; - if (dto.getPriceMin() != null | dto.getPriceMax() != null) { - if (priceMin.compareTo(x) == 0 | priceMax.compareTo(x) == 0) { + if (dto.getPriceMin() != null || dto.getPriceMax() != null) { + if (priceMin.compareTo(x) == 0 || priceMax.compareTo(x) == 0) { price = x; predicates.add(cb.equal(root.get(ProductEntity_.PRICE), dto.getPrice())); } else if ((price.compareTo(priceMin) == 1) & (price.compareTo(priceMax) == -1)) { @@ -74,9 +71,6 @@ public Page findAllQueryDsl(ProductSearchCriteriaDto dto) { if (dto.getTitle() != null && !dto.getTitle().isEmpty()) { query.where(Product.title.eq(dto.getTitle())); } - // if (dto.getNumberOfLegs() != null) { - // query.where(Product.numberOfLegs.eq(dto.getNumberOfLegs())); - // } BigDecimal price, priceMin, priceMax, x; if (dto.getPriceMin() != null | dto.getPriceMax() != null) { diff --git a/src/main/java/com/devonfw/quarkus/productmanagement/logic/UcFindProduct.java b/src/main/java/com/devonfw/quarkus/productmanagement/logic/UcFindProduct.java index c8ea3e32..487232d8 100644 --- a/src/main/java/com/devonfw/quarkus/productmanagement/logic/UcFindProduct.java +++ b/src/main/java/com/devonfw/quarkus/productmanagement/logic/UcFindProduct.java @@ -1,7 +1,5 @@ package com.devonfw.quarkus.productmanagement.logic; -import java.math.BigDecimal; - import org.springframework.data.domain.Page; import com.devonfw.quarkus.productmanagement.service.v1.model.ProductDto; @@ -23,6 +21,4 @@ public interface UcFindProduct { ProductDto findProduct(String id); ProductDto findProductByTitle(String title); - - ProductDto sortProductByPrice(BigDecimal priceMin, BigDecimal priceMax); } diff --git a/src/main/java/com/devonfw/quarkus/productmanagement/service/v1/model/NewProductDto.java b/src/main/java/com/devonfw/quarkus/productmanagement/service/v1/model/NewProductDto.java index d6d6171b..a0c404dc 100644 --- a/src/main/java/com/devonfw/quarkus/productmanagement/service/v1/model/NewProductDto.java +++ b/src/main/java/com/devonfw/quarkus/productmanagement/service/v1/model/NewProductDto.java @@ -15,9 +15,6 @@ public class NewProductDto { @Schema(description = "Product tag line", minLength = 3, maxLength = 50) private String basicInfo; - // @Schema(type = SchemaType.INTEGER, description = "How many legs does the Product have", example = "3") - // private int numberOfLegs; - @Schema(nullable = false, description = "Product description", minLength = 3, maxLength = 50) private String description; } diff --git a/src/main/java/com/devonfw/quarkus/productmanagement/service/v1/model/ProductDto.java b/src/main/java/com/devonfw/quarkus/productmanagement/service/v1/model/ProductDto.java index 55c3151c..733f4ec8 100644 --- a/src/main/java/com/devonfw/quarkus/productmanagement/service/v1/model/ProductDto.java +++ b/src/main/java/com/devonfw/quarkus/productmanagement/service/v1/model/ProductDto.java @@ -15,8 +15,6 @@ public class ProductDto { private String basicInfo; - // private int numberOfLegs; - private String description; private BigDecimal price; diff --git a/src/main/java/com/devonfw/quarkus/productmanagement/service/v1/model/ProductSearchCriteriaDto.java b/src/main/java/com/devonfw/quarkus/productmanagement/service/v1/model/ProductSearchCriteriaDto.java index 23d0c530..f3dcdef5 100644 --- a/src/main/java/com/devonfw/quarkus/productmanagement/service/v1/model/ProductSearchCriteriaDto.java +++ b/src/main/java/com/devonfw/quarkus/productmanagement/service/v1/model/ProductSearchCriteriaDto.java @@ -15,9 +15,6 @@ public class ProductSearchCriteriaDto { @QueryParam("title") private String title; - // @QueryParam("legs") - // private Integer numberOfLegs; - @QueryParam("page") @DefaultValue("0") private int pageNumber = 0; From 72e98f2c83b083434313551bc94eae9183ba3064 Mon Sep 17 00:00:00 2001 From: TugbaDalmaz <89070914+TugbaDalmaz@users.noreply.github.com> Date: Thu, 2 Sep 2021 19:47:35 +0200 Subject: [PATCH 3/9] Change Animal to Product --- .../quarkus/productmanagement/domain/model/ProductEntity.java | 2 +- .../productmanagement/domain/repo/ProductRepository.java | 4 ---- .../productmanagement/service/v1/model/ProductDto.java | 2 +- 3 files changed, 2 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/devonfw/quarkus/productmanagement/domain/model/ProductEntity.java b/src/main/java/com/devonfw/quarkus/productmanagement/domain/model/ProductEntity.java index c056873e..52a19fef 100644 --- a/src/main/java/com/devonfw/quarkus/productmanagement/domain/model/ProductEntity.java +++ b/src/main/java/com/devonfw/quarkus/productmanagement/domain/model/ProductEntity.java @@ -25,5 +25,5 @@ public class ProductEntity extends ApplicationPersistenceEntity { private String description; - private BigDecimal price; + private BigDecimal price, priceMin, priceMax; } diff --git a/src/main/java/com/devonfw/quarkus/productmanagement/domain/repo/ProductRepository.java b/src/main/java/com/devonfw/quarkus/productmanagement/domain/repo/ProductRepository.java index 63ab9381..39a68d4f 100644 --- a/src/main/java/com/devonfw/quarkus/productmanagement/domain/repo/ProductRepository.java +++ b/src/main/java/com/devonfw/quarkus/productmanagement/domain/repo/ProductRepository.java @@ -1,7 +1,5 @@ package com.devonfw.quarkus.productmanagement.domain.repo; -import java.math.BigDecimal; - import org.springframework.data.domain.Page; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.CrudRepository; @@ -15,6 +13,4 @@ public interface ProductRepository extends CrudRepository, ProductEntity findByTitle(@Param("title") String title); Page findAllByOrderByTitle(); - - ProductEntity findByPrice(@Param("price") BigDecimal price); } \ No newline at end of file diff --git a/src/main/java/com/devonfw/quarkus/productmanagement/service/v1/model/ProductDto.java b/src/main/java/com/devonfw/quarkus/productmanagement/service/v1/model/ProductDto.java index 733f4ec8..2e13b79f 100644 --- a/src/main/java/com/devonfw/quarkus/productmanagement/service/v1/model/ProductDto.java +++ b/src/main/java/com/devonfw/quarkus/productmanagement/service/v1/model/ProductDto.java @@ -17,6 +17,6 @@ public class ProductDto { private String description; - private BigDecimal price; + private BigDecimal price, priceMin, priceMax; } From 99db8396565035c25475a3f47aaa838cf957f3ea Mon Sep 17 00:00:00 2001 From: TugbaDalmaz <89070914+TugbaDalmaz@users.noreply.github.com> Date: Tue, 7 Sep 2021 14:53:37 +0200 Subject: [PATCH 4/9] Change Animal to Product --- .../DemoApplication.java | 2 + .../model}/ApplicationPersistenceEntity.java | 6 +- .../productmanagement/GenericEntity.java | 81 ------------------- .../domain/model/ProductEntity.java | 4 +- .../domain/repo/ProductFragmentImpl.java | 35 ++++---- .../logic/UcManageProductImpl.java | 40 ++++----- .../service/v1/ProductRestService.java | 2 +- .../service/v1/mapper/ProductMapper.java | 2 +- .../service/v1/model/ProductDto.java | 2 +- .../service/v1/ProductRestServiceTest.java | 4 +- 10 files changed, 51 insertions(+), 127 deletions(-) rename src/main/java/com/devonfw/quarkus/{productmanagement => }/DemoApplication.java (96%) rename src/main/java/com/devonfw/quarkus/{productmanagement => general/domain/model}/ApplicationPersistenceEntity.java (97%) delete mode 100644 src/main/java/com/devonfw/quarkus/productmanagement/GenericEntity.java diff --git a/src/main/java/com/devonfw/quarkus/productmanagement/DemoApplication.java b/src/main/java/com/devonfw/quarkus/DemoApplication.java similarity index 96% rename from src/main/java/com/devonfw/quarkus/productmanagement/DemoApplication.java rename to src/main/java/com/devonfw/quarkus/DemoApplication.java index e548b96d..3e958c38 100644 --- a/src/main/java/com/devonfw/quarkus/productmanagement/DemoApplication.java +++ b/src/main/java/com/devonfw/quarkus/DemoApplication.java @@ -1,3 +1,5 @@ +package com.devonfw.quarkus; + import javax.ws.rs.core.Application; import org.eclipse.microprofile.openapi.annotations.OpenAPIDefinition; diff --git a/src/main/java/com/devonfw/quarkus/productmanagement/ApplicationPersistenceEntity.java b/src/main/java/com/devonfw/quarkus/general/domain/model/ApplicationPersistenceEntity.java similarity index 97% rename from src/main/java/com/devonfw/quarkus/productmanagement/ApplicationPersistenceEntity.java rename to src/main/java/com/devonfw/quarkus/general/domain/model/ApplicationPersistenceEntity.java index fd764509..1da37090 100644 --- a/src/main/java/com/devonfw/quarkus/productmanagement/ApplicationPersistenceEntity.java +++ b/src/main/java/com/devonfw/quarkus/general/domain/model/ApplicationPersistenceEntity.java @@ -30,7 +30,6 @@ public ApplicationPersistenceEntity() { super(); } - @Override @Id @GeneratedValue(strategy = GenerationType.AUTO) public Long getId() { @@ -38,20 +37,17 @@ public Long getId() { return this.id; } - @Override public void setId(Long id) { this.id = id; } - @Override @Version public int getModificationCounter() { return this.modificationCounter; } - @Override public void setModificationCounter(int version) { this.modificationCounter = version; @@ -80,4 +76,4 @@ protected void toString(StringBuilder buffer) { buffer.append("]"); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/devonfw/quarkus/productmanagement/GenericEntity.java b/src/main/java/com/devonfw/quarkus/productmanagement/GenericEntity.java deleted file mode 100644 index d76a9045..00000000 --- a/src/main/java/com/devonfw/quarkus/productmanagement/GenericEntity.java +++ /dev/null @@ -1,81 +0,0 @@ -package com.devonfw.quarkus.productmanagement; - -import java.io.Serializable; - -/** - * This is the interface for an entity, which is an object that is potentially stored in a persistent store (typically a - * database via JPA). Every non-abstract implementation of this interface is simply called an entity. It is - * supposed to be a simple java bean.
- * This interface makes the following assumptions: - *
    - *
  • A {@link GenericEntity} is identified by a {@link #getId() primary key}.
  • - *
  • A {@link GenericEntity} has a {@link #getModificationCounter() modification counter} for optimistic locking (even - * though not strictly required - you could statically return 0).
  • - *
- * ATTENTION:
- * An instance of this interface is typically one of the following: - *
    - *
  • a JPA {@link javax.persistence.Entity}
    - *
  • a {@link com.devonfw.module.basic.common.api.to.AbstractEto entity transfer-object}
    - *
- * In order to distinguish the above cases an application has an architecture that organizes the code in technical - * layers (see multilayered architecture) and - * business oriented slices (business components). Therefore within the persistence layer instances should always be - * {@link javax.persistence.Entity persistence entities}. On the other hand the higher layers always need to use - * {@link com.devonfw.module.basic.common.api.to.AbstractTo transfer-objects}. Our recommendation is to map between - * these two in the logic-layer using the {@code BeanMapper} component from the {@code devon4j-beanmapping} module. - * - * @see javax.persistence.Entity - * - * @param is the type of the {@link #getId() primary key}. - * - * @since 3.0.0 - */ -public interface GenericEntity extends Serializable { - - /** - * @return the primary key (unique identifier) of this entity. May be {@code null} if this entity is transient (not - * yet {@link javax.persistence.EntityManager#persist(Object) saved} in the database). While this method is - * initially defined in a generic way, it is strongly recommended to use {@link Long} as datatype for IDs. - *
- * Even if you want to have a {@link String}-based business-oriented identifier it is best practice to use a - * {@link Long} as primary key and add the business identifier as additional field (with a unique constraint). - * This way references to the entity will be a lot more compact and improve your performance in JOINs or the - * like. However, there may be reasons to use other datatypes for the ID. In any case the unique ID should be - * an immutable java-object that can be rebuild from its {@link Object#toString() string-representation}.
- * Please note that if your ID has a specific syntax, semantic, formatting rules, etc. you should create a - * custom datatype for it. If it can easily be mapped to a {@link Long} value you can still use {@link Long} - * here and provide a transient getter method that returns the your custom datatype from the {@link Long}. - * @see javax.persistence.Id - */ - ID getId(); - - /** - * @param id the new {@link #getId() primary key}. This method shall typically only be used by technical frameworks - * such as hibernate. - */ - void setId(ID id); - - /** - * This method gets the current modification-counter of this entity. Whenever the object gets modified and - * {@link javax.persistence.EntityManager#persist(Object) persisted}, this counter will be increased (typically after - * the transaction is closed). The initial value after construction is {@code 0}.
- * This property is often simply called {@link javax.persistence.Version version}. However, as this sometimes causes - * confusion or may conflict with a business property "version", we use the more technical and self-explanatory name - * {@code modificationCounter}.
- * If this feature is NOT supported for some reason, this method should always return {@code 0}. - * - * @see javax.persistence.Version - * - * @return the current modification-counter. - * @see javax.persistence.Version - */ - int getModificationCounter(); - - /** - * @param modificationCounter the new {@link #getModificationCounter() modification counter}. This method shall - * typically only be used by technical frameworks such as hibernate. - */ - void setModificationCounter(int modificationCounter); - -} \ No newline at end of file diff --git a/src/main/java/com/devonfw/quarkus/productmanagement/domain/model/ProductEntity.java b/src/main/java/com/devonfw/quarkus/productmanagement/domain/model/ProductEntity.java index 52a19fef..222c0b9d 100644 --- a/src/main/java/com/devonfw/quarkus/productmanagement/domain/model/ProductEntity.java +++ b/src/main/java/com/devonfw/quarkus/productmanagement/domain/model/ProductEntity.java @@ -5,7 +5,7 @@ import javax.persistence.Entity; import javax.persistence.Table; -import com.devonfw.quarkus.productmanagement.ApplicationPersistenceEntity; +import com.devonfw.quarkus.general.domain.model.ApplicationPersistenceEntity; import lombok.Getter; import lombok.Setter; @@ -25,5 +25,5 @@ public class ProductEntity extends ApplicationPersistenceEntity { private String description; - private BigDecimal price, priceMin, priceMax; + private BigDecimal price; } diff --git a/src/main/java/com/devonfw/quarkus/productmanagement/domain/repo/ProductFragmentImpl.java b/src/main/java/com/devonfw/quarkus/productmanagement/domain/repo/ProductFragmentImpl.java index f1ed4c77..586cb84e 100644 --- a/src/main/java/com/devonfw/quarkus/productmanagement/domain/repo/ProductFragmentImpl.java +++ b/src/main/java/com/devonfw/quarkus/productmanagement/domain/repo/ProductFragmentImpl.java @@ -1,6 +1,5 @@ package com.devonfw.quarkus.productmanagement.domain.repo; -import java.math.BigDecimal; import java.util.ArrayList; import java.util.List; @@ -39,17 +38,20 @@ public Page findAllCriteriaApi(ProductSearchCriteriaDto dto) { predicates.add(cb.like(root.get(ProductEntity_.TITLE), dto.getTitle())); } - BigDecimal price, priceMin, priceMax, x; - if (dto.getPriceMin() != null || dto.getPriceMax() != null) { - if (priceMin.compareTo(x) == 0 || priceMax.compareTo(x) == 0) { - price = x; - predicates.add(cb.equal(root.get(ProductEntity_.PRICE), dto.getPrice())); - } else if ((price.compareTo(priceMin) == 1) & (price.compareTo(priceMax) == -1)) { - predicates.add(cb.equal(root.get(ProductEntity_.PRICE), dto.getPrice())); + if (dto.getPrice() != null) { + predicates.add(cb.gt(root.get(ProductEntity_.PRICE), dto.getPrice())); + } else if (dto.getPriceMin() != null || dto.getPriceMax() != null) { + if (dto.getPriceMin() != null) { + predicates.add(cb.gt(root.get(ProductEntity_.PRICE), dto.getPriceMin())); + } + if (dto.getPriceMax() != null) { + predicates.add(cb.lt(root.get(ProductEntity_.PRICE), dto.getPriceMax())); } } - if (!predicates.isEmpty()) { + if (!predicates.isEmpty()) + + { cq.where(predicates.toArray(new Predicate[0])); } @@ -72,13 +74,14 @@ public Page findAllQueryDsl(ProductSearchCriteriaDto dto) { query.where(Product.title.eq(dto.getTitle())); } - BigDecimal price, priceMin, priceMax, x; - if (dto.getPriceMin() != null | dto.getPriceMax() != null) { - if (getPriceMin().compareTo(x) == 0 | priceMax.compareTo(x) == 0) { - price = x; - query.where(Product.price.eq(dto.getPrice())); - } else if ((price.compareTo(priceMin) == 1) & (price.compareTo(priceMax) == -1)) { - query.where(Product.price.eq(dto.getPrice())); + if (dto.getPrice() != null) { + query.where(Product.price.eq(dto.getPrice())); + } else if (dto.getPriceMin() != null || dto.getPriceMax() != null) { + if (dto.getPriceMin() != null) { + query.where(Product.price.gt(dto.getPriceMin())); + } + if (dto.getPriceMax() != null) { + query.where(Product.price.lt(dto.getPriceMax())); } } diff --git a/src/main/java/com/devonfw/quarkus/productmanagement/logic/UcManageProductImpl.java b/src/main/java/com/devonfw/quarkus/productmanagement/logic/UcManageProductImpl.java index 2eadc9bf..cccbb6be 100644 --- a/src/main/java/com/devonfw/quarkus/productmanagement/logic/UcManageProductImpl.java +++ b/src/main/java/com/devonfw/quarkus/productmanagement/logic/UcManageProductImpl.java @@ -7,32 +7,34 @@ import com.devonfw.quarkus.productmanagement.domain.model.ProductEntity; import com.devonfw.quarkus.productmanagement.domain.repo.ProductRepository; import com.devonfw.quarkus.productmanagement.service.v1.mapper.ProductMapper; -import com.devonfw.quarkus.productmanagement.service.v1.model.ProductDto; import com.devonfw.quarkus.productmanagement.service.v1.model.NewProductDto; +import com.devonfw.quarkus.productmanagement.service.v1.model.ProductDto; @Named @Transactional public class UcManageProductImpl implements UcManageProduct { - @Inject - ProductRepository ProductRepository; + @Inject + ProductRepository ProductRepository; - @Inject - ProductMapper mapper; + @Inject + ProductMapper mapper; - @Override - public ProductDto saveProduct(NewProductDto dto) { - ProductEntity created = this.ProductRepository.save(this.mapper.create(dto)); - return this.mapper.map(created); - } + @Override + public ProductDto saveProduct(NewProductDto dto) { + + ProductEntity created = this.ProductRepository.save(this.mapper.create(dto)); + return this.mapper.map(created); + } + + @Override + public ProductDto deleteProduct(String id) { - @Override - public ProductDto deleteProduct(String id) { - ProductEntity Product = this.ProductRepository.findById(Long.valueOf(id)).get(); - if (Product != null) { - this.ProductRepository.delete(Product); - return this.mapper.map(Product); - } else { - return null; - } + ProductEntity Product = this.ProductRepository.findById(Long.valueOf(id)).get(); + if (Product != null) { + this.ProductRepository.delete(Product); + return this.mapper.map(Product); + } else { + return null; } + } } diff --git a/src/main/java/com/devonfw/quarkus/productmanagement/service/v1/ProductRestService.java b/src/main/java/com/devonfw/quarkus/productmanagement/service/v1/ProductRestService.java index cd412731..b886fcea 100644 --- a/src/main/java/com/devonfw/quarkus/productmanagement/service/v1/ProductRestService.java +++ b/src/main/java/com/devonfw/quarkus/productmanagement/service/v1/ProductRestService.java @@ -30,7 +30,7 @@ //In Quarkus all JAX-RS resources are treated as CDI beans //default is Singleton scope -@Path("/Products") +@Path("/products") // how we serialize response @Produces(MediaType.APPLICATION_JSON) // how we deserialize params diff --git a/src/main/java/com/devonfw/quarkus/productmanagement/service/v1/mapper/ProductMapper.java b/src/main/java/com/devonfw/quarkus/productmanagement/service/v1/mapper/ProductMapper.java index b7d797b9..46c1f856 100644 --- a/src/main/java/com/devonfw/quarkus/productmanagement/service/v1/mapper/ProductMapper.java +++ b/src/main/java/com/devonfw/quarkus/productmanagement/service/v1/mapper/ProductMapper.java @@ -6,8 +6,8 @@ import org.tkit.quarkus.rs.mappers.OffsetDateTimeMapper; import com.devonfw.quarkus.productmanagement.domain.model.ProductEntity; -import com.devonfw.quarkus.productmanagement.service.v1.model.ProductDto; import com.devonfw.quarkus.productmanagement.service.v1.model.NewProductDto; +import com.devonfw.quarkus.productmanagement.service.v1.model.ProductDto; //mapstruct will generate an impl class(CDI bean, see pom.xml) from this interface at compile time @Mapper(uses = OffsetDateTimeMapper.class) diff --git a/src/main/java/com/devonfw/quarkus/productmanagement/service/v1/model/ProductDto.java b/src/main/java/com/devonfw/quarkus/productmanagement/service/v1/model/ProductDto.java index 2e13b79f..733f4ec8 100644 --- a/src/main/java/com/devonfw/quarkus/productmanagement/service/v1/model/ProductDto.java +++ b/src/main/java/com/devonfw/quarkus/productmanagement/service/v1/model/ProductDto.java @@ -17,6 +17,6 @@ public class ProductDto { private String description; - private BigDecimal price, priceMin, priceMax; + private BigDecimal price; } diff --git a/src/test/java/com/devonfw/demoquarkus/service/v1/ProductRestServiceTest.java b/src/test/java/com/devonfw/demoquarkus/service/v1/ProductRestServiceTest.java index 92c80af1..0a176f7b 100644 --- a/src/test/java/com/devonfw/demoquarkus/service/v1/ProductRestServiceTest.java +++ b/src/test/java/com/devonfw/demoquarkus/service/v1/ProductRestServiceTest.java @@ -6,6 +6,8 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; +import java.math.BigDecimal; + import javax.ws.rs.core.MediaType; import org.junit.jupiter.api.Test; @@ -57,7 +59,7 @@ void createNewProduct() { ProductDto product = new ProductDto(); product.setTitle("Dog"); product.setBasicInfo("Live"); - product.setPrice(1, 50); + product.setPrice(BigDecimal.valueOf(1)); // product.setNumberOfLegs(4); From eda22d5b94d2da4561af116c327f1263af0563c4 Mon Sep 17 00:00:00 2001 From: TugbaDalmaz <89070914+TugbaDalmaz@users.noreply.github.com> Date: Tue, 7 Sep 2021 15:21:50 +0200 Subject: [PATCH 5/9] Change Animal to Product --- .../domain/model/ApplicationPersistenceEntity.java | 10 +++++----- .../domain/repo/ProductFragmentImpl.java | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/devonfw/quarkus/general/domain/model/ApplicationPersistenceEntity.java b/src/main/java/com/devonfw/quarkus/general/domain/model/ApplicationPersistenceEntity.java index 1da37090..f3f9d079 100644 --- a/src/main/java/com/devonfw/quarkus/general/domain/model/ApplicationPersistenceEntity.java +++ b/src/main/java/com/devonfw/quarkus/general/domain/model/ApplicationPersistenceEntity.java @@ -18,9 +18,11 @@ public abstract class ApplicationPersistenceEntity { private static final long serialVersionUID = 1L; + @Id + @GeneratedValue(strategy = GenerationType.AUTO) private Long id; - private int modificationCounter; + private Integer modificationCounter; /** * The constructor. @@ -30,8 +32,6 @@ public ApplicationPersistenceEntity() { super(); } - @Id - @GeneratedValue(strategy = GenerationType.AUTO) public Long getId() { return this.id; @@ -43,12 +43,12 @@ public void setId(Long id) { } @Version - public int getModificationCounter() { + public Integer getModificationCounter() { return this.modificationCounter; } - public void setModificationCounter(int version) { + public void setModificationCounter(Integer version) { this.modificationCounter = version; } diff --git a/src/main/java/com/devonfw/quarkus/productmanagement/domain/repo/ProductFragmentImpl.java b/src/main/java/com/devonfw/quarkus/productmanagement/domain/repo/ProductFragmentImpl.java index 586cb84e..8cf27d9a 100644 --- a/src/main/java/com/devonfw/quarkus/productmanagement/domain/repo/ProductFragmentImpl.java +++ b/src/main/java/com/devonfw/quarkus/productmanagement/domain/repo/ProductFragmentImpl.java @@ -67,7 +67,7 @@ public Page findAllCriteriaApi(ProductSearchCriteriaDto dto) { @Override public Page findAllQueryDsl(ProductSearchCriteriaDto dto) { - QProductEntity Product = QProductEntity.ProductEntity; + QProductEntity Product = QProductEntity.productEntity; JPAQuery query = new JPAQuery(this.em); query.from(Product); if (dto.getTitle() != null && !dto.getTitle().isEmpty()) { From ca0687960e5a1f05d592960bbc1c603066fac708 Mon Sep 17 00:00:00 2001 From: TugbaDalmaz <89070914+TugbaDalmaz@users.noreply.github.com> Date: Wed, 8 Sep 2021 11:13:34 +0200 Subject: [PATCH 6/9] Change Animal to Product --- .../domain/model/ProductEntity.java | 1 - .../domain/model/ProductSearchCriteria.java | 2 - .../domain/repo/ProductFragmentImpl.java | 32 +++++------ .../logic/UcFindProductImpl.java | 52 +++++++++--------- .../logic/UcManageProductImpl.java | 12 ++-- .../service/v1/model/NewProductDto.java | 13 +++-- .../service/v1/model/ProductDto.java | 2 - .../v1/model/ProductSearchCriteriaDto.java | 3 - .../service/v1/ProductRestServiceTest.java | 11 ++-- .../data/{animal.xls => product.xls} | Bin 35328 -> 35328 bytes 10 files changed, 60 insertions(+), 68 deletions(-) rename src/test/resources/data/{animal.xls => product.xls} (68%) diff --git a/src/main/java/com/devonfw/quarkus/productmanagement/domain/model/ProductEntity.java b/src/main/java/com/devonfw/quarkus/productmanagement/domain/model/ProductEntity.java index 222c0b9d..2466b1ab 100644 --- a/src/main/java/com/devonfw/quarkus/productmanagement/domain/model/ProductEntity.java +++ b/src/main/java/com/devonfw/quarkus/productmanagement/domain/model/ProductEntity.java @@ -21,7 +21,6 @@ public class ProductEntity extends ApplicationPersistenceEntity { private String title; // every primitive attribute on this class will be represented as column in Product table - private String basicInfo; private String description; diff --git a/src/main/java/com/devonfw/quarkus/productmanagement/domain/model/ProductSearchCriteria.java b/src/main/java/com/devonfw/quarkus/productmanagement/domain/model/ProductSearchCriteria.java index ae679575..4cca919b 100644 --- a/src/main/java/com/devonfw/quarkus/productmanagement/domain/model/ProductSearchCriteria.java +++ b/src/main/java/com/devonfw/quarkus/productmanagement/domain/model/ProductSearchCriteria.java @@ -15,7 +15,5 @@ public class ProductSearchCriteria { private Integer pageSize; - private String description; - private BigDecimal price, priceMin, priceMax; } diff --git a/src/main/java/com/devonfw/quarkus/productmanagement/domain/repo/ProductFragmentImpl.java b/src/main/java/com/devonfw/quarkus/productmanagement/domain/repo/ProductFragmentImpl.java index 8cf27d9a..3c7e0c78 100644 --- a/src/main/java/com/devonfw/quarkus/productmanagement/domain/repo/ProductFragmentImpl.java +++ b/src/main/java/com/devonfw/quarkus/productmanagement/domain/repo/ProductFragmentImpl.java @@ -58,39 +58,39 @@ public Page findAllCriteriaApi(ProductSearchCriteriaDto dto) { // Order by title cq.orderBy(cb.desc(root.get(ProductEntity_.TITLE))); - TypedQuery Products = this.em.createQuery(cq).setFirstResult(dto.getPageNumber() * dto.getPageSize()) + TypedQuery products = this.em.createQuery(cq).setFirstResult(dto.getPageNumber() * dto.getPageSize()) .setMaxResults(dto.getPageSize()); - return new PageImpl(Products.getResultList(), PageRequest.of(dto.getPageNumber(), dto.getPageSize()), - Products.getResultList().size()); + return new PageImpl(products.getResultList(), PageRequest.of(dto.getPageNumber(), dto.getPageSize()), + products.getResultList().size()); } @Override public Page findAllQueryDsl(ProductSearchCriteriaDto dto) { - QProductEntity Product = QProductEntity.productEntity; + QProductEntity product = QProductEntity.productEntity; JPAQuery query = new JPAQuery(this.em); - query.from(Product); + query.from(product); if (dto.getTitle() != null && !dto.getTitle().isEmpty()) { - query.where(Product.title.eq(dto.getTitle())); + query.where(product.title.eq(dto.getTitle())); } if (dto.getPrice() != null) { - query.where(Product.price.eq(dto.getPrice())); + query.where(product.price.eq(dto.getPrice())); } else if (dto.getPriceMin() != null || dto.getPriceMax() != null) { if (dto.getPriceMin() != null) { - query.where(Product.price.gt(dto.getPriceMin())); + query.where(product.price.gt(dto.getPriceMin())); } if (dto.getPriceMax() != null) { - query.where(Product.price.lt(dto.getPriceMax())); + query.where(product.price.lt(dto.getPriceMax())); } } // Order by title - query.orderBy(Product.title.desc()); + query.orderBy(product.title.desc()); - List Products = query.limit(dto.getPageSize()).offset(dto.getPageNumber() * dto.getPageSize()) + List products = query.limit(dto.getPageSize()).offset(dto.getPageNumber() * dto.getPageSize()) .fetch(); - return new PageImpl<>(Products, PageRequest.of(dto.getPageNumber(), dto.getPageSize()), Products.size()); + return new PageImpl<>(products, PageRequest.of(dto.getPageNumber(), dto.getPageSize()), products.size()); } @Override @@ -98,8 +98,8 @@ public Page findByTitleQuery(ProductSearchCriteriaDto dto) { Query query = this.em.createQuery("select a from ProductEntity a where a.title = :title"); query.setParameter("title", dto.getTitle()); - List Products = query.getResultList(); - return new PageImpl<>(Products, PageRequest.of(dto.getPageNumber(), dto.getPageSize()), Products.size()); + List products = query.getResultList(); + return new PageImpl<>(products, PageRequest.of(dto.getPageNumber(), dto.getPageSize()), products.size()); } @Override @@ -107,8 +107,8 @@ public Page findByTitleNativeQuery(ProductSearchCriteriaDto dto) Query query = this.em.createNativeQuery("select * from ProductEntity where title = :title", ProductEntity.class); query.setParameter("title", dto.getTitle()); - List Products = query.getResultList(); - return new PageImpl<>(Products, PageRequest.of(dto.getPageNumber(), dto.getPageSize()), Products.size()); + List products = query.getResultList(); + return new PageImpl<>(products, PageRequest.of(dto.getPageNumber(), dto.getPageSize()), products.size()); } } diff --git a/src/main/java/com/devonfw/quarkus/productmanagement/logic/UcFindProductImpl.java b/src/main/java/com/devonfw/quarkus/productmanagement/logic/UcFindProductImpl.java index 92b71f63..759f7dc0 100644 --- a/src/main/java/com/devonfw/quarkus/productmanagement/logic/UcFindProductImpl.java +++ b/src/main/java/com/devonfw/quarkus/productmanagement/logic/UcFindProductImpl.java @@ -32,59 +32,59 @@ public class UcFindProductImpl implements UcFindProduct { @Override public Page findProducts(ProductSearchCriteriaDto dto) { - Iterable ProductsIterator = this.ProductRepository.findAll(); - List Products = new ArrayList(); - ProductsIterator.forEach(Products::add); - List ProductsDto = this.mapper.map(Products); - return new PageImpl<>(ProductsDto, PageRequest.of(dto.getPageNumber(), dto.getPageSize()), ProductsDto.size()); + Iterable productsIterator = this.ProductRepository.findAll(); + List products = new ArrayList(); + productsIterator.forEach(products::add); + List productsDto = this.mapper.map(products); + return new PageImpl<>(productsDto, PageRequest.of(dto.getPageNumber(), dto.getPageSize()), productsDto.size()); } @Override public Page findProductsByCriteriaApi(ProductSearchCriteriaDto dto) { - List Products = this.ProductRepository.findAllCriteriaApi(dto).getContent(); - List ProductsDto = this.mapper.map(Products); - return new PageImpl<>(ProductsDto, PageRequest.of(dto.getPageNumber(), dto.getPageSize()), ProductsDto.size()); + List products = this.ProductRepository.findAllCriteriaApi(dto).getContent(); + List productsDto = this.mapper.map(products); + return new PageImpl<>(productsDto, PageRequest.of(dto.getPageNumber(), dto.getPageSize()), productsDto.size()); } @Override public Page findProductsByQueryDsl(ProductSearchCriteriaDto dto) { - List Products = this.ProductRepository.findAllQueryDsl(dto).getContent(); - List ProductsDto = this.mapper.map(Products); - return new PageImpl<>(ProductsDto, PageRequest.of(dto.getPageNumber(), dto.getPageSize()), ProductsDto.size()); + List products = this.ProductRepository.findAllQueryDsl(dto).getContent(); + List productsDto = this.mapper.map(products); + return new PageImpl<>(productsDto, PageRequest.of(dto.getPageNumber(), dto.getPageSize()), productsDto.size()); } @Override public Page findProductsByTitleQuery(ProductSearchCriteriaDto dto) { - List Products = this.ProductRepository.findByTitleQuery(dto).getContent(); - List ProductsDto = this.mapper.map(Products); - return new PageImpl<>(ProductsDto, PageRequest.of(dto.getPageNumber(), dto.getPageSize()), ProductsDto.size()); + List products = this.ProductRepository.findByTitleQuery(dto).getContent(); + List productsDto = this.mapper.map(products); + return new PageImpl<>(productsDto, PageRequest.of(dto.getPageNumber(), dto.getPageSize()), productsDto.size()); } @Override public Page findProductsByTitleNativeQuery(ProductSearchCriteriaDto dto) { - List Products = this.ProductRepository.findByTitleNativeQuery(dto).getContent(); - List ProductsDto = this.mapper.map(Products); - return new PageImpl<>(ProductsDto, PageRequest.of(dto.getPageNumber(), dto.getPageSize()), ProductsDto.size()); + List products = this.ProductRepository.findByTitleNativeQuery(dto).getContent(); + List productsDto = this.mapper.map(products); + return new PageImpl<>(productsDto, PageRequest.of(dto.getPageNumber(), dto.getPageSize()), productsDto.size()); } @Override public Page findProductsOrderedByTitle() { - List Products = this.ProductRepository.findAllByOrderByTitle().getContent(); - List ProductsDto = this.mapper.map(Products); - return new PageImpl<>(ProductsDto); + List products = this.ProductRepository.findAllByOrderByTitle().getContent(); + List productsDto = this.mapper.map(products); + return new PageImpl<>(productsDto); } @Override public ProductDto findProduct(String id) { - ProductEntity Product = this.ProductRepository.findById(Long.valueOf(id)).get(); - if (Product != null) { - return this.mapper.map(Product); + ProductEntity product = this.ProductRepository.findById(Long.valueOf(id)).get(); + if (product != null) { + return this.mapper.map(product); } else { return null; } @@ -93,9 +93,9 @@ public ProductDto findProduct(String id) { @Override public ProductDto findProductByTitle(String title) { - ProductEntity Product = this.ProductRepository.findByTitle(title); - if (Product != null) { - return this.mapper.map(Product); + ProductEntity product = this.ProductRepository.findByTitle(title); + if (product != null) { + return this.mapper.map(product); } else { return null; } diff --git a/src/main/java/com/devonfw/quarkus/productmanagement/logic/UcManageProductImpl.java b/src/main/java/com/devonfw/quarkus/productmanagement/logic/UcManageProductImpl.java index cccbb6be..d79477a3 100644 --- a/src/main/java/com/devonfw/quarkus/productmanagement/logic/UcManageProductImpl.java +++ b/src/main/java/com/devonfw/quarkus/productmanagement/logic/UcManageProductImpl.java @@ -14,7 +14,7 @@ @Transactional public class UcManageProductImpl implements UcManageProduct { @Inject - ProductRepository ProductRepository; + ProductRepository productRepository; @Inject ProductMapper mapper; @@ -22,17 +22,17 @@ public class UcManageProductImpl implements UcManageProduct { @Override public ProductDto saveProduct(NewProductDto dto) { - ProductEntity created = this.ProductRepository.save(this.mapper.create(dto)); + ProductEntity created = this.productRepository.save(this.mapper.create(dto)); return this.mapper.map(created); } @Override public ProductDto deleteProduct(String id) { - ProductEntity Product = this.ProductRepository.findById(Long.valueOf(id)).get(); - if (Product != null) { - this.ProductRepository.delete(Product); - return this.mapper.map(Product); + ProductEntity product = this.productRepository.findById(Long.valueOf(id)).get(); + if (product != null) { + this.productRepository.delete(product); + return this.mapper.map(product); } else { return null; } diff --git a/src/main/java/com/devonfw/quarkus/productmanagement/service/v1/model/NewProductDto.java b/src/main/java/com/devonfw/quarkus/productmanagement/service/v1/model/NewProductDto.java index a0c404dc..8a88bfff 100644 --- a/src/main/java/com/devonfw/quarkus/productmanagement/service/v1/model/NewProductDto.java +++ b/src/main/java/com/devonfw/quarkus/productmanagement/service/v1/model/NewProductDto.java @@ -1,5 +1,7 @@ package com.devonfw.quarkus.productmanagement.service.v1.model; +import java.math.BigDecimal; + import org.eclipse.microprofile.openapi.annotations.media.Schema; import lombok.Getter; @@ -9,12 +11,13 @@ @Setter public class NewProductDto { - @Schema(nullable = false, description = "Product title", minLength = 3, maxLength = 50) + @Schema(nullable = false, description = "Product title", minLength = 3, maxLength = 500) private String title; - @Schema(description = "Product tag line", minLength = 3, maxLength = 50) - private String basicInfo; - - @Schema(nullable = false, description = "Product description", minLength = 3, maxLength = 50) + @Schema(description = "Product description", minLength = 3, maxLength = 500) private String description; + + @Schema(description = "Product price", minLength = 1) + private BigDecimal price; + } diff --git a/src/main/java/com/devonfw/quarkus/productmanagement/service/v1/model/ProductDto.java b/src/main/java/com/devonfw/quarkus/productmanagement/service/v1/model/ProductDto.java index 733f4ec8..c3dd0465 100644 --- a/src/main/java/com/devonfw/quarkus/productmanagement/service/v1/model/ProductDto.java +++ b/src/main/java/com/devonfw/quarkus/productmanagement/service/v1/model/ProductDto.java @@ -13,8 +13,6 @@ public class ProductDto { private String title; - private String basicInfo; - private String description; private BigDecimal price; diff --git a/src/main/java/com/devonfw/quarkus/productmanagement/service/v1/model/ProductSearchCriteriaDto.java b/src/main/java/com/devonfw/quarkus/productmanagement/service/v1/model/ProductSearchCriteriaDto.java index f3dcdef5..1ad69ed5 100644 --- a/src/main/java/com/devonfw/quarkus/productmanagement/service/v1/model/ProductSearchCriteriaDto.java +++ b/src/main/java/com/devonfw/quarkus/productmanagement/service/v1/model/ProductSearchCriteriaDto.java @@ -23,9 +23,6 @@ public class ProductSearchCriteriaDto { @DefaultValue("10") private int pageSize = 10; - @QueryParam("description") - private String description; - @QueryParam("priceMin") private BigDecimal priceMin; diff --git a/src/test/java/com/devonfw/demoquarkus/service/v1/ProductRestServiceTest.java b/src/test/java/com/devonfw/demoquarkus/service/v1/ProductRestServiceTest.java index 0a176f7b..a67186c9 100644 --- a/src/test/java/com/devonfw/demoquarkus/service/v1/ProductRestServiceTest.java +++ b/src/test/java/com/devonfw/demoquarkus/service/v1/ProductRestServiceTest.java @@ -35,7 +35,6 @@ class ProductRestServiceTest {// extends AbstractTest { void getAll() { Response response = given().when().contentType(MediaType.APPLICATION_JSON).get("/products").then().statusCode(200) - // .body("$.size()", equalTo(2)) .extract().response(); PageResultDTO productsReturned = response.as(new TypeRef>() { @@ -57,12 +56,10 @@ void getNonExistingTest() { void createNewProduct() { ProductDto product = new ProductDto(); - product.setTitle("Dog"); - product.setBasicInfo("Live"); + product.setTitle("HP Notebook"); + product.setDescription("ZBook"); product.setPrice(BigDecimal.valueOf(1)); - // product.setNumberOfLegs(4); - Response response = given().when().body(product).contentType(MediaType.APPLICATION_JSON).post("/products").then() .log().all().statusCode(201).header("Location", notNullValue()).extract().response(); @@ -84,7 +81,7 @@ void createNewProduct() { public void testGetById() { given().when().log().all().contentType(MediaType.APPLICATION_JSON).get("/products/1").then().statusCode(200) - .body("basicInfo", equalTo("Cat")); + .body("description", equalTo("Apple Notebook")); } @Test @@ -93,7 +90,7 @@ public void deleteById() { // delete given().when().log().all().contentType(MediaType.APPLICATION_JSON).delete("/products/1").then().statusCode(200) - .body("title", equalTo("Kitty")); + .body("title", equalTo("MacBook Pro")); // after deletion it should be deleted given().when().log().all().contentType(MediaType.APPLICATION_JSON).get("/products/1").then().statusCode(404); diff --git a/src/test/resources/data/animal.xls b/src/test/resources/data/product.xls similarity index 68% rename from src/test/resources/data/animal.xls rename to src/test/resources/data/product.xls index 8b8fff4b6ded3d3d6946112c3023f4258476559e..5f633e3e64821ab9135cd87c8f1290d4f1ad94bf 100644 GIT binary patch delta 2880 zcmb`Jc|4SB8^@nnFf(S%SR(rj62~%~Q1*R{ee6myX|ivbV=HMK4N*DdCTl00EKyme zWDiN9Q$yrbhe(Q)mljTodLKHcPM^>F=lk5B=en=!`+M%|dOpwd$8{y=B9n8G_508w z?ypr@4qyyH21|n3X8{|Xh7bks&|xAjO5yWaXU7n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QiYuCWV>f~cU{ uSecIt-ZK2pa6Ig>fltQfRfjS(L3FGLsEj3Yi#l)h@ND1;`_9}r_WuA&xyN(> From b9994b794e9e90b40052b09deeb73579f05989fd Mon Sep 17 00:00:00 2001 From: TugbaDalmaz <89070914+TugbaDalmaz@users.noreply.github.com> Date: Wed, 8 Sep 2021 11:17:45 +0200 Subject: [PATCH 7/9] Change Animal to Product --- src/main/java/com/devonfw/quarkus/DemoApplication.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/devonfw/quarkus/DemoApplication.java b/src/main/java/com/devonfw/quarkus/DemoApplication.java index 3e958c38..1c0f6662 100644 --- a/src/main/java/com/devonfw/quarkus/DemoApplication.java +++ b/src/main/java/com/devonfw/quarkus/DemoApplication.java @@ -8,7 +8,7 @@ import org.eclipse.microprofile.openapi.annotations.tags.Tag; @OpenAPIDefinition(tags = { -@Tag(name = "Product", description = "Product API.") }, info = @Info(title = "My Demo App RESTful API", version = "1.0.0", contact = @Contact(name = "API Support", email = "support@acme.com"))) +@Tag(name = "product", description = "Product API.") }, info = @Info(title = "My Demo App RESTful API", version = "1.0.0", contact = @Contact(name = "API Support", email = "support@acme.com"))) /** * JaxRS application is not required in quarkus, but it is useful to place central API docs somewhere. We could also use * package-info.java for this. From a60ac784e3c8f12fbb6091ca0ce0fe17fa80bc79 Mon Sep 17 00:00:00 2001 From: TugbaDalmaz <89070914+TugbaDalmaz@users.noreply.github.com> Date: Wed, 8 Sep 2021 14:48:07 +0200 Subject: [PATCH 8/9] Change Animal to Product --- .../quarkus/productmanagement/domain/model/ProductEntity.java | 2 -- .../productmanagement/service/v1/model/NewProductDto.java | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/src/main/java/com/devonfw/quarkus/productmanagement/domain/model/ProductEntity.java b/src/main/java/com/devonfw/quarkus/productmanagement/domain/model/ProductEntity.java index 2466b1ab..b7b22ac0 100644 --- a/src/main/java/com/devonfw/quarkus/productmanagement/domain/model/ProductEntity.java +++ b/src/main/java/com/devonfw/quarkus/productmanagement/domain/model/ProductEntity.java @@ -20,8 +20,6 @@ public class ProductEntity extends ApplicationPersistenceEntity { private String title; - // every primitive attribute on this class will be represented as column in Product table - private String description; private BigDecimal price; diff --git a/src/main/java/com/devonfw/quarkus/productmanagement/service/v1/model/NewProductDto.java b/src/main/java/com/devonfw/quarkus/productmanagement/service/v1/model/NewProductDto.java index 8a88bfff..69cf8119 100644 --- a/src/main/java/com/devonfw/quarkus/productmanagement/service/v1/model/NewProductDto.java +++ b/src/main/java/com/devonfw/quarkus/productmanagement/service/v1/model/NewProductDto.java @@ -17,7 +17,7 @@ public class NewProductDto { @Schema(description = "Product description", minLength = 3, maxLength = 500) private String description; - @Schema(description = "Product price", minLength = 1) + @Schema(description = "Product price") private BigDecimal price; } From 1527e1f0f9fd749d01805c3936b9a206c4671c85 Mon Sep 17 00:00:00 2001 From: TugbaDalmaz <89070914+TugbaDalmaz@users.noreply.github.com> Date: Thu, 16 Sep 2021 19:08:10 +0200 Subject: [PATCH 9/9] Change Animal to Product --- src/test/resources/data/empty.xls | Bin 35328 -> 35328 bytes src/test/resources/data/product.xls | Bin 35328 -> 35328 bytes 2 files changed, 0 insertions(+), 0 deletions(-) diff --git a/src/test/resources/data/empty.xls b/src/test/resources/data/empty.xls index 8b6a5a46753c2af735ae78d96d99e4b1ce91e7c2..1ee268f00cf0b9d53e2849c1288d524fee56c9f3 100644 GIT binary patch delta 2620 zcmZvecT`j78^`YrVI*WiNP?h*p+E(q0wO3I2|Iuc2O1IC!;-QT@lp&3iWRva)2diz zlogF63|Uec)qp|j06|2dC!WH1IKx9=>k}Q^YA(!1rh#toJ7hRcq@^WE41vkEpMW&`OX_>ok15`3X*T#J_esWM z%kmKfECAT~M@0G`(W80A1|RT;ti-#Qv7ho(GzrK8 z0RTV%AH`(&Z;bp(0U5Tye%@ga0OeZ|6;1s1mxR*;L0~h`g!p1Zg3%c4XB&eR!;6^D z=fP{Rs1-s*Z~NAT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