03-02-2025 10:57
parent
8f95df0a27
commit
f2eafc9149
|
@ -47,9 +47,6 @@
|
|||
<classpathentry kind="src" output="target/test-classes" path="target/generated-test-sources/test-annotations">
|
||||
<attributes>
|
||||
<attribute name="optional" value="true"/>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
<attribute name="ignore_optional_problems" value="true"/>
|
||||
<attribute name="m2e-apt" value="true"/>
|
||||
<attribute name="test" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
|
|
|
@ -22,6 +22,7 @@ import org.springframework.data.domain.Pageable;
|
|||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/users")
|
||||
public class UserController {
|
||||
|
@ -32,7 +33,8 @@ public class UserController {
|
|||
private UserService userService;
|
||||
|
||||
@PostMapping("/createUser")
|
||||
public ResponseEntity<Response<List<Map<String, Object>>>> createInternalUsers(@RequestBody List<UserDTO> userDTOs) {
|
||||
public ResponseEntity<Response<List<Map<String, Object>>>> createInternalUsers(
|
||||
@RequestBody List<UserDTO> userDTOs) {
|
||||
log.info("Received request to create/update users: {}", userDTOs);
|
||||
try {
|
||||
Response<List<Map<String, Object>>> response = userService.createInternalUsers(userDTOs);
|
||||
|
@ -55,13 +57,13 @@ public class UserController {
|
|||
|
||||
@PutMapping("/update")
|
||||
public ResponseEntity<Response<Map<String, Object>>> updateUser(
|
||||
@RequestParam(required = false) String userEmpTransCode,
|
||||
@RequestBody UserUpdateDTO userUpdateDTO) {
|
||||
log.info("Received request to update user with employeeTransCode: {} or email: {}", userEmpTransCode, userUpdateDTO.getEmailId());
|
||||
@RequestParam(required = false) String userEmpTransCode, @RequestBody UserUpdateDTO userUpdateDTO) {
|
||||
log.info("Received request to update user with employeeTransCode: {} or email: {}", userEmpTransCode,
|
||||
userUpdateDTO.getEmailId());
|
||||
|
||||
// Validate input
|
||||
if ((userEmpTransCode == null || userEmpTransCode.isEmpty()) &&
|
||||
(userUpdateDTO.getEmailId() == null || userUpdateDTO.getEmailId().isEmpty())) {
|
||||
if ((userEmpTransCode == null || userEmpTransCode.isEmpty())
|
||||
&& (userUpdateDTO.getEmailId() == null || userUpdateDTO.getEmailId().isEmpty())) {
|
||||
log.warn("Invalid request: Either employeeTransCode or email must be provided.");
|
||||
return ResponseEntity.status(HttpStatus.BAD_REQUEST)
|
||||
.body(Response.error(400, "Either employeeTransCode or email must be provided."));
|
||||
|
@ -75,13 +77,11 @@ public class UserController {
|
|||
|
||||
} catch (UserNotFoundException e) {
|
||||
log.warn("User not found: {}", e.getMessage());
|
||||
return ResponseEntity.status(HttpStatus.NOT_FOUND)
|
||||
.body(Response.error(404, e.getMessage()));
|
||||
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(Response.error(404, e.getMessage()));
|
||||
|
||||
} catch (IllegalArgumentException e) {
|
||||
log.warn("Invalid input: {}", e.getMessage());
|
||||
return ResponseEntity.status(HttpStatus.BAD_REQUEST)
|
||||
.body(Response.error(400, e.getMessage()));
|
||||
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(Response.error(400, e.getMessage()));
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("Unexpected error occurred while updating user: {}", e.getMessage(), e);
|
||||
|
@ -90,8 +90,6 @@ public class UserController {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// @PutMapping("/update")
|
||||
// public ResponseEntity<String> updateUser(@RequestParam String userEmpTransCode,
|
||||
// @RequestBody UserUpdateDTO userUpdateDTO) {
|
||||
|
@ -107,8 +105,7 @@ public class UserController {
|
|||
// }
|
||||
|
||||
@GetMapping("/getallUserWithPagination")
|
||||
public ResponseEntity<Page<User>> getAllUsers(
|
||||
@RequestParam(defaultValue = "0") int pageNumber,
|
||||
public ResponseEntity<Page<User>> getAllUsers(@RequestParam(defaultValue = "0") int pageNumber,
|
||||
@RequestParam(defaultValue = "10") int pageSize) {
|
||||
log.info("Fetching all users with page: {} and size: {}", pageNumber, pageSize);
|
||||
|
||||
|
@ -149,8 +146,7 @@ public class UserController {
|
|||
}
|
||||
|
||||
@GetMapping("/getAllAndUserWithStatusPagination")
|
||||
public Response<Page<UserDTO>> getUsersWithPagination(
|
||||
@RequestParam(defaultValue = "0") int pageNumber,
|
||||
public Response<Page<UserDTO>> getUsersWithPagination(@RequestParam(defaultValue = "0") int pageNumber,
|
||||
@RequestParam(defaultValue = "10") int pageSize,
|
||||
@RequestParam(value = "status", required = false) String status) {
|
||||
|
||||
|
@ -172,31 +168,11 @@ public class UserController {
|
|||
}
|
||||
|
||||
@PostMapping("/userdetails")
|
||||
public ResponseEntity<Response<Page<Map<String, Object>>>> getUserDetails(
|
||||
@RequestBody Map<String, Object> req, Pageable pageable) {
|
||||
public ResponseEntity<Page<List<Map<String, Object>>>> getUserDetails(@RequestBody Map<String, Object> req,
|
||||
Pageable pageable) {
|
||||
log.info("Received request to fetch user details with filters: {}", req);
|
||||
try {
|
||||
// Call the service to fetch user details
|
||||
Page<Map<String, Object>> userDetails = userService.getUserDetails(req, pageable);
|
||||
return ResponseEntity.status(HttpStatus.MULTI_STATUS).body(userService.getUserDetails(req, pageable));
|
||||
|
||||
// Check if the result is empty and respond accordingly
|
||||
if (userDetails.isEmpty()) {
|
||||
log.info("No user details found for the provided filters.");
|
||||
return ResponseEntity.ok(new Response<>(204,"No User details found for the provided filters.", userDetails));
|
||||
}
|
||||
|
||||
// Return success response with transporter details
|
||||
log.info("Successfully fetched user details.");
|
||||
return ResponseEntity.ok(new Response<>(200,"User details fetched successfully.",userDetails));
|
||||
} catch (Exception e) {
|
||||
// Log the exception
|
||||
log.error("Error fetching user details.", e);
|
||||
|
||||
// Return error response
|
||||
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(
|
||||
new Response<>(500, "An error occurred while fetching user details. Please try again later.", null)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@GetMapping("/userdropdown")
|
||||
|
@ -240,4 +216,3 @@ public class UserController {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -45,7 +45,7 @@ public interface UserRepository extends JpaRepository<User, Integer> {
|
|||
|
||||
@Query(value="SELECT user_Id, usertype_id, user_name, user_fname, user_lname, user_email, user_mobile, " +
|
||||
"user_emp_trans_code, user_added_channel, created_by, last_updated_by, last_updated_on, status FROM UserMaster u " +
|
||||
"WHERE u.status = 'A' and u.user_name = :userName", nativeQuery = true)
|
||||
"WHERE u.status = 'A' and u.user_email = :userName", nativeQuery = true)
|
||||
User getUserIDByUserName(String userName);
|
||||
|
||||
|
||||
|
|
|
@ -48,7 +48,7 @@ public interface UserService {
|
|||
|
||||
List<User> getUsersByActive_Inactive(List<String> status);
|
||||
|
||||
Page<Map<String, Object>> getUserDetails(Map<String, Object> req, Pageable pageable);
|
||||
Page<List<Map<String, Object>>> getUserDetails(Map<String, Object> req, Pageable pageable);
|
||||
|
||||
Response<Map<String, Object>> updateUser(String userEmpTransCode, UserUpdateDTO userUpdateDTO);
|
||||
|
||||
|
|
|
@ -13,7 +13,6 @@ import org.springframework.beans.BeanUtils;
|
|||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageImpl;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
|
@ -252,8 +251,9 @@ public class UserServiceImpl implements UserService {
|
|||
}
|
||||
|
||||
// Fetch user by employeeTransCode or email
|
||||
log.info("line 254");
|
||||
User existingUser = userRepository.findByEmployeeTransCodeOrEmail(employeeTransCode, userUpdateDTO.getEmailId());
|
||||
|
||||
log.info("line 256 => "+existingUser);
|
||||
if (existingUser == null) {
|
||||
throw new UserNotFoundException("User not found with provided employeeTransCode or email.");
|
||||
}
|
||||
|
@ -455,7 +455,7 @@ public class UserServiceImpl implements UserService {
|
|||
|
||||
|
||||
@Override
|
||||
public Page<Map<String, Object>> getUserDetails(Map<String, Object> req, Pageable pageable) {
|
||||
public Page<List<Map<String, Object>>> getUserDetails(Map<String, Object> req, Pageable pageable) {
|
||||
StringBuffer userQuery = new StringBuffer(
|
||||
"SELECT u.user_id, u.usertype_id, ut.usertype_name, u.user_name, u.user_fname, u.user_lname, " +
|
||||
"u.user_email, u.user_mobile, u.user_emp_trans_code, u.user_added_channel, u.status, u.created_on, " +
|
||||
|
@ -471,41 +471,43 @@ public class UserServiceImpl implements UserService {
|
|||
|
||||
try {
|
||||
// Add filters dynamically
|
||||
if (req.containsKey("userName") && req.get("userName") != null && !req.get("userName").toString().isEmpty()) {
|
||||
if (req.containsKey("userName") && req.get("userName") != null && !req.get("userName").toString().equalsIgnoreCase("")) {
|
||||
userQuery.append(" AND u.user_name = '").append(req.get("userName").toString()).append("'");
|
||||
userCountQuery.append(" AND u.user_name = '").append(req.get("userName").toString()).append("'");
|
||||
}
|
||||
if (req.containsKey("Email") && req.get("Email") != null && !req.get("Email").toString().isEmpty()) {
|
||||
if (req.containsKey("Email") && req.get("Email") != null && !req.get("Email").toString().equalsIgnoreCase("")) {
|
||||
userQuery.append(" AND u.user_email = '").append(req.get("Email").toString()).append("'");
|
||||
userCountQuery.append(" AND u.user_email = '").append(req.get("Email").toString()).append("'");
|
||||
}
|
||||
if (req.containsKey("userTypeName") && req.get("userTypeName") != null && !req.get("userTypeName").toString().isEmpty()) {
|
||||
if (req.containsKey("userTypeName") && req.get("userTypeName") != null && !req.get("userTypeName").toString().equalsIgnoreCase("")) {
|
||||
userQuery.append(" AND ut.usertype_name = '").append(req.get("userTypeName").toString()).append("'");
|
||||
userCountQuery.append(" AND ut.usertype_name = '").append(req.get("userTypeName").toString()).append("'");
|
||||
}
|
||||
if (req.containsKey("status") && req.get("status") != null && !req.get("status").toString().isEmpty()) {
|
||||
if (req.containsKey("status") && req.get("status") != null && !req.get("status").toString().equalsIgnoreCase("")) {
|
||||
userQuery.append(" AND u.status = '").append(req.get("status").toString()).append("'");
|
||||
userCountQuery.append(" AND u.status = '").append(req.get("status").toString()).append("'");
|
||||
}
|
||||
if (req.containsKey("EmployeeTransCode") && req.get("EmployeeTransCode") != null && !req.get("EmployeeTransCode").toString().isEmpty()) {
|
||||
if (req.containsKey("EmployeeTransCode") && req.get("EmployeeTransCode") != null && !req.get("EmployeeTransCode").toString().equalsIgnoreCase("")) {
|
||||
userQuery.append(" AND u.user_emp_trans_code = '").append(req.get("EmployeeTransCode").toString()).append("'");
|
||||
userCountQuery.append(" AND u.user_emp_trans_code = '").append(req.get("EmployeeTransCode").toString()).append("'");
|
||||
}
|
||||
|
||||
// Add sorting and pagination to the data query
|
||||
userQuery.append(" ORDER BY ").append(pageable.getSort().toString().replace(":", " "));
|
||||
userQuery.append(" LIMIT ").append(pageable.getPageSize()).append(" OFFSET ").append(pageable.getOffset());
|
||||
// userQuery.append(" ORDER BY ").append(pageable.getSort().toString().replace(":", " "));
|
||||
// userQuery.append(" LIMIT ").append(pageable.getPageSize()).append(" OFFSET ").append(pageable.getOffset());
|
||||
|
||||
// Execute queries
|
||||
log.info("userQuery => {}",userQuery.toString());
|
||||
log.info("userCountQuery => {}",userCountQuery.toString());
|
||||
List<Map<String, Object>> result = temp.queryForList(userQuery.toString());
|
||||
Long totalCount = temp.queryForObject(userCountQuery.toString(), Long.class);
|
||||
|
||||
// Return the paginated result
|
||||
return new PageImpl<>(result, pageable, totalCount);
|
||||
return new PageImpl<>(List.of(result), pageable, totalCount);
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("Error while fetching user details: {}", e.getMessage());
|
||||
return Page.empty();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -23,6 +23,8 @@ spring.jpa.properties.hibernate.use_sql_comments=true
|
|||
spring.jpa.properties.hibernate.jdbc.batch_size=20
|
||||
spring.jpa.properties.hibernate.order_inserts=true
|
||||
spring.jpa.properties.hibernate.order_updates=true
|
||||
spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
|
||||
|
||||
|
||||
# ===============================
|
||||
# Logging Configuration
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#Generated by Maven Integration for Eclipse
|
||||
#Sat Feb 01 09:05:48 IST 2025
|
||||
#Sat Feb 01 17:48:26 IST 2025
|
||||
artifactId=inbound-user-service
|
||||
groupId=com.sahyog.app.inbound
|
||||
m2e.projectLocation=C\:\\MyProject\\CODE\\Source Code\\Git\\Backup\\inbound-user-service
|
||||
|
|
|
@ -23,6 +23,8 @@ spring.jpa.properties.hibernate.use_sql_comments=true
|
|||
spring.jpa.properties.hibernate.jdbc.batch_size=20
|
||||
spring.jpa.properties.hibernate.order_inserts=true
|
||||
spring.jpa.properties.hibernate.order_updates=true
|
||||
spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
|
||||
|
||||
|
||||
# ===============================
|
||||
# Logging Configuration
|
||||
|
|
Binary file not shown.
Binary file not shown.
|
@ -0,0 +1,86 @@
|
|||
com\sahyog\app\inbound\user\model\UserType1.class
|
||||
com\sahyog\app\inbound\user\repository\TransporterRepository.class
|
||||
com\sahyog\app\inbound\user\serviceImpl\UserRoleServiceImpl.class
|
||||
com\sahyog\app\inbound\user\mapper\UserTypeMapper.class
|
||||
com\sahyog\app\inbound\user\serviceImpl\MaterialMasterServiceImpl.class
|
||||
com\sahyog\app\inbound\user\exception\RoleNotFoundException.class
|
||||
com\sahyog\app\inbound\user\controller\PlantMasterController.class
|
||||
com\sahyog\app\inbound\user\controller\UserController.class
|
||||
com\sahyog\app\inbound\user\service\UserPlantService.class
|
||||
com\sahyog\app\inbound\user\repository\RoleRepository.class
|
||||
com\sahyog\app\inbound\user\repository\MaterialMasterRepository.class
|
||||
com\sahyog\app\inbound\user\enums\UserType.class
|
||||
com\sahyog\app\inbound\user\exception\RoleAlreadyExistsException.class
|
||||
com\sahyog\app\inbound\user\mapper\RoleMapper.class
|
||||
com\sahyog\app\inbound\user\serviceImpl\UserPlantServiceImpl.class
|
||||
com\sahyog\app\inbound\user\exception\UserNotFoundException.class
|
||||
com\sahyog\app\inbound\user\service\TransporterService.class
|
||||
com\sahyog\app\inbound\user\dto\TransporterResponse.class
|
||||
com\sahyog\app\inbound\user\mapper\TransporterMapper.class
|
||||
com\sahyog\app\inbound\user\controller\UserTypeController.class
|
||||
com\sahyog\app\inbound\user\dto\MaterialMasterDTO.class
|
||||
com\sahyog\app\inbound\user\serviceImpl\RoleServiceImpl.class
|
||||
com\sahyog\app\inbound\user\dto\TransporterUpdateDTO.class
|
||||
com\sahyog\app\inbound\user\controller\RoleController.class
|
||||
com\sahyog\app\inbound\user\service\UserService.class
|
||||
com\sahyog\app\inbound\user\service\RoleService.class
|
||||
com\sahyog\app\inbound\user\utils\MaterialProcessingHelper.class
|
||||
com\sahyog\app\inbound\user\exception\UserAlreadyExistsException.class
|
||||
com\sahyog\app\inbound\user\dto\UserRequestDTO.class
|
||||
com\sahyog\app\inbound\user\exception\TransporterUpdateException.class
|
||||
com\sahyog\app\inbound\user\exception\TransporterValidationException.class
|
||||
com\sahyog\app\inbound\user\filter\TransporterFilters.class
|
||||
com\sahyog\app\inbound\user\dto\UserTypeDTO.class
|
||||
com\sahyog\app\inbound\user\utils\UserProcessingHelper.class
|
||||
com\sahyog\app\inbound\user\dto\PlantDTO.class
|
||||
com\sahyog\app\inbound\user\service\PlantMasterService.class
|
||||
com\sahyog\app\inbound\user\utils\TransporterProcessingHelper.class
|
||||
com\sahyog\app\inbound\user\repository\UserRoleRepository.class
|
||||
com\sahyog\app\inbound\user\enums\Status.class
|
||||
com\sahyog\app\inbound\user\mapper\PlantMapper.class
|
||||
com\sahyog\app\inbound\user\repository\UserRepository.class
|
||||
com\sahyog\app\inbound\user\utils\UserConstants.class
|
||||
com\sahyog\app\inbound\user\model\UserPlant.class
|
||||
com\sahyog\app\inbound\user\model\PlantMaster.class
|
||||
com\sahyog\app\inbound\user\repository\UserTypeRepository.class
|
||||
com\sahyog\app\inbound\user\dto\UserDTO.class
|
||||
com\sahyog\app\inbound\user\service\UserRoleService.class
|
||||
com\sahyog\app\inbound\user\enums\RoleType.class
|
||||
com\sahyog\app\inbound\user\serviceImpl\TransporterServiceImpl.class
|
||||
com\sahyog\app\inbound\user\controller\TransporterController.class
|
||||
com\sahyog\app\inbound\user\dto\AssignRolesRequestDTO.class
|
||||
com\sahyog\app\inbound\user\exception\GlobalExceptionHandler.class
|
||||
com\sahyog\app\inbound\user\model\UserRole.class
|
||||
com\sahyog\app\inbound\user\dto\UserUpdateDTO.class
|
||||
com\sahyog\app\inbound\user\exception\CustomException.class
|
||||
com\sahyog\app\inbound\user\model\Response.class
|
||||
com\sahyog\app\inbound\user\service\MaterialMasterService.class
|
||||
com\sahyog\app\inbound\user\controller\UserPlantController.class
|
||||
com\sahyog\app\inbound\user\dto\AssignPlantsRequestDTO.class
|
||||
com\sahyog\app\inbound\user\dto\UserRoleDTO.class
|
||||
com\sahyog\app\inbound\user\dto\RoleDTO.class
|
||||
com\sahyog\app\inbound\user\dto\UserTypeCreateDTO.class
|
||||
com\sahyog\app\inbound\user\serviceImpl\PlantMasterServiceImpl.class
|
||||
com\sahyog\app\inbound\user\model\User.class
|
||||
com\sahyog\app\inbound\user\controller\MaterialMasterController.class
|
||||
com\sahyog\app\inbound\user\controller\UserRoleController.class
|
||||
com\sahyog\app\inbound\user\repository\UserPlantRepository.class
|
||||
com\sahyog\app\inbound\user\InboundUserServiceApplication.class
|
||||
com\sahyog\app\inbound\user\exception\TransporterProcessingException.class
|
||||
com\sahyog\app\inbound\user\model\UserType.class
|
||||
com\sahyog\app\inbound\user\mapper\MaterialMapper.class
|
||||
com\sahyog\app\inbound\user\config\CorsConfig.class
|
||||
com\sahyog\app\inbound\user\exception\TransporterCreationException.class
|
||||
com\sahyog\app\inbound\user\dto\PlantMasterDTO.class
|
||||
com\sahyog\app\inbound\user\service\UserTypeService.class
|
||||
com\sahyog\app\inbound\user\dto\TransporterMasterDto.class
|
||||
com\sahyog\app\inbound\user\model\MaterialMaster.class
|
||||
com\sahyog\app\inbound\user\mapper\UserMapper.class
|
||||
com\sahyog\app\inbound\user\dto\UserPlantDTO.class
|
||||
com\sahyog\app\inbound\user\model\Role.class
|
||||
com\sahyog\app\inbound\user\serviceImpl\UserTypeServiceImpl.class
|
||||
com\sahyog\app\inbound\user\repository\PlantRepository.class
|
||||
com\sahyog\app\inbound\user\utils\PlantProcessingHelper.class
|
||||
com\sahyog\app\inbound\user\serviceImpl\UserServiceImpl.class
|
||||
com\sahyog\app\inbound\user\enums\UserTypeEnum.class
|
||||
com\sahyog\app\inbound\user\model\Transporter.class
|
Loading…
Reference in New Issue