Added endpoint to get all users
This commit is contained in:
@@ -230,6 +230,7 @@ public class GepafinConstant {
|
|||||||
public static final String ATTEMPT_DATE = "attemptDate";
|
public static final String ATTEMPT_DATE = "attemptDate";
|
||||||
public static final String LOGIN_ATTEMPTED_CREATED_SUCCESSFULLY="login_attempt_successfully_created";
|
public static final String LOGIN_ATTEMPTED_CREATED_SUCCESSFULLY="login_attempt_successfully_created";
|
||||||
public static final String GET_LOGIN_ATTEMPT_MSG="get_login_attempt_se_msg";
|
public static final String GET_LOGIN_ATTEMPT_MSG="get_login_attempt_se_msg";
|
||||||
|
public static final String GET_USERS_SUCCESS_MSG = "get.users.success.msg";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ import org.springframework.stereotype.Component;
|
|||||||
import org.springframework.stereotype.Repository;
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import static net.gepafin.tendermanagement.util.Utils.setIfUpdated;
|
import static net.gepafin.tendermanagement.util.Utils.setIfUpdated;
|
||||||
|
|
||||||
@@ -354,5 +355,22 @@ public class UserDao {
|
|||||||
return authService.validateNewUserToken(token);
|
return authService.validateNewUserToken(token);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<UserResponseBean> getAllUsers(Long roleId) {
|
||||||
|
List<UserEntity> users;
|
||||||
|
if (roleId != null) {
|
||||||
|
log.info("Fetching users by role ID: {}", roleId);
|
||||||
|
users = userRepository.findByRoleEntityId(roleId);
|
||||||
|
} else {
|
||||||
|
log.info("Fetching all users");
|
||||||
|
users = userRepository.findAll();
|
||||||
|
}
|
||||||
|
List<UserResponseBean> userResponseBeans = users.stream()
|
||||||
|
.map(this::convertUserEntityToUserResponse)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
|
log.info("Total users found with role ID {}: {}", roleId, userResponseBeans.size());
|
||||||
|
return userResponseBeans;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,11 @@
|
|||||||
package net.gepafin.tendermanagement.repositories;
|
package net.gepafin.tendermanagement.repositories;
|
||||||
|
|
||||||
import net.gepafin.tendermanagement.entities.UserEntity;
|
import net.gepafin.tendermanagement.entities.UserEntity;
|
||||||
|
import net.gepafin.tendermanagement.model.response.UserResponseBean;
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
import org.springframework.stereotype.Repository;
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
@Repository
|
@Repository
|
||||||
@@ -21,5 +23,5 @@ public interface UserRepository extends JpaRepository<UserEntity, Long> {
|
|||||||
UserEntity findByBeneficiaryId(Long beneficiaryId);
|
UserEntity findByBeneficiaryId(Long beneficiaryId);
|
||||||
|
|
||||||
Long countByStatusAndRoleEntity_RoleType(String status, String roleName);
|
Long countByStatusAndRoleEntity_RoleType(String status, String roleName);
|
||||||
|
List<UserEntity> findByRoleEntityId(Long roleId);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,6 +12,8 @@ import net.gepafin.tendermanagement.model.response.UserSamlResponse;
|
|||||||
import net.gepafin.tendermanagement.model.response.UserResponseBean;
|
import net.gepafin.tendermanagement.model.response.UserResponseBean;
|
||||||
import net.gepafin.tendermanagement.model.util.JWTToken;
|
import net.gepafin.tendermanagement.model.util.JWTToken;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public interface UserService {
|
public interface UserService {
|
||||||
JWTToken createUser(HttpServletRequest request, String tempToken, UserReq userReq);
|
JWTToken createUser(HttpServletRequest request, String tempToken, UserReq userReq);
|
||||||
|
|
||||||
@@ -43,5 +45,6 @@ public interface UserService {
|
|||||||
UserEntity getUserByBeneficiaryId(Long beneficiaryId);
|
UserEntity getUserByBeneficiaryId(Long beneficiaryId);
|
||||||
|
|
||||||
public UserEntity getUserEntityById(Long userId);
|
public UserEntity getUserEntityById(Long userId);
|
||||||
|
List<UserResponseBean> getAllUsers(Long roleId);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -72,7 +72,7 @@ public class AuthenticationService {
|
|||||||
|
|
||||||
public JWTToken login(LoginReq loginReq,HttpServletRequest request) {
|
public JWTToken login(LoginReq loginReq,HttpServletRequest request) {
|
||||||
UserEntity user=null;
|
UserEntity user=null;
|
||||||
try {
|
|
||||||
LoginAttemptEntity loginAttemptEntity = prepareLoginAttemptEntity(loginReq, request);
|
LoginAttemptEntity loginAttemptEntity = prepareLoginAttemptEntity(loginReq, request);
|
||||||
log.info("Attempting login for email: {}", loginReq.getEmail());
|
log.info("Attempting login for email: {}", loginReq.getEmail());
|
||||||
UsernamePasswordAuthenticationToken authenticationToken = new UsernamePasswordAuthenticationToken(
|
UsernamePasswordAuthenticationToken authenticationToken = new UsernamePasswordAuthenticationToken(
|
||||||
@@ -89,10 +89,6 @@ public class AuthenticationService {
|
|||||||
Translator.toLocale(GepafinConstant.USER_NOT_FOUND_MSG));
|
Translator.toLocale(GepafinConstant.USER_NOT_FOUND_MSG));
|
||||||
}
|
}
|
||||||
createSuccessLoginAttempt(loginAttemptEntity);
|
createSuccessLoginAttempt(loginAttemptEntity);
|
||||||
} catch (Exception e) {
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
return getJWTTokenBean(user, loginReq.getRememberMe());
|
return getJWTTokenBean(user, loginReq.getRememberMe());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
@@ -124,4 +125,10 @@ public class UserServiceImpl implements UserService {
|
|||||||
// Calling DAO Function
|
// Calling DAO Function
|
||||||
return userDao.validateUser(userId);
|
return userDao.validateUser(userId);
|
||||||
}
|
}
|
||||||
|
@Override
|
||||||
|
@Transactional(readOnly = true)
|
||||||
|
public List<UserResponseBean> getAllUsers(Long roleId) {
|
||||||
|
// Calling DAO Function
|
||||||
|
return userDao.getAllUsers(roleId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -22,6 +22,8 @@ import org.springframework.security.access.prepost.PreAuthorize;
|
|||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
|
||||||
@Validated
|
@Validated
|
||||||
public interface UserApi {
|
public interface UserApi {
|
||||||
@@ -219,6 +221,18 @@ public interface UserApi {
|
|||||||
ResponseEntity<Response<UserSamlResponse>> validateNewUserToken(HttpServletRequest request,
|
ResponseEntity<Response<UserSamlResponse>> validateNewUserToken(HttpServletRequest request,
|
||||||
@Parameter(description = "The spid token", required = true) @PathVariable("token") String token);
|
@Parameter(description = "The spid token", required = true) @PathVariable("token") String token);
|
||||||
|
|
||||||
|
@Operation(summary = "Api to get all users",
|
||||||
|
responses = {
|
||||||
|
@ApiResponse(responseCode = "200", description = "OK"),
|
||||||
|
@ApiResponse(responseCode = "404", description = "Not Found", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
|
||||||
|
@ExampleObject(value = ErrorConstants.NOTFOUND_ERROR_EXAMPLE)})),
|
||||||
|
@ApiResponse(responseCode = "401", description = "Unauthorized", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
|
||||||
|
@ExampleObject(value = ErrorConstants.UNAUTHORIZED_ERROR_EXAMPLE)})),
|
||||||
|
@ApiResponse(responseCode = "400", description = "Bad Request", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
|
||||||
|
@ExampleObject(value = ErrorConstants.BADREQUEST_ERROR_EXAMPLE)}))})
|
||||||
|
@RequestMapping(value = "", produces = {"application/json"}, method = RequestMethod.GET)
|
||||||
|
ResponseEntity<Response<List<UserResponseBean>>> getAllUsers(
|
||||||
|
@Parameter( required = false)@RequestParam(value ="roleId", required = false) Long roleId);
|
||||||
|
|
||||||
|
|
||||||
@RequestMapping("favicon.ico")
|
@RequestMapping("favicon.ico")
|
||||||
|
|||||||
@@ -22,6 +22,8 @@ import org.springframework.http.ResponseEntity;
|
|||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("${openapi.gepafin.base-path:/v1/user}")
|
@RequestMapping("${openapi.gepafin.base-path:/v1/user}")
|
||||||
@@ -139,7 +141,14 @@ public class UserApiController implements UserApi {
|
|||||||
UserSamlResponse data = userService.validateNewUserToken(request,token);
|
UserSamlResponse data = userService.validateNewUserToken(request,token);
|
||||||
return ResponseEntity.ok(new Response<>(data, Status.SUCCESS, Translator.toLocale(GepafinConstant.TOKEN_VALIDATE_SUCCESS_MSE)));
|
return ResponseEntity.ok(new Response<>(data, Status.SUCCESS, Translator.toLocale(GepafinConstant.TOKEN_VALIDATE_SUCCESS_MSE)));
|
||||||
}
|
}
|
||||||
|
@Override
|
||||||
|
public ResponseEntity<Response<List<UserResponseBean>>> getAllUsers(
|
||||||
|
Long roleId) {
|
||||||
|
log.info("Get all Users by Role ID - Role ID: {}", roleId);
|
||||||
|
List<UserResponseBean> users = userService.getAllUsers(roleId);
|
||||||
|
return ResponseEntity.status(HttpStatus.OK)
|
||||||
|
.body(new Response<>(users, Status.SUCCESS, Translator.toLocale(GepafinConstant.GET_USERS_SUCCESS_MSG)));
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void returnNoFavicon() {
|
public void returnNoFavicon() {
|
||||||
|
|||||||
@@ -251,4 +251,4 @@ dashboard.widget.fetched.successfully=Dasboard widget fetched sucessfully.
|
|||||||
login_attempt_successfully_created = Login attempt successfully created.
|
login_attempt_successfully_created = Login attempt successfully created.
|
||||||
get_login_attempt_se_msg=Login attempts fetched successfully.
|
get_login_attempt_se_msg=Login attempts fetched successfully.
|
||||||
|
|
||||||
|
get.users.success.msg = Successfully fetched users.
|
||||||
|
|||||||
@@ -247,3 +247,4 @@ dashboard.widget.fetched.successfully=Widget dashboard recuperato correttamente.
|
|||||||
login_attempt_successfully_created= Tentativo di login creato con successo.
|
login_attempt_successfully_created= Tentativo di login creato con successo.
|
||||||
get_login_attempt_se_msg=Lista dei tentativi di accesso recuperata correttamente.
|
get_login_attempt_se_msg=Lista dei tentativi di accesso recuperata correttamente.
|
||||||
|
|
||||||
|
get.users.success.msg = Utenti recuperati con successo
|
||||||
Reference in New Issue
Block a user