Tutorial working

This commit is contained in:
2025-03-15 18:23:24 -04:00
parent a86f0302de
commit 2778740cef
4 changed files with 76 additions and 2 deletions

View File

@@ -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;
}
}

View File

@@ -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);
}
}
}

View File

@@ -10,4 +10,7 @@ import com.mattrixwv.raidbuilder.entity.AccountTutorialStatus;
public interface AccountTutorialStatusRepository extends AccountTutorialStatusCustomRepository, JpaRepository<AccountTutorialStatus, UUID>{
public void deleteAllByAccountId(UUID accountId);
public AccountTutorialStatus findByAccountId(UUID accountId);
}

View File

@@ -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);
}
}