Skip to content

Change Animal to Product#15

Merged
sobkowiak merged 9 commits into
devonfw-sample:masterfrom
TugbaDalmaz:changing_animals_to_products
Sep 17, 2021
Merged

Change Animal to Product#15
sobkowiak merged 9 commits into
devonfw-sample:masterfrom
TugbaDalmaz:changing_animals_to_products

Conversation

@TugbaDalmaz
Copy link
Copy Markdown
Contributor

@TugbaDalmaz TugbaDalmaz commented Aug 30, 2021

Closes #9

@TugbaDalmaz TugbaDalmaz self-assigned this Aug 30, 2021
* 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<Long> {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you don't need ApplicationEntity and GenericEntity. Just let your entity extend from ApplicationPersistenceEntity

@Id
@GeneratedValue
private Long id;
// private Long id;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove the outcommented lines. You can also remove the @Id and @GeneratedValue as they are no longer needed in this class as they are now included in ApplicationPersistenceEntity.

@@ -0,0 +1,87 @@
package com.devonfw.quarkus.productmanagement;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This class does not belong to any entity, as it is a base class for all entities. Therefore it should not be located in com.devonfw.quarkus.productmanagement. Better name it com.devonfw.quarkus.general.domain.model

@@ -1,4 +1,4 @@
package com.devonfw.demoquarkus;
package com.devonfw.quarkus.productmanagement;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This class is also a general class, so do not move it to the productmanagement package

if (dto.getTitle() != null && !dto.getTitle().isEmpty()) {
predicates.add(cb.like(root.get(ProductEntity_.TITLE), dto.getTitle()));
}
// if (dto.getNumberOfLegs() != null) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove the outcommented lines

// }

BigDecimal price, priceMin, priceMax, x;
if (dto.getPriceMin() != null | dto.getPriceMax() != null) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For a logical or use two pipes ||


BigDecimal price, priceMin, priceMax, x;
if (dto.getPriceMin() != null | dto.getPriceMax() != null) {
if (priceMin.compareTo(x) == 0 | priceMax.compareTo(x) == 0) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no value assigned to priceMin, priceMax and x


//In Quarkus all JAX-RS resources are treated as CDI beans
//default is Singleton scope
@Path("/Products")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use lowercase letters for the paths


ProductDto findProductByTitle(String title);

ProductDto sortProductByPrice(BigDecimal priceMin, BigDecimal priceMax);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You define this method in the interface but not in the implementing class


private String description;

private BigDecimal price, priceMin, priceMax;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why priceMin and Max attribute in the entity? here we should only define a property price


// 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;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we do not need the basicInfo attribute anymore, because we have the descrption now. So you can remove it from here and the corresponding transfer objects

@Override
public Page<ProductDto> findProducts(ProductSearchCriteriaDto dto) {

Iterable<ProductEntity> ProductsIterator = this.ProductRepository.findAll();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Start variable names with a lowercase letter. Also change this in the other files


@Getter
@Setter
public class NewProductDto {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The price is missing here

animal.setBasicInfo("Live");
animal.setNumberOfLegs(4);
ProductDto product = new ProductDto();
product.setTitle("Dog");
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use meaningful content for the test cases

product.setPrice(BigDecimal.valueOf(1));

Response response = given().when().body(animal).contentType(MediaType.APPLICATION_JSON).post("/animals").then()
// product.setNumberOfLegs(4);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove the comments not needed


@Test
@WithDBData(value = "data/animal.xls", deleteBeforeInsert = true)
@WithDBData(value = "data/product.xls", deleteBeforeInsert = true)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You also have to change the name of the file in src/test/resources/data. Also change the content, so that it does match with the test cases


private String title;

// every primitive attribute on this class will be represented as column in Product table
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this comment from here

@Schema(description = "Product description", minLength = 3, maxLength = 500)
private String description;

@Schema(description = "Product price", minLength = 1)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove the minLength property, as this is only for strings (see here)

@sobkowiak
Copy link
Copy Markdown
Collaborator

Hi @TugbaDalmaz. When you look into the xls files under /src/test/resources/data/ there is still the tab name ANIMAL.

@TugbaDalmaz
Copy link
Copy Markdown
Contributor Author

@sobkowiak Ok thank you very much for the information. I have fixed it.

@sobkowiak
Copy link
Copy Markdown
Collaborator

Accepting this pull request although test case are broken, because they were broken before. Please implement #18 with high priority.

@sobkowiak sobkowiak merged commit 4351313 into devonfw-sample:master Sep 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Change quarkus reference app from animals to products

5 participants