Merge branch 'feature/GEPAFINBE-31' of https://github.com/Kitzanos/GEPAFIN-BE into feature/GEPAFINBE-31

This commit is contained in:
rajesh
2024-11-24 21:37:41 +05:30
3 changed files with 23 additions and 10 deletions

View File

@@ -38,18 +38,12 @@ public class LoginAttemptDao {
public LoginAttemptEntity createLoginAttempt(LoginAttemptEntity loginAttemptEntity) {
VersionActionTypeEnum actionType;
LoginAttemptEntity oldLoginAttemptEntity = Utils.getClonedEntityForData(loginAttemptEntity);
loginAttemptEntity.setAttemptDate(DateTimeUtil.DateServerToUTC(LocalDateTime.now()));
if(loginAttemptEntity.getId() != null ) {
actionType = VersionActionTypeEnum.UPDATE;
}else{
actionType = VersionActionTypeEnum.INSERT;
oldLoginAttemptEntity = null;
}
loginAttemptEntity = loginAttemptRepository.save(loginAttemptEntity);
loginAttemptEntity = loginAttemptRepository.save(loginAttemptEntity);
/** This code is responsible for adding a version history log for "Create Login Attempt" operation. **/
loggingUtil.addVersionHistoryWithoutToken(VersionHistoryRequest.builder().actionType(actionType).request(request).oldData(oldLoginAttemptEntity).newData(loginAttemptEntity).build());
loggingUtil.addVersionHistoryWithoutToken(
VersionHistoryRequest.builder().actionType(VersionActionTypeEnum.INSERT).request(request).oldData(null).newData(loginAttemptEntity).build());
return loginAttemptEntity;
}

View File

@@ -104,7 +104,11 @@ public enum UserActionContextEnum {
DELETE_DOCUMENT("DELETE_DOCUMENT"),
UPDATE_DOCUMENT("UPDATE_DOCUEMENT"),
UPDATE_IMAGES("UPDATE_IMAGES"),
GET_DOCUMENT("GET_DOCUMENT");
GET_DOCUMENT("GET_DOCUMENT"),
/** Login attempt action context **/
GET_LOGIN_ATTEMPT_LIST("GET_LOGIN_ATTEMPT_LIST"),
ADD_LOGIN_ATTEMPT("ADD_LOGIN_ATTEMPT");
private final String value;

View File

@@ -5,11 +5,15 @@ import net.gepafin.tendermanagement.config.Translator;
import net.gepafin.tendermanagement.constants.GepafinConstant;
import net.gepafin.tendermanagement.entities.LoginAttemptEntity;
import net.gepafin.tendermanagement.entities.UserEntity;
import net.gepafin.tendermanagement.enums.UserActionContextEnum;
import net.gepafin.tendermanagement.enums.UserActionLogsEnum;
import net.gepafin.tendermanagement.model.request.LoginAttemptReq;
import net.gepafin.tendermanagement.model.request.UserActionRequest;
import net.gepafin.tendermanagement.model.response.LoginAttemptPageableResponseBean;
import net.gepafin.tendermanagement.model.util.Response;
import net.gepafin.tendermanagement.service.LoginAttemptService;
import net.gepafin.tendermanagement.service.UserService;
import net.gepafin.tendermanagement.util.LoggingUtil;
import net.gepafin.tendermanagement.util.Validator;
import net.gepafin.tendermanagement.web.rest.api.LoginAttemptApi;
import net.gepafin.tendermanagement.web.rest.api.errors.Status;
@@ -38,8 +42,15 @@ public class LoginAttemptApiController implements LoginAttemptApi {
@Autowired
private UserService userService;
@Autowired
private LoggingUtil loggingUtil;
@Override
public ResponseEntity<LoginAttemptPageableResponseBean<List<LoginAttemptEntity>>> getLoginAttemptsList(HttpServletRequest request, Integer pageNo, Integer pageLimit) {
/** This code is responsible for creating user action logs for the "Get login attempt list" operation. **/
loggingUtil.logUserAction(UserActionRequest.builder().request(request).actionType(UserActionLogsEnum.VIEW).actionContext(UserActionContextEnum.GET_LOGIN_ATTEMPT_LIST).build());
LoginAttemptPageableResponseBean<List<LoginAttemptEntity>> response = loginAttemptService.getLoginAttemptsList(request, pageNo, pageLimit);
return ResponseEntity.status(HttpStatus.OK).body(response);
}
@@ -50,6 +61,10 @@ public class LoginAttemptApiController implements LoginAttemptApi {
String userIdString = (String) userInfo.get("userId");
UserEntity currentUser = userService.getUserEntityById(Long.parseLong(userIdString));
loginAttemptReq.setUserName(currentUser.getEmail());
/** This code is responsible for creating user action logs for the "add login attempt" operation. **/
loggingUtil.logUserAction(UserActionRequest.builder().request(request).actionType(UserActionLogsEnum.INSERT).actionContext(UserActionContextEnum.ADD_LOGIN_ATTEMPT).build());
loginAttemptService.createLoginAttempt(loginAttemptReq, request);
return ResponseEntity.status(HttpStatus.CREATED).body(new Response<Void>(null, Status.SUCCESS, Translator.toLocale(GepafinConstant.LOGIN_ATTEMPTED_CREATED_SUCCESSFULLY)));
}