From e14d4612d313b7424b2163ba247843655c4dfca1 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Fri, 19 Jul 2024 13:25:06 +0300 Subject: Update premium status on login --- src/main/java/com/juick/service/VKService.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'src/main/java/com/juick/service/VKService.java') diff --git a/src/main/java/com/juick/service/VKService.java b/src/main/java/com/juick/service/VKService.java index 19fa5b58..b9b2483f 100644 --- a/src/main/java/com/juick/service/VKService.java +++ b/src/main/java/com/juick/service/VKService.java @@ -56,7 +56,7 @@ public class VKService { .build(VkontakteApi.instance())); } - public void updatePremiumStatus(Integer userId) { + public boolean updatePremiumStatus(Integer userId) { var vkUser = userService.getVkTokens(userId); if (vkUser != null) { OAuth2AccessToken token = new OAuth2AccessToken(vkUser.getRight()); @@ -65,12 +65,13 @@ public class VKService { getVkAuthService().signRequest(token, donRequest); try (Response vkResponse = getVkAuthService().execute(donRequest)) { if (vkResponse.isSuccessful()) { - logger.info(vkResponse.getBody()); + logger.debug(vkResponse.getBody()); var response = jsonMapper.readTree(vkResponse.getBody()); if (response.has("response")) { var isDon = response.get("response").intValue() > 0; - logger.info("{} is Don: {}", vkUser.getLeft(), isDon); + logger.debug("{} is Don: {}", vkUser.getLeft(), isDon); userService.setPremium(userId, isDon); + return isDon; } else { // token is expired or does not have "groups" permissions userService.updateVkToken(userId, ""); @@ -80,8 +81,9 @@ public class VKService { logger.error("Don request error", e); } } else { - logger.warn("User is not connected to VK: {}", userId); + logger.debug("User is not connected to VK: {}", userId); } + return false; } public OAuth20Service getVkAuthService() { -- cgit v1.2.3