diff --git a/src/main/java/com/mattrixwv/raidbuilder/controller/AccountTutorialController.java b/src/main/java/com/mattrixwv/raidbuilder/controller/AccountTutorialController.java new file mode 100644 index 0000000..7d53a88 --- /dev/null +++ b/src/main/java/com/mattrixwv/raidbuilder/controller/AccountTutorialController.java @@ -0,0 +1,62 @@ +package com.mattrixwv.raidbuilder.controller; + + +import org.springframework.security.core.Authentication; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.node.ObjectNode; +import com.mattrixwv.raidbuilder.annotation.AccountAuthorization; +import com.mattrixwv.raidbuilder.entity.Account; +import com.mattrixwv.raidbuilder.entity.AccountTutorialStatus; +import com.mattrixwv.raidbuilder.service.AccountService; +import com.mattrixwv.raidbuilder.service.AccountTutorialStatusService; +import com.mattrixwv.raidbuilder.util.DatabaseTypeUtil.AccountPermissionType; + +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; + + + +@Slf4j +@RestController +@RequestMapping("/account/tutorial") +@RequiredArgsConstructor +public class AccountTutorialController{ + private final ObjectMapper mapper; + private final AccountService accountService; + private final AccountTutorialStatusService tutorialService; + + + @GetMapping + @AccountAuthorization(permissions = {AccountPermissionType.ADMIN, AccountPermissionType.USER}) + public AccountTutorialStatus getTutorialStatus(Authentication authentication){ + log.info("Getting tutorial status for account {}", authentication.getName()); + + + Account account = accountService.getByUsername(authentication.getName()); + return tutorialService.getByAccountId(account.getAccountId()); + } + + + @PutMapping + @AccountAuthorization(permissions = {AccountPermissionType.ADMIN, AccountPermissionType.USER}) + public ObjectNode updateTutorialStatus(@RequestBody AccountTutorialStatus tutorialStatus, Authentication authentication){ + log.info("Updating tutorial status for account {} to {}", authentication.getName(), tutorialStatus); + + + Account account = accountService.getByUsername(authentication.getName()); + tutorialStatus.setAccountId(account.getAccountId()); + tutorialService.updateAccountTutorialStatus(tutorialStatus); + + ObjectNode returnNode = mapper.createObjectNode(); + returnNode.put("status", "success"); + + + return returnNode; + } +} diff --git a/src/main/java/com/mattrixwv/raidbuilder/controller/AuthenticationController.java b/src/main/java/com/mattrixwv/raidbuilder/controller/AuthenticationController.java index 5d4f2ad..3637d2c 100644 --- a/src/main/java/com/mattrixwv/raidbuilder/controller/AuthenticationController.java +++ b/src/main/java/com/mattrixwv/raidbuilder/controller/AuthenticationController.java @@ -70,13 +70,12 @@ public class AuthenticationController{ log.info("Refreshing token"); - Thread.sleep(2000); UUID refreshToken = null; if(request.getCookies() != null){ for(Cookie cookie : request.getCookies()){ if(cookie.getName().equals("refreshToken")){ - log.debug("refreshToken = {}", refreshToken); refreshToken = UUID.fromString(cookie.getValue()); + log.debug("refreshToken = {}", refreshToken); } } } diff --git a/src/main/java/com/mattrixwv/raidbuilder/repository/account_tutorial_status/AccountTutorialStatusRepository.java b/src/main/java/com/mattrixwv/raidbuilder/repository/account_tutorial_status/AccountTutorialStatusRepository.java index 45bc4a4..ff9f4fb 100644 --- a/src/main/java/com/mattrixwv/raidbuilder/repository/account_tutorial_status/AccountTutorialStatusRepository.java +++ b/src/main/java/com/mattrixwv/raidbuilder/repository/account_tutorial_status/AccountTutorialStatusRepository.java @@ -10,4 +10,7 @@ import com.mattrixwv.raidbuilder.entity.AccountTutorialStatus; public interface AccountTutorialStatusRepository extends AccountTutorialStatusCustomRepository, JpaRepository{ public void deleteAllByAccountId(UUID accountId); + + + public AccountTutorialStatus findByAccountId(UUID accountId); } diff --git a/src/main/java/com/mattrixwv/raidbuilder/service/AccountTutorialStatusService.java b/src/main/java/com/mattrixwv/raidbuilder/service/AccountTutorialStatusService.java index a1b1373..46ad2f5 100644 --- a/src/main/java/com/mattrixwv/raidbuilder/service/AccountTutorialStatusService.java +++ b/src/main/java/com/mattrixwv/raidbuilder/service/AccountTutorialStatusService.java @@ -24,7 +24,17 @@ public class AccountTutorialStatusService{ return accountTutorialStatusRepository.save(accountTutorialStatus); } + public AccountTutorialStatus updateAccountTutorialStatus(AccountTutorialStatus accountTutorialStatus){ + return accountTutorialStatusRepository.save(accountTutorialStatus); + } + public void deleteByAccountId(UUID accountId){ accountTutorialStatusRepository.deleteAllByAccountId(accountId); } + + + //Read + public AccountTutorialStatus getByAccountId(UUID accountId){ + return accountTutorialStatusRepository.findByAccountId(accountId); + } }