Skip to content

Commit

Permalink
Merge pull request refactor/category
Browse files Browse the repository at this point in the history
Add an attribute to the DTO and Entity of the Category
  • Loading branch information
superpollo2 authored May 9, 2024
2 parents 50e3b62 + c318be3 commit 1332587
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src/main/java/com/consola/lis/dto/CategoryDTO.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ public class CategoryDTO {
@NotBlank(message = "Category name is required")
private String categoryName;

private String idFieldName;

@NotNull(message = "Quantizable status is required")
private Boolean quantizable;

Expand Down
3 changes: 3 additions & 0 deletions src/main/java/com/consola/lis/model/entity/Category.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ public class Category {
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;

@Column(name = "id_item_field")
private String idItemField;

@Column(name = "category_name")
private String categoryName;
private Boolean quantizable;
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/consola/lis/service/CategoryService.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public void createCategory(CategoryDTO categoryRequest) throws JsonProcessingExc
String listAttributesJson = objectMapper.writeValueAsString(categoryRequest.getListAttributes());
Category category = Category.builder()
.categoryName(categoryRequest.getCategoryName().toLowerCase())
.idItemField(categoryRequest.getIdFieldName())
.quantizable(categoryRequest.getQuantizable())
.attributes(attributesJson)
.listAttributes(listAttributesJson)
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/application-dev.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ spring.ldap.urls=rls=https://sistemas.udea.edu.co/api/ldap/login/{username}
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.username=root
spring.datasource.password=
spring.datasource.url=jdbc:mysql://localhost:3306/console_lis?allowPublicKeyRetrieval=true&useSSL=false
spring.datasource.url=jdbc:mysql://lcoalhost:3306/console_lis?allowPublicKeyRetrieval=true&useSSL=false
springdoc.default-produces-media-type=application/json
spring.jpa.show-sql=true

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ void testGetAllCategories() {
@Test
void testCreateCategory_Success() throws JsonProcessingException {

CategoryDTO categoryDTO= new CategoryDTO("Test Category",true,new String[]{"Attribute1"},new ListAttributeDTO[]{new ListAttributeDTO()});
CategoryDTO categoryDTO= new CategoryDTO("Test Category","test",true,new String[]{"Attribute1"},new ListAttributeDTO[]{new ListAttributeDTO()});
when(categoryRepository.existsByCategoryName("Test Category")).thenReturn(false);
//act
categoryService.createCategory(categoryDTO);
Expand All @@ -60,7 +60,7 @@ void testCreateCategory_Success() throws JsonProcessingException {
@Test
void testCreateCategory_CategoryAlreadyExists() {

CategoryDTO categoryDTO= new CategoryDTO("Test Category",true,new String[]{"Attribute1"},new ListAttributeDTO[]{new ListAttributeDTO()});
CategoryDTO categoryDTO= new CategoryDTO("Test Category","test",true,new String[]{"Attribute1"},new ListAttributeDTO[]{new ListAttributeDTO()});
when(categoryRepository.existsByCategoryName("Test Category")).thenReturn(true);

assertThrows(AlreadyExistsException.class, () -> categoryService.createCategory(categoryDTO));
Expand Down

0 comments on commit 1332587

Please sign in to comment.