add internal feign key

This commit is contained in:
2026-06-05 22:29:55 +07:00
parent 9b028237a4
commit c537de7fe6
@@ -33,6 +33,8 @@ public class AdminUserHandler implements RequestHandler {
private final AdminUserService adminUserService;
private final JwtUtil jwtUtil;
private final AdminSectionPermissionService permissionService;
private final HttpServletRequest httpServletRequest;
@@ -45,6 +47,7 @@ public class AdminUserHandler implements RequestHandler {
String action = adminRequest.getAction();
return switch (action) {
case "login" -> handleLogin(request, adminRequest);
case "create" -> handleCreate(request, adminRequest);
case "get_all" -> handleGetAll(request, adminRequest);
case "get_by_id" -> handleGetById(request, adminRequest);
@@ -58,6 +61,54 @@ public class AdminUserHandler implements RequestHandler {
};
}
private BaseResponse handleLogin(BaseRequest request, AdminUserRequest adminRequest) {
String email = adminRequest.getEmail();
String password = adminRequest.getPassword();
boolean authenticated = adminUserService.authenticate(email, password);
if (!authenticated) {
return BaseResponse.builder()
.msgId(request.getMsgId())
.messageCode(MessageCode.INVALID_CREDENTIALS.getCode())
.messageDesc(MessageCode.INVALID_CREDENTIALS.getDescription())
.build();
}
try {
AdminUser admin = adminUserService.findByEmail(email);
if (!admin.getIsActive()) {
return BaseResponse.builder()
.msgId(request.getMsgId())
.messageCode(MessageCode.ADMIN_INACTIVE.getCode())
.messageDesc(MessageCode.ADMIN_INACTIVE.getDescription())
.build();
}
String token = jwtUtil.generateToken(admin.getEmail(), admin.getId());
LoginResponse loginResponse = LoginResponse.builder()
.success(true)
.token(token)
.admin(convertToResponse(admin))
.build();
return BaseResponse.builder()
.msgId(request.getMsgId())
.messageCode(MessageCode.SUCCESS.getCode())
.messageDesc(MessageCode.SUCCESS.getDescription())
.messageBody(loginResponse)
.build();
} catch (AdminUserNotFoundException e) {
return BaseResponse.builder()
.msgId(request.getMsgId())
.messageCode(MessageCode.ADMIN_NOT_FOUND.getCode())
.messageDesc(MessageCode.ADMIN_NOT_FOUND.getDescription())
.build();
}
}
private BaseResponse handleCreate(BaseRequest request, AdminUserRequest adminRequest) {
try {
Long currentUserId = (Long) httpServletRequest.getAttribute("userId");