Skip to content

Commit

Permalink
Merge pull request feat/mappers
Browse files Browse the repository at this point in the history
Data Normalization Mapper
  • Loading branch information
superpollo2 authored Apr 19, 2024
2 parents 57f0892 + e4d2cbf commit 6848831
Show file tree
Hide file tree
Showing 30 changed files with 178 additions and 92 deletions.
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20240303</version>
</dependency>
<dependency>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.consola.lis.configuration;


import io.swagger.v3.oas.models.security.SecurityRequirement;
import io.swagger.v3.oas.models.security.SecurityScheme;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Info;
Expand All @@ -26,14 +25,14 @@ public OpenAPI swagger() {
.bearerFormat("JWT");

// Define security requirement for endpoints that require Bearer token
SecurityRequirement securityRequirement = new SecurityRequirement()
.addList("bearerAuth");
// SecurityRequirement securityRequirement = new SecurityRequirement()
// .addList("bearerAuth");

// Create OpenAPI object and configure servers, info, security schemes, and security requirements
return new OpenAPI()
.info(info)
.components(new io.swagger.v3.oas.models.Components().addSecuritySchemes("bearerAuth", securityScheme))
.addSecurityItem(securityRequirement);
.components(new io.swagger.v3.oas.models.Components().addSecuritySchemes("bearerAuth", securityScheme));
//.addSecurityItem(securityRequirement);


}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.consola.lis.controller;


import com.consola.lis.constans.EndpointConstant;
import com.consola.lis.util.constans.EndpointConstant;
import com.consola.lis.dto.CategoryDTO;
import com.consola.lis.model.entity.Category;
import com.consola.lis.service.CategoryService;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.consola.lis.controller;

import com.consola.lis.dto.ErrorDTO;
import com.consola.lis.exception.*;
import com.consola.lis.util.exception.*;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
Expand Down
20 changes: 0 additions & 20 deletions src/main/java/com/consola/lis/controller/Holi.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.consola.lis.controller;

import com.consola.lis.constans.EndpointConstant;
import com.consola.lis.util.constans.EndpointConstant;
import com.consola.lis.dto.GeneralItemDTO;
import com.consola.lis.dto.QuantizableItemDTO;
import com.consola.lis.model.entity.GeneralItem;
Expand All @@ -12,6 +12,7 @@
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.Map;

@Tag(name = "Manage for Inventory", description = "something")
@RestController
Expand Down Expand Up @@ -50,8 +51,9 @@ public void deleteCategory(@PathVariable("itemId") String itemId){
}

@GetMapping
public List<Object> inventoryItems() {
return inventoryItemService.getAllItems();
public Map<String, Object> inventoryItems() {
System.out.println("al menos me dan click");
return inventoryItemService.getAllItemsMapped();
}

@GetMapping(EndpointConstant.ENDPOINT_ONE_GENERAL_ITEM)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.consola.lis.controller;

import com.consola.lis.constans.EndpointConstant;
import com.consola.lis.util.constans.EndpointConstant;
import com.consola.lis.dto.AuthResponseDTO;
import com.consola.lis.dto.LoginRequestDTO;
import com.consola.lis.service.LoginService;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.consola.lis.controller;


import com.consola.lis.constans.EndpointConstant;
import com.consola.lis.util.constans.EndpointConstant;
import com.consola.lis.dto.AuthResponseDTO;
import com.consola.lis.dto.RegisterRequestDTO;
import com.consola.lis.service.RegisterService;
Expand Down
14 changes: 7 additions & 7 deletions src/main/java/com/consola/lis/controller/UserController.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.consola.lis.controller;


import com.consola.lis.constans.EndpointConstant;
import com.consola.lis.util.constans.EndpointConstant;
import com.consola.lis.dto.AuthResponseDTO;
import com.consola.lis.dto.UserDTO;
import com.consola.lis.model.entity.User;
Expand All @@ -21,24 +21,24 @@
public class UserController {

private final UserService userService;
@GetMapping("/{userName}")
public User oneUser(@PathVariable("userName") String userId){
return userService.getUser(userId);
@GetMapping(EndpointConstant.ENDPOINT_ONE_USER)
public ResponseEntity<UserDTO> oneUser(@PathVariable("username") String userId){
return ResponseEntity.ok(userService.getUser(userId));
}


@Operation(summary = "This method is used to login the options valid are ADMIN, AUXPROG, AUXADMI")
@PatchMapping("/role/{username}")
@PatchMapping(EndpointConstant.ENDPOINT_CHANGE_ROLE_USER)
public ResponseEntity<AuthResponseDTO> changeRole(@PathVariable("username") String username, @RequestBody UserRole userRole){
return ResponseEntity.ok(userService.changeUserRole(username, userRole));
}

@GetMapping("/ldapUser/{username}")
@GetMapping(EndpointConstant.ENDPOINT_USER_LDAP)
public ResponseEntity<UserDTO> userLDAP(@PathVariable("username") String username){
return ResponseEntity.ok(userService.getUserLDAP(username));
}

@DeleteMapping("/{username}")
@DeleteMapping(EndpointConstant.ENDPOINT_DELETE_USER)
public void deleteUser(@PathVariable("username") String username){
userService.deleteUser(username);
}
Expand Down
19 changes: 19 additions & 0 deletions src/main/java/com/consola/lis/dto/ItemInfoDTO.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.consola.lis.dto;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class ItemInfoDTO {
private String id;
private String state;
private String category;
private String wallet;
private String[] attributes;
private boolean quantizable;
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.consola.lis.jwt;

import com.consola.lis.exception.JwtExpiredException;
import com.consola.lis.util.exception.JwtExpiredException;
import io.jsonwebtoken.ExpiredJwtException;
import jakarta.servlet.FilterChain;
import jakarta.servlet.ServletException;
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/consola/lis/service/CategoryService.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@


import com.consola.lis.dto.CategoryDTO;
import com.consola.lis.exception.AlreadyExistsException;
import com.consola.lis.exception.NotExistingException;
import com.consola.lis.util.exception.AlreadyExistsException;
import com.consola.lis.util.exception.NotExistingException;
import com.consola.lis.model.entity.Category;
import com.consola.lis.model.repository.CategoryRepository;
import com.fasterxml.jackson.core.JsonProcessingException;
Expand Down
49 changes: 40 additions & 9 deletions src/main/java/com/consola/lis/service/InventoryItemService.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package com.consola.lis.service;


import com.consola.lis.constans.Util;
import com.consola.lis.dto.ItemInfoDTO;
import com.consola.lis.util.constans.Util;
import com.consola.lis.dto.GeneralItemDTO;
import com.consola.lis.dto.QuantizableItemDTO;
import com.consola.lis.exception.AlreadyExistsException;
import com.consola.lis.exception.IllegalParameterInRequest;
import com.consola.lis.exception.NotExistingException;
import com.consola.lis.util.exception.AlreadyExistsException;
import com.consola.lis.util.exception.IllegalParameterInRequest;
import com.consola.lis.util.exception.NotExistingException;
import com.consola.lis.model.entity.Category;
import com.consola.lis.model.entity.GeneralItem;
import com.consola.lis.model.entity.QuantizableItem;
Expand All @@ -15,6 +16,7 @@
import com.consola.lis.model.repository.CategoryRepository;
import com.consola.lis.model.repository.GeneralItemRepository;
import com.consola.lis.model.repository.QuantizableItemRepository;
import com.consola.lis.util.mapper.InventoryItemMapper;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import jakarta.transaction.Transactional;
Expand All @@ -23,6 +25,7 @@

import java.util.*;


@Service

public class InventoryItemService {
Expand All @@ -32,6 +35,7 @@ public class InventoryItemService {
private final QuantizableItemRepository quantizableItemRepository;
private final CategoryRepository categoryRepository;


private final Map<Boolean, Map<Boolean, List<String>>> validStatesMap = new HashMap<>();

public InventoryItemService(ObjectMapper objectMapper,
Expand Down Expand Up @@ -183,17 +187,44 @@ public boolean existItem(String itemId) {
return generalItemRepository.existsById(itemId);
}

public List<Object> getAllItems() {
public Map<String, Object> getAllItemsMapped() {
List<ItemInfoDTO> inventoryItems = getAllItems();
Map<String, Object> result = new HashMap<>();
result.put("header", createHeader());
result.put("allRegisters", inventoryItems);
return result;
}

private List<String> createHeader() {
List<String> header = new ArrayList<>();
header.add("Id");
header.add("Estado");
header.add("Categoría");
header.add("Wallet");
header.add("Atributos");
return header;
}

private List<ItemInfoDTO> getAllItems() {
List<GeneralItem> generalItems = getAllGeneralItems();
List<Object> inventoryItems = new ArrayList<>(generalItems);
List<QuantizableItem> quantizableItems = getAllQuantizableItems();
inventoryItems.addAll(quantizableItems);

return inventoryItems;
List<ItemInfoDTO> inventoryItems = new ArrayList<>();

}
generalItems.forEach(generalItem -> {
Category category = categoryRepository.findCategoryById(generalItem.getCategoryId());
inventoryItems.add(InventoryItemMapper.mapToItemInfoDTO(generalItem, category));
});

// Mapear los QuantizableItems
quantizableItems.forEach(quantizableItem -> {
GeneralItem generalItem = quantizableItem.getGeneralItem();
Category category = categoryRepository.findCategoryById(generalItem.getCategoryId());
inventoryItems.add(InventoryItemMapper.mapToItemInfoDTO(generalItem, category));
});


return inventoryItems;
}

}
2 changes: 1 addition & 1 deletion src/main/java/com/consola/lis/service/LoginService.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import com.consola.lis.dto.AuthResponseDTO;
import com.consola.lis.dto.LoginRequestDTO;
import com.consola.lis.exception.UserAuthenticationException;
import com.consola.lis.util.exception.UserAuthenticationException;
import com.consola.lis.jwt.JwtService;
import com.consola.lis.model.entity.User;
import com.consola.lis.model.repository.UserRepository;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/consola/lis/service/RegisterService.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import com.consola.lis.dto.AuthResponseDTO;
import com.consola.lis.dto.RegisterRequestDTO;
import com.consola.lis.exception.AlreadyExistsException;
import com.consola.lis.util.exception.AlreadyExistsException;
import com.consola.lis.jwt.JwtService;
import com.consola.lis.model.entity.User;
import com.consola.lis.model.repository.UserRepository;
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/com/consola/lis/service/UserService.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

import com.consola.lis.dto.AuthResponseDTO;
import com.consola.lis.dto.UserDTO;
import com.consola.lis.exception.NotExistingException;
import com.consola.lis.util.mapper.UserMapper;
import com.consola.lis.util.exception.NotExistingException;
import com.consola.lis.jwt.JwtService;
import com.consola.lis.model.entity.User;
import com.consola.lis.model.enums.UserRole;
Expand All @@ -25,13 +26,12 @@ public class UserService {
public final PasswordEncoder passwordEncoder;
public final JwtService jwtService;

public User getUser(String username) {

public UserDTO getUser(String username) {
Optional<User> user = userRepository.findByUsername(username);
if (user.isEmpty()) {
throw new NotExistingException("404", HttpStatus.NOT_FOUND, "the category whit id " + username + " not exist ");
} else {
return user.get();
}
} else return UserMapper.mapToUserDTO(user.get());
}


Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.consola.lis.constans;
package com.consola.lis.util.constans;

import lombok.experimental.UtilityClass;

Expand All @@ -14,7 +14,7 @@ public class EndpointConstant {
public static final String ENDPOINT_CATEGORY = "/api/console-lis/auth/category";
public static final String ENDPOINT_DELETE_CATEGORY = "/{categoryName}";
public static final String ENDPOINT_ONE_CATEGORY = "/{categoryName}";
public static final String ENDPOINT_ALL_NAMES_CATEGORYS = "/CategoriesNames";
public static final String ENDPOINT_ALL_NAMES_CATEGORYS = "/categoriesNames";


//Endpoints Inventory Item
Expand All @@ -34,6 +34,14 @@ public class EndpointConstant {
//user

public static final String ENDPOINT_USER = "/api/console-lis/auth/user";
public static final String ENDPOINT_ONE_USER ="/{username}";
public static final String ENDPOINT_USER_LDAP = "/ldapUser/{username}";
public static final String ENDPOINT_DELETE_USER = "/delete/{username}";
public static final String ENDPOINT_CHANGE_ROLE_USER = "/role/{username}";







Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.consola.lis.constans;
package com.consola.lis.util.constans;

import lombok.experimental.UtilityClass;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.consola.lis.exception;
package com.consola.lis.util.exception;

import lombok.Data;
import lombok.EqualsAndHashCode;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.consola.lis.exception;
package com.consola.lis.util.exception;


import lombok.Data;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.consola.lis.exception;
package com.consola.lis.util.exception;

import lombok.Data;
import lombok.EqualsAndHashCode;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.consola.lis.exception;
package com.consola.lis.util.exception;

import lombok.Data;
import lombok.EqualsAndHashCode;
Expand Down
Loading

0 comments on commit 6848831

Please sign in to comment.