Add validation to utils
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package com.mattrixwv.raidbuilder.controller;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
@@ -144,18 +145,22 @@ public class AccountController{
|
||||
|
||||
|
||||
ObjectNode returnNode = mapper.createObjectNode();
|
||||
Account existingAccount = accountService.getByUsername(account.getUsername());
|
||||
if(existingAccount != null){
|
||||
//TODO: Move this to util
|
||||
List<String> errors = verifyNewAccount(account);
|
||||
if(errors.isEmpty()){
|
||||
account = accountService.createAccount(account);
|
||||
|
||||
returnNode.put("status", "success");
|
||||
returnNode.put("accountId", account.getAccountId().toString());
|
||||
|
||||
log.info("Created account {}", account.getAccountId());
|
||||
}
|
||||
else{
|
||||
ArrayNode errorsNode = mapper.createArrayNode();
|
||||
errorsNode.add("Username already exists");
|
||||
returnNode.set("errors", errorsNode);
|
||||
returnNode.put("status", "error");
|
||||
}
|
||||
else{
|
||||
account = accountService.createAccount(account);
|
||||
returnNode.put("status", "success");
|
||||
returnNode.put("accountId", account.getAccountId().toString());
|
||||
}
|
||||
|
||||
|
||||
return returnNode;
|
||||
@@ -294,23 +299,25 @@ public class AccountController{
|
||||
log.info("Updating account {}", accountId);
|
||||
|
||||
|
||||
//TODO: Existing account verification
|
||||
Account oldAccount = accountService.getByAccountId(accountId);
|
||||
//TODO: Move this to util
|
||||
List<String> errors = verifyUpdatedAccount(account);
|
||||
|
||||
ObjectNode returnNode = mapper.createObjectNode();
|
||||
if(oldAccount == null){
|
||||
if(errors.isEmpty()){
|
||||
Account existingAccount = accountService.getByAccountId(accountId);
|
||||
existingAccount.setUsername(account.getUsername());
|
||||
existingAccount.setEmail(account.getEmail());
|
||||
existingAccount.setAccountStatus(account.getAccountStatus());
|
||||
accountService.updateAccount(existingAccount);
|
||||
|
||||
returnNode.put("status", "success");
|
||||
}
|
||||
else{
|
||||
ArrayNode errorsNode = mapper.createArrayNode();
|
||||
errorsNode.add("Account not found");
|
||||
returnNode.set("errors", errorsNode);
|
||||
returnNode.put("status", "error");
|
||||
}
|
||||
else{
|
||||
oldAccount.setUsername(account.getUsername());
|
||||
oldAccount.setEmail(account.getEmail());
|
||||
oldAccount.setAccountStatus(account.getAccountStatus());
|
||||
accountService.updateAccount(oldAccount);
|
||||
|
||||
returnNode.put("status", "success");
|
||||
}
|
||||
|
||||
|
||||
return returnNode;
|
||||
@@ -339,4 +346,86 @@ public class AccountController{
|
||||
|
||||
return returnNode;
|
||||
}
|
||||
|
||||
|
||||
private List<String> verifyNewAccount(Account account){
|
||||
ArrayList<String> errors = new ArrayList<>();
|
||||
|
||||
//Check ID
|
||||
if(account.getAccountId() != null){
|
||||
errors.add("Invalid Account ID");
|
||||
}
|
||||
|
||||
//Check login exists in entity
|
||||
if((account.getUsername() == null) || (account.getUsername().isEmpty())){
|
||||
errors.add("Invalid Login ID");
|
||||
}
|
||||
else{
|
||||
//Check login doesn't exist in db
|
||||
Account existingAccount = accountService.getByUsername(account.getUsername());
|
||||
if(existingAccount != null){
|
||||
errors.add("Login ID already exists");
|
||||
}
|
||||
}
|
||||
|
||||
//Check password exists in entity
|
||||
if((account.getPassword() == null) || (account.getPassword().isEmpty())){
|
||||
errors.add("No password found");
|
||||
}
|
||||
|
||||
//Check email exists in entity
|
||||
if((account.getEmail() == null) || (account.getEmail().isEmpty())){
|
||||
errors.add("Invalid email");
|
||||
}
|
||||
else{
|
||||
//Check email doesn't exist in db
|
||||
Account existingAccount = accountService.getByEmail(account.getEmail());
|
||||
if(existingAccount != null){
|
||||
errors.add("Account with email already exists");
|
||||
}
|
||||
}
|
||||
|
||||
return errors;
|
||||
}
|
||||
|
||||
private List<String> verifyUpdatedAccount(Account account){
|
||||
ArrayList<String> errors = new ArrayList<>();
|
||||
|
||||
//Check ID
|
||||
if(account.getAccountId() == null){
|
||||
errors.add("Invalid Account ID");
|
||||
}
|
||||
|
||||
//Verify account exists
|
||||
Account existingAccount = accountService.getByAccountId(account.getAccountId());
|
||||
if(existingAccount == null){
|
||||
errors.add("Account not found");
|
||||
}
|
||||
|
||||
//Check login exists in entity
|
||||
if((account.getUsername() == null) || (account.getUsername().isEmpty())){
|
||||
errors.add("Invalid Login ID");
|
||||
}
|
||||
else{
|
||||
//Check login doesn't exist in db, other than the object itself
|
||||
Account existingAccountByLogin = accountService.getByUsername(account.getUsername());
|
||||
if((existingAccountByLogin != null) && (!existingAccountByLogin.getAccountId().equals(account.getAccountId()))){
|
||||
errors.add("Login ID already exists");
|
||||
}
|
||||
}
|
||||
|
||||
//Check email exists in entity
|
||||
if((account.getEmail() == null) || (account.getEmail().isEmpty())){
|
||||
errors.add("Invalid email");
|
||||
}
|
||||
else{
|
||||
//Check email doesn't exist in db, other than the object itself
|
||||
Account existingAccountByEmail = accountService.getByEmail(account.getEmail());
|
||||
if((existingAccountByEmail != null) && (!existingAccountByEmail.getAccountId().equals(account.getAccountId()))){
|
||||
errors.add("Account with email already exists");
|
||||
}
|
||||
}
|
||||
|
||||
return errors;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,6 +43,7 @@ public class AccountTutorialController{
|
||||
}
|
||||
|
||||
|
||||
//TODO: Break this up per tutorial?
|
||||
@PutMapping
|
||||
@AccountAuthorization(permissions = {AccountPermissionType.ADMIN, AccountPermissionType.USER})
|
||||
public ObjectNode updateTutorialStatus(@RequestBody AccountTutorialStatus tutorialStatus, Authentication authentication){
|
||||
|
||||
@@ -204,7 +204,6 @@ public class AuthenticationController{
|
||||
@PostMapping("/forgot/{forgotToken}")
|
||||
@AccountAuthorization(permissions = {})
|
||||
public ObjectNode setNewPasswordForgot(@PathVariable("forgotToken") UUID forgotToken, @RequestBody ObjectNode passwordNode){
|
||||
String newPassword = passwordNode.get("password").asText();
|
||||
log.info("Confirming user reset password (forget) with token {}", forgotToken);
|
||||
|
||||
|
||||
@@ -214,6 +213,11 @@ public class AuthenticationController{
|
||||
//Verify the account exists
|
||||
Account existingAccount = accountService.getByRefreshToken(forgotToken);
|
||||
if(existingAccount != null){
|
||||
String newPassword = passwordNode.get("password").asText();
|
||||
if(newPassword.trim().length() <= 0){
|
||||
throw new IllegalArgumentException("Invalid password");
|
||||
}
|
||||
|
||||
existingAccount = accountService.updatePassword(existingAccount.getAccountId(), newPassword);
|
||||
|
||||
existingAccount.setRefreshToken(null);
|
||||
@@ -244,6 +248,9 @@ public class AuthenticationController{
|
||||
|
||||
String currentPassword = requestNode.get("currentPassword").asText();
|
||||
String newPassword = requestNode.get("newPassword").asText();
|
||||
if(newPassword.trim().length() <= 0){
|
||||
throw new IllegalArgumentException("Invalid password");
|
||||
}
|
||||
|
||||
Account account = accountService.getByUsername(authentication.getName());
|
||||
if(!passwordEncoder.matches(currentPassword, account.getPassword())){
|
||||
@@ -342,45 +349,4 @@ public class AuthenticationController{
|
||||
|
||||
return errors;
|
||||
}
|
||||
|
||||
private List<String> verifyUpdatedAccount(Account account){
|
||||
ArrayList<String> errors = new ArrayList<>();
|
||||
|
||||
//Check ID
|
||||
if(account.getAccountId() == null){
|
||||
errors.add("Invalid Account ID");
|
||||
}
|
||||
|
||||
//Verify account exists
|
||||
Account existingAccount = accountService.getByAccountId(account.getAccountId());
|
||||
if(existingAccount == null){
|
||||
errors.add("Account not found");
|
||||
}
|
||||
|
||||
//Check login exists in entity
|
||||
if((account.getUsername() == null) || (account.getUsername().isEmpty())){
|
||||
errors.add("Invalid Login ID");
|
||||
}
|
||||
else{
|
||||
//Check login doesn't exist in db, other than the object itself
|
||||
Account existingAccountByLogin = accountService.getByUsername(account.getUsername());
|
||||
if((existingAccountByLogin != null) && (!existingAccountByLogin.getAccountId().equals(account.getAccountId()))){
|
||||
errors.add("Login ID already exists");
|
||||
}
|
||||
}
|
||||
|
||||
//Check email exists in entity
|
||||
if((account.getEmail() == null) || (account.getEmail().isEmpty())){
|
||||
errors.add("Invalid email");
|
||||
}
|
||||
else{
|
||||
//Check email doesn't exist in db, other than the object itself
|
||||
Account existingAccountByEmail = accountService.getByEmail(account.getEmail());
|
||||
if((existingAccountByEmail != null) && (!existingAccountByEmail.getAccountId().equals(account.getAccountId()))){
|
||||
errors.add("Account with email already exists");
|
||||
}
|
||||
}
|
||||
|
||||
return errors;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ 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.ArrayNode;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.mattrixwv.raidbuilder.annotation.AccountAuthorization;
|
||||
import com.mattrixwv.raidbuilder.annotation.GameAuthorization;
|
||||
@@ -27,6 +28,7 @@ import com.mattrixwv.raidbuilder.service.RaidInstanceService;
|
||||
import com.mattrixwv.raidbuilder.util.DatabaseTypeUtil.AccountPermissionType;
|
||||
import com.mattrixwv.raidbuilder.util.DatabaseTypeUtil.GamePermissionType;
|
||||
import com.mattrixwv.raidbuilder.util.DatabaseTypeUtil.RaidGroupPermissionType;
|
||||
import com.mattrixwv.raidbuilder.util.validation.CalendarEventValidationUtil;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@@ -41,6 +43,8 @@ public class CalendarController{
|
||||
private final GameCalendarEventService gceService;
|
||||
private final RaidGroupCalendarEventService rgceService;
|
||||
private final RaidInstanceService raidInstanceService;
|
||||
//Utilities
|
||||
private final CalendarEventValidationUtil cevUtil;
|
||||
|
||||
|
||||
//! Game
|
||||
@@ -61,10 +65,21 @@ public class CalendarController{
|
||||
|
||||
|
||||
gameCalendarEvent.setGameId(gameId);
|
||||
gceService.createGameCalendarEvent(gameCalendarEvent);
|
||||
|
||||
ObjectNode returnNode = mapper.createObjectNode();
|
||||
returnNode.put("status", "success");
|
||||
List<String> errors = cevUtil.validateExistingGameCalendarEvent(gameCalendarEvent);
|
||||
if(errors.isEmpty()){
|
||||
gameCalendarEvent = gceService.createGameCalendarEvent(gameCalendarEvent);
|
||||
|
||||
returnNode.put("status", "success");
|
||||
returnNode.put("gameCalendarEventId", gameCalendarEvent.getGameCalendarEventId().toString());
|
||||
}
|
||||
else{
|
||||
returnNode.put("status", "error");
|
||||
ArrayNode errorNode = mapper.createArrayNode();
|
||||
errors.forEach(errorNode::add);
|
||||
returnNode.set("errors", errorNode);
|
||||
}
|
||||
|
||||
|
||||
return returnNode;
|
||||
}
|
||||
@@ -77,10 +92,21 @@ public class CalendarController{
|
||||
|
||||
|
||||
gameCalendarEvent.setGameId(gameId);
|
||||
gceService.updateGameCalendarEvent(gameCalendarEvent);
|
||||
|
||||
ObjectNode returnNode = mapper.createObjectNode();
|
||||
returnNode.put("status", "success");
|
||||
List<String> errors = cevUtil.validateExistingGameCalendarEvent(gameCalendarEvent);
|
||||
if(errors.isEmpty()){
|
||||
gameCalendarEvent = gceService.updateGameCalendarEvent(gameCalendarEvent);
|
||||
|
||||
returnNode.put("status", "success");
|
||||
returnNode.put("gameCalendarEventId", gameCalendarEvent.getGameCalendarEventId().toString());
|
||||
}
|
||||
else{
|
||||
returnNode.put("status", "error");
|
||||
ArrayNode errorNode = mapper.createArrayNode();
|
||||
errors.forEach(errorNode::add);
|
||||
returnNode.set("errors", errorNode);
|
||||
}
|
||||
|
||||
|
||||
return returnNode;
|
||||
}
|
||||
@@ -92,10 +118,19 @@ public class CalendarController{
|
||||
log.info("Deleting calendar event for game {}", gameId);
|
||||
|
||||
|
||||
gceService.deleteGameCalendarEvent(calendarEventId);
|
||||
|
||||
ObjectNode returnNode = mapper.createObjectNode();
|
||||
returnNode.put("status", "success");
|
||||
GameCalendarEvent gce = gceService.getById(calendarEventId);
|
||||
if(gce != null){
|
||||
gceService.deleteGameCalendarEvent(calendarEventId);
|
||||
|
||||
returnNode.put("status", "success");
|
||||
}
|
||||
else{
|
||||
ArrayNode errorsNode = mapper.createArrayNode();
|
||||
errorsNode.add("Calendar event ID is invalid");
|
||||
returnNode.put("status", "error");
|
||||
returnNode.set("errors", errorsNode);
|
||||
}
|
||||
|
||||
return returnNode;
|
||||
}
|
||||
@@ -120,10 +155,22 @@ public class CalendarController{
|
||||
|
||||
|
||||
raidGroupCalendarEvent.setRaidGroupId(raidGroupId);
|
||||
rgceService.createRaidGroupCalendarEvent(raidGroupCalendarEvent);
|
||||
|
||||
ObjectNode returnNode = mapper.createObjectNode();
|
||||
returnNode.put("status", "success");
|
||||
List<String> errors = cevUtil.validateNewRaidGroupCalendarEvent(raidGroupCalendarEvent);
|
||||
if(errors.isEmpty()){
|
||||
rgceService.createRaidGroupCalendarEvent(raidGroupCalendarEvent);
|
||||
|
||||
returnNode.put("status", "success");
|
||||
returnNode.put("raidGroupCalendarEventId", raidGroupCalendarEvent.getRaidGroupCalendarEventId().toString());
|
||||
|
||||
log.info("Created Raid Group Calendar Event {}", raidGroupCalendarEvent.getRaidGroupCalendarEventId());
|
||||
}
|
||||
else{
|
||||
returnNode.put("status", "error");
|
||||
ArrayNode errorNode = mapper.createArrayNode();
|
||||
errors.forEach(errorNode::add);
|
||||
returnNode.set("errors", errorNode);
|
||||
}
|
||||
|
||||
return returnNode;
|
||||
}
|
||||
@@ -136,10 +183,21 @@ public class CalendarController{
|
||||
|
||||
|
||||
raidGroupCalendarEvent.setRaidGroupId(raidGroupId);
|
||||
rgceService.updateRaidGroupCalendarEvent(raidGroupCalendarEvent);
|
||||
|
||||
ObjectNode returnNode = mapper.createObjectNode();
|
||||
returnNode.put("status", "success");
|
||||
List<String> errors = cevUtil.validateExistingRaidGroupCalendarEvent(raidGroupCalendarEvent);
|
||||
if(errors.isEmpty()){
|
||||
rgceService.updateRaidGroupCalendarEvent(raidGroupCalendarEvent);
|
||||
|
||||
returnNode.put("status", "success");
|
||||
returnNode.put("raidGroupCalendarEventId", raidGroupCalendarEvent.getRaidGroupCalendarEventId().toString());
|
||||
}
|
||||
else{
|
||||
returnNode.put("status", "error");
|
||||
ArrayNode errorNode = mapper.createArrayNode();
|
||||
errors.forEach(errorNode::add);
|
||||
returnNode.set("errors", errorNode);
|
||||
}
|
||||
|
||||
return returnNode;
|
||||
}
|
||||
@@ -151,10 +209,20 @@ public class CalendarController{
|
||||
log.info("Deleting calendar event for raid group {}", raidGroupId);
|
||||
|
||||
|
||||
rgceService.deleteRaidGroupCalendarEvent(calendarEventId);
|
||||
|
||||
ObjectNode returnNode = mapper.createObjectNode();
|
||||
returnNode.put("status", "success");
|
||||
GameCalendarEvent gce = gceService.getById(calendarEventId);
|
||||
if(gce != null){
|
||||
gceService.deleteGameCalendarEvent(calendarEventId);
|
||||
|
||||
returnNode.put("status", "success");
|
||||
returnNode.put("raidGroupCalendarEventId", gce.getGameCalendarEventId().toString());
|
||||
}
|
||||
else{
|
||||
ArrayNode errorsNode = mapper.createArrayNode();
|
||||
errorsNode.add("Calendar event ID is invalid");
|
||||
returnNode.put("status", "error");
|
||||
returnNode.set("errors", errorsNode);
|
||||
}
|
||||
|
||||
return returnNode;
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ArrayNode;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.mattrixwv.raidbuilder.annotation.AccountAuthorization;
|
||||
import com.mattrixwv.raidbuilder.annotation.RaidGroupAuthorization;
|
||||
@@ -25,6 +26,7 @@ import com.mattrixwv.raidbuilder.entity.ClassGroupGameClassXref;
|
||||
import com.mattrixwv.raidbuilder.service.ClassGroupService;
|
||||
import com.mattrixwv.raidbuilder.util.DatabaseTypeUtil.AccountPermissionType;
|
||||
import com.mattrixwv.raidbuilder.util.DatabaseTypeUtil.RaidGroupPermissionType;
|
||||
import com.mattrixwv.raidbuilder.util.validation.ClassGroupValidationUtil;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@@ -35,8 +37,10 @@ import lombok.extern.slf4j.Slf4j;
|
||||
@RequestMapping("/raidGroup/{raidGroupId}/classGroup")
|
||||
@RequiredArgsConstructor
|
||||
public class ClassGroupController{
|
||||
private final ObjectMapper mapper = new ObjectMapper();
|
||||
private final ObjectMapper mapper;
|
||||
private final ClassGroupService classGroupService;
|
||||
//Utilities
|
||||
private final ClassGroupValidationUtil cgvUtil;
|
||||
|
||||
|
||||
@GetMapping
|
||||
@@ -116,11 +120,24 @@ public class ClassGroupController{
|
||||
xref.setGameClassId(gameClassId);
|
||||
xrefs.add(xref);
|
||||
}
|
||||
classGroup = classGroupService.createClassGroup(classGroup, xrefs);
|
||||
|
||||
List<String> errors = cgvUtil.validateNewClassGroup(classGroup);
|
||||
ObjectNode returnNode = mapper.createObjectNode();
|
||||
returnNode.put("classGroupId", classGroup.getClassGroupId().toString());
|
||||
returnNode.put("status", "success");
|
||||
if(errors.isEmpty()){
|
||||
classGroup = classGroupService.createClassGroup(classGroup, xrefs);
|
||||
|
||||
returnNode.put("status", "success");
|
||||
returnNode.put("classGroupId", classGroup.getClassGroupId().toString());
|
||||
|
||||
log.info("Created Class Group {}", classGroup.getClassGroupId());
|
||||
}
|
||||
else{
|
||||
returnNode.put("status", "error");
|
||||
ArrayNode errorNode = mapper.createArrayNode();
|
||||
errors.forEach(errorNode::add);
|
||||
returnNode.set("errors", errorNode);
|
||||
}
|
||||
|
||||
|
||||
return returnNode;
|
||||
}
|
||||
@@ -142,12 +159,22 @@ public class ClassGroupController{
|
||||
xref.setGameClassId(gameClassId);
|
||||
xrefs.add(xref);
|
||||
}
|
||||
classGroupService.updateClassGroup(classGroup, xrefs);
|
||||
|
||||
|
||||
List<String> errors = cgvUtil.validateExistingClassGroup(classGroup);
|
||||
ObjectNode returnNode = mapper.createObjectNode();
|
||||
returnNode.put("classGroupId", classGroup.getClassGroupId().toString());
|
||||
returnNode.put("status", "success");
|
||||
if(errors.isEmpty()){
|
||||
classGroupService.updateClassGroup(classGroup, xrefs);
|
||||
|
||||
returnNode.put("classGroupId", classGroup.getClassGroupId().toString());
|
||||
returnNode.put("status", "success");
|
||||
}
|
||||
else{
|
||||
returnNode.put("status", "error");
|
||||
ArrayNode errorNode = mapper.createArrayNode();
|
||||
errors.forEach(errorNode::add);
|
||||
returnNode.set("errors", errorNode);
|
||||
}
|
||||
|
||||
|
||||
return returnNode;
|
||||
}
|
||||
@@ -159,10 +186,20 @@ public class ClassGroupController{
|
||||
log.info("Deleting class group {} for raid group {}", classGroupId, raidGroupId);
|
||||
|
||||
|
||||
classGroupService.deleteClassGroup(classGroupId, raidGroupId);
|
||||
ClassGroup classGroup = classGroupService.getClassGroup(classGroupId, raidGroupId);
|
||||
|
||||
ObjectNode returnNode = mapper.createObjectNode();
|
||||
returnNode.put("status", "success");
|
||||
if(classGroup != null){
|
||||
classGroupService.deleteClassGroup(classGroupId, raidGroupId);
|
||||
|
||||
returnNode.put("status", "success");
|
||||
}
|
||||
else{
|
||||
returnNode.put("status", "error");
|
||||
ArrayNode errorNode = mapper.createArrayNode();
|
||||
errorNode.add("Class group ID is invalid");
|
||||
returnNode.set("errors", errorNode);
|
||||
}
|
||||
|
||||
return returnNode;
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ArrayNode;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.mattrixwv.raidbuilder.annotation.AccountAuthorization;
|
||||
import com.mattrixwv.raidbuilder.annotation.GameAuthorization;
|
||||
@@ -22,6 +23,7 @@ import com.mattrixwv.raidbuilder.entity.GameClass;
|
||||
import com.mattrixwv.raidbuilder.service.GameClassService;
|
||||
import com.mattrixwv.raidbuilder.util.DatabaseTypeUtil.AccountPermissionType;
|
||||
import com.mattrixwv.raidbuilder.util.DatabaseTypeUtil.GamePermissionType;
|
||||
import com.mattrixwv.raidbuilder.util.validation.GameClassValidationUtil;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@@ -34,6 +36,8 @@ import lombok.extern.slf4j.Slf4j;
|
||||
public class GameClassController{
|
||||
private final ObjectMapper mapper;
|
||||
private final GameClassService gameClassService;
|
||||
//Utilities
|
||||
private final GameClassValidationUtil gcvUtil;
|
||||
|
||||
|
||||
@GetMapping("/{gameClassId}")
|
||||
@@ -107,12 +111,22 @@ public class GameClassController{
|
||||
GameClass gameClass = new GameClass();
|
||||
gameClass.setGameId(gameId);
|
||||
gameClass.setGameClassName(gameClassName);
|
||||
gameClassService.createGameClass(gameClass, file);
|
||||
List<String> errors = gcvUtil.validateNewGameClass(gameClass);
|
||||
if(errors.isEmpty()){
|
||||
gameClassService.createGameClass(gameClass, file);
|
||||
|
||||
returnNode.put("gameClassId", gameClass.getGameClassId().toString());
|
||||
returnNode.put("status", "success");
|
||||
returnNode.put("status", "success");
|
||||
returnNode.put("gameClassId", gameClass.getGameClassId().toString());
|
||||
|
||||
log.info("Successfully created game class: {}", gameClass.getGameClassId());
|
||||
}
|
||||
else{
|
||||
returnNode.put("status", "error");
|
||||
ArrayNode errorNode = mapper.createArrayNode();
|
||||
errors.forEach(errorNode::add);
|
||||
returnNode.set("errors", errorNode);
|
||||
}
|
||||
|
||||
log.info("Successfully created game class: {}", gameClass.getGameClassId());
|
||||
|
||||
return returnNode;
|
||||
}
|
||||
@@ -130,12 +144,20 @@ public class GameClassController{
|
||||
gameClass.setGameId(gameId);
|
||||
gameClass.setGameClassName(gameClassName);
|
||||
gameClass.setGameClassIcon(gameClassIcon);
|
||||
gameClassService.updateGameClass(gameClass, file);
|
||||
List<String> errors = gcvUtil.validateExistingGameClass(gameClass);
|
||||
if(errors.isEmpty()){
|
||||
gameClassService.updateGameClass(gameClass, file);
|
||||
|
||||
returnNode.put("gameClassId", gameClass.getGameClassId().toString());
|
||||
returnNode.put("status", "success");
|
||||
returnNode.put("gameClassId", gameClass.getGameClassId().toString());
|
||||
returnNode.put("status", "success");
|
||||
}
|
||||
else{
|
||||
returnNode.put("status", "error");
|
||||
ArrayNode errorNode = mapper.createArrayNode();
|
||||
errors.forEach(errorNode::add);
|
||||
returnNode.set("errors", errorNode);
|
||||
}
|
||||
|
||||
log.info("Successfully updated game class: {}", gameClass.getGameClassId());
|
||||
|
||||
return returnNode;
|
||||
}
|
||||
@@ -147,11 +169,19 @@ public class GameClassController{
|
||||
log.info("Deleting game class {}", gameClassId);
|
||||
|
||||
|
||||
GameClass gameClass = gameClassService.getById(gameClassId);
|
||||
ObjectNode returnNode = mapper.createObjectNode();
|
||||
gameClassService.deleteById(gameClassId);
|
||||
returnNode.put("status", "success");
|
||||
if(gameClass != null){
|
||||
gameClassService.deleteById(gameClassId);
|
||||
returnNode.put("status", "success");
|
||||
}
|
||||
else{
|
||||
returnNode.put("status", "error");
|
||||
ArrayNode errorNode = mapper.createArrayNode();
|
||||
errorNode.add("Game class ID is invalid");
|
||||
returnNode.set("errors", errorNode);
|
||||
}
|
||||
|
||||
log.info("Successfully deleted game class: {}", gameClassId);
|
||||
|
||||
return returnNode;
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ArrayNode;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.mattrixwv.raidbuilder.annotation.AccountAuthorization;
|
||||
import com.mattrixwv.raidbuilder.annotation.GameAuthorization;
|
||||
@@ -22,6 +23,7 @@ import com.mattrixwv.raidbuilder.entity.Game;
|
||||
import com.mattrixwv.raidbuilder.service.GameService;
|
||||
import com.mattrixwv.raidbuilder.util.DatabaseTypeUtil.AccountPermissionType;
|
||||
import com.mattrixwv.raidbuilder.util.DatabaseTypeUtil.GamePermissionType;
|
||||
import com.mattrixwv.raidbuilder.util.validation.GameValidationUtil;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@@ -34,8 +36,19 @@ import lombok.extern.slf4j.Slf4j;
|
||||
public class GameController{
|
||||
private final ObjectMapper mapper;
|
||||
private final GameService gameService;
|
||||
//Utilities
|
||||
private final GameValidationUtil gvUtil;
|
||||
|
||||
|
||||
@GetMapping("/{gameId}")
|
||||
@AccountAuthorization(permissions = {AccountPermissionType.ADMIN, AccountPermissionType.USER})
|
||||
public Game getGame(@PathVariable("gameId") UUID gameId){
|
||||
log.info("Getting game {}", gameId);
|
||||
|
||||
|
||||
return gameService.getGameById(gameId);
|
||||
}
|
||||
|
||||
@GetMapping
|
||||
@AccountAuthorization(permissions = {AccountPermissionType.ADMIN, AccountPermissionType.USER})
|
||||
public List<Game> getGames(@RequestParam("page") int page, @RequestParam("pageSize") int pageSize, @RequestParam(value = "searchTerm", required = false) String searchTerm){
|
||||
@@ -85,28 +98,29 @@ public class GameController{
|
||||
log.info("Creating game {}", gameName);
|
||||
|
||||
|
||||
//TODO: New game verification
|
||||
ObjectNode returnNode = mapper.createObjectNode();
|
||||
Game game = new Game();
|
||||
game.setGameName(gameName);
|
||||
game = gameService.createGame(game, file);
|
||||
returnNode.put("gameId", game.getGameId().toString());
|
||||
returnNode.put("status", "success");
|
||||
List<String> errors = gvUtil.validateNewGame(game);
|
||||
if(errors.isEmpty()){
|
||||
game = gameService.createGame(game, file);
|
||||
|
||||
returnNode.put("gameId", game.getGameId().toString());
|
||||
returnNode.put("status", "success");
|
||||
|
||||
log.info("Successfully created game: {}", game.getGameId());
|
||||
}
|
||||
else{
|
||||
returnNode.put("status", "error");
|
||||
ArrayNode errorNode = mapper.createArrayNode();
|
||||
errors.forEach(errorNode::add);
|
||||
returnNode.set("errors", errorNode);
|
||||
}
|
||||
|
||||
log.info("Successfully created game: {}", game.getGameId());
|
||||
|
||||
return returnNode;
|
||||
}
|
||||
|
||||
@GetMapping("/{gameId}")
|
||||
@AccountAuthorization(permissions = {AccountPermissionType.ADMIN, AccountPermissionType.USER})
|
||||
public Game getGame(@PathVariable("gameId") UUID gameId){
|
||||
log.info("Getting game {}", gameId);
|
||||
|
||||
|
||||
return gameService.getGameById(gameId);
|
||||
}
|
||||
|
||||
@PutMapping("/{gameId}")
|
||||
@AccountAuthorization(permissions = {AccountPermissionType.ADMIN, AccountPermissionType.USER})
|
||||
@GameAuthorization(permissions = {GamePermissionType.ADMIN})
|
||||
@@ -119,11 +133,19 @@ public class GameController{
|
||||
game.setGameId(gameId);
|
||||
game.setGameName(gameName);
|
||||
game.setGameIcon(gameIcon);
|
||||
game = gameService.updateGame(game, file);
|
||||
returnNode.put("gameId", game.getGameId().toString());
|
||||
returnNode.put("status", "success");
|
||||
List<String> errors = gvUtil.validateExistingGame(game);
|
||||
if(errors.isEmpty()){
|
||||
game = gameService.updateGame(game, file);
|
||||
|
||||
log.info("Successfully updated game: {}", game.getGameId());
|
||||
returnNode.put("gameId", game.getGameId().toString());
|
||||
returnNode.put("status", "success");
|
||||
}
|
||||
else{
|
||||
returnNode.put("status", "error");
|
||||
ArrayNode errorNode = mapper.createArrayNode();
|
||||
errors.forEach(errorNode::add);
|
||||
returnNode.set("errors", errorNode);
|
||||
}
|
||||
|
||||
return returnNode;
|
||||
}
|
||||
@@ -136,10 +158,19 @@ public class GameController{
|
||||
|
||||
|
||||
ObjectNode returnNode = mapper.createObjectNode();
|
||||
gameService.deleteById(gameId);
|
||||
returnNode.put("status", "success");
|
||||
Game game = gameService.getGameById(gameId);
|
||||
if(game != null){
|
||||
gameService.deleteById(gameId);
|
||||
|
||||
returnNode.put("status", "success");
|
||||
}
|
||||
else{
|
||||
returnNode.put("status", "error");
|
||||
ArrayNode errorNode = mapper.createArrayNode();
|
||||
errorNode.add("Game ID is invalid");
|
||||
returnNode.set("errors", errorNode);
|
||||
}
|
||||
|
||||
log.info("Successfully deleted game: {}", gameId);
|
||||
|
||||
return returnNode;
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ArrayNode;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.mattrixwv.raidbuilder.annotation.AccountAuthorization;
|
||||
import com.mattrixwv.raidbuilder.annotation.RaidGroupAuthorization;
|
||||
@@ -22,6 +23,7 @@ import com.mattrixwv.raidbuilder.entity.PersonCharacter;
|
||||
import com.mattrixwv.raidbuilder.service.PersonCharacterService;
|
||||
import com.mattrixwv.raidbuilder.util.DatabaseTypeUtil.AccountPermissionType;
|
||||
import com.mattrixwv.raidbuilder.util.DatabaseTypeUtil.RaidGroupPermissionType;
|
||||
import com.mattrixwv.raidbuilder.util.validation.PersonCharacterValidationUtil;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@@ -34,6 +36,8 @@ import lombok.extern.slf4j.Slf4j;
|
||||
public class PersonCharacterController{
|
||||
private final ObjectMapper mapper;
|
||||
private final PersonCharacterService personCharacterService;
|
||||
//Utilities
|
||||
private final PersonCharacterValidationUtil pcvUtil;
|
||||
|
||||
|
||||
@GetMapping
|
||||
@@ -91,37 +95,80 @@ public class PersonCharacterController{
|
||||
@PostMapping
|
||||
@AccountAuthorization(permissions = {AccountPermissionType.ADMIN, AccountPermissionType.USER})
|
||||
@RaidGroupAuthorization(permissions = {RaidGroupPermissionType.ADMIN, RaidGroupPermissionType.LEADER})
|
||||
public PersonCharacter createPersonCharacter(@PathVariable("raidGroupId") UUID raidGroupId, @PathVariable("personId") UUID personId, @RequestBody PersonCharacter personCharacter){
|
||||
public ObjectNode createPersonCharacter(@PathVariable("raidGroupId") UUID raidGroupId, @PathVariable("personId") UUID personId, @RequestBody PersonCharacter personCharacter){
|
||||
log.info("Creating person character {} for person {}", personCharacter.getCharacterName(), personId);
|
||||
|
||||
|
||||
personCharacter.setPersonId(personId);
|
||||
personCharacter = personCharacterService.createPersonCharacter(personCharacter);
|
||||
|
||||
return personCharacter;
|
||||
ObjectNode returnNode = mapper.createObjectNode();
|
||||
List<String> errors = pcvUtil.validateNewPersonCharacter(personCharacter, raidGroupId);
|
||||
if(errors.isEmpty()){
|
||||
personCharacter = personCharacterService.createPersonCharacter(personCharacter);
|
||||
|
||||
returnNode.put("status", "success");
|
||||
returnNode.put("personCharacterId", personCharacter.getPersonCharacterId().toString());
|
||||
|
||||
log.info("Created person character {} for person {}", personCharacter.getCharacterName(), personId);
|
||||
}
|
||||
else{
|
||||
returnNode.put("status", "error");
|
||||
returnNode.set("errors", mapper.valueToTree(errors));
|
||||
}
|
||||
|
||||
|
||||
return returnNode;
|
||||
}
|
||||
|
||||
@PutMapping("/{characterId}")
|
||||
@AccountAuthorization(permissions = {AccountPermissionType.ADMIN, AccountPermissionType.USER})
|
||||
@RaidGroupAuthorization(permissions = {RaidGroupPermissionType.ADMIN, RaidGroupPermissionType.LEADER})
|
||||
public PersonCharacter updatePersonCharacter(@PathVariable("raidGroupId") UUID raidGroupId, @PathVariable("personId") UUID personId, @PathVariable("characterId") UUID characterId, @RequestBody PersonCharacter personCharacter){
|
||||
public ObjectNode updatePersonCharacter(@PathVariable("raidGroupId") UUID raidGroupId, @PathVariable("personId") UUID personId, @PathVariable("characterId") UUID characterId, @RequestBody PersonCharacter personCharacter){
|
||||
log.info("Updating person character {} for person {}", personCharacter.getCharacterName(), personId);
|
||||
|
||||
|
||||
personCharacter.setPersonCharacterId(characterId);
|
||||
personCharacter.setPersonId(personId);
|
||||
personCharacter = personCharacterService.updatePersonCharacter(personCharacter);
|
||||
|
||||
return personCharacter;
|
||||
ObjectNode returnNode = mapper.createObjectNode();
|
||||
List<String> errors = pcvUtil.validateExistingPersonCharacter(personCharacter, raidGroupId);
|
||||
if(errors.isEmpty()){
|
||||
personCharacter = personCharacterService.updatePersonCharacter(personCharacter);
|
||||
|
||||
returnNode.put("status", "success");
|
||||
returnNode.put("personCharacterId", personCharacter.getPersonCharacterId().toString());
|
||||
}
|
||||
else{
|
||||
returnNode.put("status", "error");
|
||||
returnNode.set("errors", mapper.valueToTree(errors));
|
||||
}
|
||||
|
||||
|
||||
return returnNode;
|
||||
}
|
||||
|
||||
@DeleteMapping("/{characterId}")
|
||||
@AccountAuthorization(permissions = {AccountPermissionType.ADMIN, AccountPermissionType.USER})
|
||||
@RaidGroupAuthorization(permissions = {RaidGroupPermissionType.ADMIN, RaidGroupPermissionType.LEADER})
|
||||
public void deletePersonCharacter(@PathVariable("raidGroupId") UUID raidGroupId, @PathVariable("personId") UUID personId, @PathVariable("characterId") UUID characterId){
|
||||
public ObjectNode deletePersonCharacter(@PathVariable("raidGroupId") UUID raidGroupId, @PathVariable("personId") UUID personId, @PathVariable("characterId") UUID characterId){
|
||||
log.info("Deleting person character {} for person {}", characterId, personId);
|
||||
|
||||
|
||||
personCharacterService.deletePersonCharacter(characterId);
|
||||
ObjectNode returnNode = mapper.createObjectNode();
|
||||
PersonCharacter personCharacter = personCharacterService.getById(characterId);
|
||||
if(personCharacter != null){
|
||||
personCharacterService.deletePersonCharacter(characterId);
|
||||
|
||||
returnNode.put("status", "success");
|
||||
}
|
||||
else{
|
||||
ArrayNode errorsNode = mapper.createArrayNode();
|
||||
errorsNode.add("Person character not found");
|
||||
returnNode.put("status", "error");
|
||||
returnNode.set("errors", errorsNode);
|
||||
}
|
||||
|
||||
|
||||
return returnNode;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ import com.mattrixwv.raidbuilder.entity.Person;
|
||||
import com.mattrixwv.raidbuilder.service.PersonService;
|
||||
import com.mattrixwv.raidbuilder.util.DatabaseTypeUtil.AccountPermissionType;
|
||||
import com.mattrixwv.raidbuilder.util.DatabaseTypeUtil.RaidGroupPermissionType;
|
||||
import com.mattrixwv.raidbuilder.util.validation.PersonValidationUtil;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@@ -35,6 +36,8 @@ import lombok.extern.slf4j.Slf4j;
|
||||
public class PersonController{
|
||||
private final ObjectMapper mapper;
|
||||
private final PersonService personService;
|
||||
//Utils
|
||||
private final PersonValidationUtil pvUtil;
|
||||
|
||||
|
||||
@GetMapping
|
||||
@@ -96,30 +99,55 @@ public class PersonController{
|
||||
@PostMapping
|
||||
@AccountAuthorization(permissions = {AccountPermissionType.ADMIN, AccountPermissionType.USER})
|
||||
@RaidGroupAuthorization(permissions = {RaidGroupPermissionType.ADMIN, RaidGroupPermissionType.LEADER})
|
||||
public Person createPerson(@PathVariable("raidGroupId") UUID raidGroupId, @RequestBody Person person){
|
||||
public ObjectNode createPerson(@PathVariable("raidGroupId") UUID raidGroupId, @RequestBody Person person){
|
||||
log.info("Creating person for raid group {}", raidGroupId);
|
||||
|
||||
|
||||
person.setRaidGroupId(raidGroupId);
|
||||
person = personService.createPerson(person);
|
||||
|
||||
ObjectNode returnNode = mapper.createObjectNode();
|
||||
List<String> errors = pvUtil.validateNewPerson(person);
|
||||
if(errors.isEmpty()){
|
||||
person = personService.createPerson(person);
|
||||
|
||||
returnNode.put("status", "success");
|
||||
returnNode.put("personId", person.getPersonId().toString());
|
||||
|
||||
log.info("Created person {} for raid group {}", person.getPersonName(), raidGroupId);
|
||||
}
|
||||
else{
|
||||
returnNode.put("status", "error");
|
||||
returnNode.set("errors", mapper.valueToTree(errors));
|
||||
}
|
||||
|
||||
|
||||
return person;
|
||||
return returnNode;
|
||||
}
|
||||
|
||||
@PutMapping("/{personId}")
|
||||
@AccountAuthorization(permissions = {AccountPermissionType.ADMIN, AccountPermissionType.USER})
|
||||
@RaidGroupAuthorization(permissions = {RaidGroupPermissionType.ADMIN, RaidGroupPermissionType.LEADER})
|
||||
public Person updatePerson(@PathVariable("raidGroupId") UUID raidGroupId, @PathVariable("personId") UUID personId, @RequestBody Person person){
|
||||
public ObjectNode updatePerson(@PathVariable("raidGroupId") UUID raidGroupId, @PathVariable("personId") UUID personId, @RequestBody Person person){
|
||||
log.info("Updating person for raid group {}", raidGroupId);
|
||||
|
||||
|
||||
person.setPersonId(personId);
|
||||
person.setRaidGroupId(raidGroupId);
|
||||
person = personService.updatePerson(person);
|
||||
|
||||
ObjectNode returnNode = mapper.createObjectNode();
|
||||
List<String> errors = pvUtil.validateExistingPerson(person);
|
||||
if(errors.isEmpty()){
|
||||
person = personService.updatePerson(person);
|
||||
|
||||
returnNode.put("status", "success");
|
||||
}
|
||||
else{
|
||||
returnNode.put("status", "error");
|
||||
returnNode.set("errors", mapper.valueToTree(errors));
|
||||
}
|
||||
|
||||
|
||||
return person;
|
||||
return returnNode;
|
||||
}
|
||||
|
||||
@DeleteMapping("/{personId}")
|
||||
|
||||
@@ -15,6 +15,7 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ArrayNode;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.mattrixwv.raidbuilder.annotation.AccountAuthorization;
|
||||
import com.mattrixwv.raidbuilder.annotation.RaidGroupAuthorization;
|
||||
@@ -24,6 +25,7 @@ import com.mattrixwv.raidbuilder.service.PersonCharacterService;
|
||||
import com.mattrixwv.raidbuilder.service.RaidGroupService;
|
||||
import com.mattrixwv.raidbuilder.util.DatabaseTypeUtil.AccountPermissionType;
|
||||
import com.mattrixwv.raidbuilder.util.DatabaseTypeUtil.RaidGroupPermissionType;
|
||||
import com.mattrixwv.raidbuilder.util.validation.RaidGroupValidationUtil;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@@ -37,6 +39,8 @@ public class RaidGroupController{
|
||||
private final ObjectMapper mapper;
|
||||
private final RaidGroupService raidGroupService;
|
||||
private final PersonCharacterService personCharacterService;
|
||||
//Utilities
|
||||
private final RaidGroupValidationUtil rgvUtil;
|
||||
|
||||
|
||||
@GetMapping
|
||||
@@ -86,17 +90,24 @@ public class RaidGroupController{
|
||||
log.info("Creating raid group {}", raidGroupName);
|
||||
|
||||
|
||||
//TODO: New raid group verification
|
||||
ObjectNode returnNode = mapper.createObjectNode();
|
||||
RaidGroup raidGroup = new RaidGroup();
|
||||
raidGroup.setGameId(gameId);
|
||||
raidGroup.setRaidGroupName(raidGroupName);
|
||||
raidGroupService.createRaidGroup(raidGroup, file);
|
||||
List<String> errors = rgvUtil.validateNewRaidGroup(raidGroup);
|
||||
if(errors.isEmpty()){
|
||||
raidGroupService.createRaidGroup(raidGroup, file);
|
||||
|
||||
returnNode.put("raidGroupId", raidGroup.getRaidGroupId().toString());
|
||||
returnNode.put("status", "success");
|
||||
returnNode.put("raidGroupId", raidGroup.getRaidGroupId().toString());
|
||||
returnNode.put("status", "success");
|
||||
|
||||
log.info("Created raid group {}", raidGroup.getRaidGroupName());
|
||||
}
|
||||
else{
|
||||
returnNode.put("status", "fail");
|
||||
returnNode.set("errors", mapper.valueToTree(errors));
|
||||
}
|
||||
|
||||
log.info("Successfully created raid group: {}", raidGroup.getRaidGroupId());
|
||||
|
||||
return returnNode;
|
||||
}
|
||||
@@ -128,12 +139,18 @@ public class RaidGroupController{
|
||||
raidGroup.setGameId(gameId);
|
||||
raidGroup.setRaidGroupName(raidGroupName);
|
||||
raidGroup.setRaidGroupIcon(raidGroupIcon);
|
||||
raidGroupService.updateRaidGroup(raidGroup, file);
|
||||
List<String> errors = rgvUtil.validateExistingRaidGroup(raidGroup);
|
||||
if(errors.isEmpty()){
|
||||
raidGroupService.updateRaidGroup(raidGroup, file);
|
||||
|
||||
returnNode.put("raidGroupId", raidGroup.getRaidGroupId().toString());
|
||||
returnNode.put("status", "success");
|
||||
returnNode.put("raidGroupId", raidGroup.getRaidGroupId().toString());
|
||||
returnNode.put("status", "success");
|
||||
}
|
||||
else{
|
||||
returnNode.put("status", "fail");
|
||||
returnNode.set("errors", mapper.valueToTree(errors));
|
||||
}
|
||||
|
||||
log.info("Successfully updated raid group: {}", raidGroup.getRaidGroupId());
|
||||
|
||||
return returnNode;
|
||||
}
|
||||
@@ -146,10 +163,18 @@ public class RaidGroupController{
|
||||
|
||||
|
||||
ObjectNode returnNode = mapper.createObjectNode();
|
||||
raidGroupService.deleteById(raidGroupId);
|
||||
returnNode.put("status", "success");
|
||||
RaidGroup existingRaidGroup = raidGroupService.getByRaidGroupId(raidGroupId);
|
||||
if(existingRaidGroup != null){
|
||||
raidGroupService.deleteById(raidGroupId);
|
||||
returnNode.put("status", "success");
|
||||
}
|
||||
else{
|
||||
returnNode.put("status", "fail");
|
||||
ArrayNode errorsNode = mapper.createArrayNode();
|
||||
errorsNode.add("Raid group does not exist");
|
||||
returnNode.set("errors", errorsNode);
|
||||
}
|
||||
|
||||
log.info("Successfully deleted raid group: {}", raidGroupId);
|
||||
|
||||
return returnNode;
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ArrayNode;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.mattrixwv.raidbuilder.annotation.AccountAuthorization;
|
||||
import com.mattrixwv.raidbuilder.annotation.RaidGroupAuthorization;
|
||||
@@ -25,6 +26,7 @@ import com.mattrixwv.raidbuilder.service.AccountService;
|
||||
import com.mattrixwv.raidbuilder.service.RaidGroupRequestService;
|
||||
import com.mattrixwv.raidbuilder.util.DatabaseTypeUtil.AccountPermissionType;
|
||||
import com.mattrixwv.raidbuilder.util.DatabaseTypeUtil.RaidGroupPermissionType;
|
||||
import com.mattrixwv.raidbuilder.util.validation.RaidGroupRequestValidationUtil;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@@ -38,6 +40,8 @@ public class RaidGroupRequestController{
|
||||
private final ObjectMapper mapper;
|
||||
private final AccountService accountService;
|
||||
private final RaidGroupRequestService rgrService;
|
||||
//Utilities
|
||||
private final RaidGroupRequestValidationUtil rgrvUtil;
|
||||
|
||||
|
||||
@GetMapping
|
||||
@@ -98,17 +102,30 @@ public class RaidGroupRequestController{
|
||||
|
||||
@PostMapping
|
||||
@AccountAuthorization(permissions = {AccountPermissionType.ADMIN, AccountPermissionType.USER})
|
||||
public RaidGroupRequest createRaidGroupRequest(@PathVariable("raidGroupId") UUID raidGroupId, @RequestBody RaidGroupRequest raidGroupRequest, Authentication authentication){
|
||||
public ObjectNode createRaidGroupRequest(@PathVariable("raidGroupId") UUID raidGroupId, @RequestBody RaidGroupRequest raidGroupRequest, Authentication authentication){
|
||||
log.info("Creating raid group request for raid group id: {}", raidGroupId);
|
||||
|
||||
|
||||
Account account = accountService.getByUsername(authentication.getName());
|
||||
raidGroupRequest.setAccountId(account.getAccountId());
|
||||
raidGroupRequest.setRaidGroupId(raidGroupId);
|
||||
raidGroupRequest = rgrService.createRaidGroupRequest(raidGroupRequest);
|
||||
ObjectNode returnNode = mapper.createObjectNode();
|
||||
List<String> errors = rgrvUtil.validateNewRaidGroupRequest(raidGroupRequest);
|
||||
if(errors.isEmpty()){
|
||||
raidGroupRequest = rgrService.createRaidGroupRequest(raidGroupRequest);
|
||||
|
||||
returnNode.put("status", "success");
|
||||
returnNode.put("raidGroupRequestId", raidGroupRequest.getRaidGroupRequestId().toString());
|
||||
|
||||
log.info("Created raid group request for raid group id: {}", raidGroupId);
|
||||
}
|
||||
else{
|
||||
returnNode.put("status", "fail");
|
||||
returnNode.set("errors", mapper.valueToTree(errors));
|
||||
}
|
||||
|
||||
|
||||
return raidGroupRequest;
|
||||
return returnNode;
|
||||
}
|
||||
|
||||
@PutMapping("/{raidGroupRequestId}")
|
||||
@@ -119,10 +136,18 @@ public class RaidGroupRequestController{
|
||||
|
||||
raidGroupRequest.setRaidGroupRequestId(raidGroupRequestId);
|
||||
raidGroupRequest.setRaidGroupId(raidGroupId);
|
||||
raidGroupRequest = rgrService.updateRaidGroupRequest(raidGroupRequest);
|
||||
|
||||
ObjectNode returnNode = mapper.createObjectNode();
|
||||
returnNode.put("status", "success");
|
||||
List<String> errors = rgrvUtil.validateExistingRaidGroupRequest(raidGroupRequest);
|
||||
if(errors.isEmpty()){
|
||||
raidGroupRequest = rgrService.updateRaidGroupRequest(raidGroupRequest);
|
||||
|
||||
returnNode.put("status", "success");
|
||||
returnNode.put("raidGroupRequestId", raidGroupRequest.getRaidGroupRequestId().toString());
|
||||
}
|
||||
else{
|
||||
returnNode.put("status", "fail");
|
||||
returnNode.set("errors", mapper.valueToTree(errors));
|
||||
}
|
||||
|
||||
|
||||
return returnNode;
|
||||
@@ -134,10 +159,19 @@ public class RaidGroupRequestController{
|
||||
log.info("Deleting raid group request for raid group id: {}", raidGroupId);
|
||||
|
||||
|
||||
rgrService.deleteRaidGroupRequest(raidGroupRequestId);
|
||||
|
||||
ObjectNode returnNode = mapper.createObjectNode();
|
||||
returnNode.put("status", "success");
|
||||
RaidGroupRequest existingRaidGroupRequest = rgrService.getById(raidGroupRequestId);
|
||||
if(existingRaidGroupRequest != null){
|
||||
rgrService.deleteRaidGroupRequest(raidGroupRequestId);
|
||||
|
||||
returnNode.put("status", "success");
|
||||
}
|
||||
else{
|
||||
returnNode.put("status", "fail");
|
||||
ArrayNode errorsNode = mapper.createArrayNode();
|
||||
errorsNode.add("Raid Group Request does not exist");
|
||||
returnNode.set("errors", errorsNode);
|
||||
}
|
||||
|
||||
|
||||
return returnNode;
|
||||
|
||||
@@ -16,6 +16,7 @@ import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ArrayNode;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.mattrixwv.raidbuilder.annotation.AccountAuthorization;
|
||||
import com.mattrixwv.raidbuilder.annotation.RaidGroupAuthorization;
|
||||
@@ -23,6 +24,7 @@ import com.mattrixwv.raidbuilder.entity.RaidInstance;
|
||||
import com.mattrixwv.raidbuilder.service.RaidInstanceService;
|
||||
import com.mattrixwv.raidbuilder.util.DatabaseTypeUtil.AccountPermissionType;
|
||||
import com.mattrixwv.raidbuilder.util.DatabaseTypeUtil.RaidGroupPermissionType;
|
||||
import com.mattrixwv.raidbuilder.util.validation.RaidInstanceValidationUtil;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@@ -35,6 +37,8 @@ import lombok.extern.slf4j.Slf4j;
|
||||
public class RaidInstanceController{
|
||||
private final ObjectMapper mapper;
|
||||
private final RaidInstanceService raidInstanceService;
|
||||
//Utilities
|
||||
private final RaidInstanceValidationUtil rivUtil;
|
||||
|
||||
|
||||
@GetMapping
|
||||
@@ -94,32 +98,55 @@ public class RaidInstanceController{
|
||||
@PostMapping
|
||||
@AccountAuthorization(permissions = {AccountPermissionType.ADMIN, AccountPermissionType.USER})
|
||||
@RaidGroupAuthorization(permissions = {RaidGroupPermissionType.ADMIN, RaidGroupPermissionType.LEADER})
|
||||
public RaidInstance createRaidInstance(@PathVariable("raidGroupId") UUID raidGroupId, @RequestBody RaidInstance raidInstance){
|
||||
public ObjectNode createRaidInstance(@PathVariable("raidGroupId") UUID raidGroupId, @RequestBody RaidInstance raidInstance){
|
||||
log.info("Creating raid instance for raid group {}", raidGroupId);
|
||||
|
||||
|
||||
raidInstance.setRaidGroupId(raidGroupId);
|
||||
RaidInstance createdRaidInstance = raidInstanceService.createRaidInstance(raidInstance);
|
||||
log.debug("Created raid instance {}", createdRaidInstance);
|
||||
ObjectNode returnNode = mapper.createObjectNode();
|
||||
List<String> errors = rivUtil.validateNewRaidInstance(raidInstance);
|
||||
if(errors.isEmpty()){
|
||||
RaidInstance createdRaidInstance = raidInstanceService.createRaidInstance(raidInstance);
|
||||
|
||||
returnNode.put("status", "success");
|
||||
returnNode.put("raidInstanceId", createdRaidInstance.getRaidInstanceId().toString());
|
||||
|
||||
log.info("Created raid instance {}", createdRaidInstance);
|
||||
}
|
||||
else{
|
||||
returnNode.put("status", "error");
|
||||
returnNode.set("errors", mapper.valueToTree(errors));
|
||||
}
|
||||
|
||||
|
||||
return createdRaidInstance;
|
||||
|
||||
return returnNode;
|
||||
}
|
||||
|
||||
@PutMapping("/{raidInstanceId}")
|
||||
@AccountAuthorization(permissions = {AccountPermissionType.ADMIN, AccountPermissionType.USER})
|
||||
@RaidGroupAuthorization(permissions = {RaidGroupPermissionType.ADMIN, RaidGroupPermissionType.LEADER})
|
||||
public RaidInstance updateRaidInstance(@PathVariable("raidGroupId") UUID raidGroupId, @PathVariable("raidInstanceId") UUID raidInstanceId, @RequestBody RaidInstance raidInstance){
|
||||
public ObjectNode updateRaidInstance(@PathVariable("raidGroupId") UUID raidGroupId, @PathVariable("raidInstanceId") UUID raidInstanceId, @RequestBody RaidInstance raidInstance){
|
||||
log.info("Updating raid instance {} for raid group {}", raidInstanceId, raidGroupId);
|
||||
|
||||
|
||||
raidInstance.setRaidInstanceId(raidInstanceId);
|
||||
raidInstance.setRaidGroupId(raidGroupId);
|
||||
RaidInstance updatedRaidInstance = raidInstanceService.updateRaidInstance(raidInstance);
|
||||
log.debug("Updated raid instance {}", updatedRaidInstance);
|
||||
ObjectNode returnNode = mapper.createObjectNode();
|
||||
List<String> errors = rivUtil.validateExistingRaidInstance(raidInstance);
|
||||
if(errors.isEmpty()){
|
||||
RaidInstance updatedRaidInstance = raidInstanceService.updateRaidInstance(raidInstance);
|
||||
|
||||
returnNode.put("status", "success");
|
||||
returnNode.put("raidInstanceId", updatedRaidInstance.getRaidInstanceId().toString());
|
||||
}
|
||||
else{
|
||||
returnNode.put("status", "error");
|
||||
returnNode.set("errors", mapper.valueToTree(errors));
|
||||
}
|
||||
|
||||
|
||||
return updatedRaidInstance;
|
||||
return returnNode;
|
||||
}
|
||||
|
||||
@DeleteMapping("/{raidInstanceId}")
|
||||
@@ -129,10 +156,18 @@ public class RaidInstanceController{
|
||||
log.info("Deleting raid instance {} for raid group {}", raidInstanceId, raidGroupId);
|
||||
|
||||
|
||||
raidInstanceService.deleteById(raidInstanceId);
|
||||
|
||||
ObjectNode returnNode = mapper.createObjectNode();
|
||||
returnNode.put("status", "success");
|
||||
if(raidInstanceService.findById(raidInstanceId) == null){
|
||||
returnNode.put("status", "fail");
|
||||
ArrayNode errorsNode = mapper.createArrayNode();
|
||||
errorsNode.add("Raid instance does not exist");
|
||||
returnNode.set("errors", errorsNode);
|
||||
}
|
||||
else{
|
||||
raidInstanceService.deleteById(raidInstanceId);
|
||||
|
||||
returnNode.put("status", "success");
|
||||
}
|
||||
|
||||
|
||||
return returnNode;
|
||||
|
||||
@@ -15,6 +15,7 @@ import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ArrayNode;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.mattrixwv.raidbuilder.annotation.AccountAuthorization;
|
||||
import com.mattrixwv.raidbuilder.annotation.RaidGroupAuthorization;
|
||||
@@ -23,6 +24,7 @@ import com.mattrixwv.raidbuilder.entity.RaidLayoutClassGroupXref;
|
||||
import com.mattrixwv.raidbuilder.service.RaidLayoutService;
|
||||
import com.mattrixwv.raidbuilder.util.DatabaseTypeUtil.AccountPermissionType;
|
||||
import com.mattrixwv.raidbuilder.util.DatabaseTypeUtil.RaidGroupPermissionType;
|
||||
import com.mattrixwv.raidbuilder.util.validation.RaidLayoutValidationUtil;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@@ -36,6 +38,8 @@ import lombok.extern.slf4j.Slf4j;
|
||||
public class RaidLayoutController{
|
||||
private final ObjectMapper mapper;
|
||||
private final RaidLayoutService raidLayoutService;
|
||||
//Utilities
|
||||
private final RaidLayoutValidationUtil rlvUtil;
|
||||
|
||||
|
||||
@GetMapping
|
||||
@@ -94,11 +98,20 @@ public class RaidLayoutController{
|
||||
RaidLayoutClassGroupXref[] xrefsArray = mapper.convertValue(bodyNode.get("raidLayoutClassGroupXrefs"), RaidLayoutClassGroupXref[].class);
|
||||
List<RaidLayoutClassGroupXref> xrefs = List.of(xrefsArray);
|
||||
|
||||
raidLayout = raidLayoutService.createRaidLayout(raidLayout, xrefs);
|
||||
|
||||
ObjectNode returnNode = mapper.createObjectNode();
|
||||
returnNode.put("raidLayoutId", raidLayout.getRaidLayoutId().toString());
|
||||
returnNode.put("status", "success");
|
||||
List<String> errors = rlvUtil.validateNewRaidLayout(raidLayout);
|
||||
if(errors.isEmpty()){
|
||||
raidLayout = raidLayoutService.createRaidLayout(raidLayout, xrefs);
|
||||
|
||||
returnNode.put("raidLayoutId", raidLayout.getRaidLayoutId().toString());
|
||||
returnNode.put("status", "success");
|
||||
|
||||
log.info("Created Raid Layout {} for Raid Group {}", raidLayout.getRaidLayoutId(), raidGroupId);
|
||||
}
|
||||
else{
|
||||
returnNode.put("status", "fail");
|
||||
returnNode.set("errors", mapper.valueToTree(errors));
|
||||
}
|
||||
|
||||
return returnNode;
|
||||
}
|
||||
@@ -116,11 +129,19 @@ public class RaidLayoutController{
|
||||
RaidLayoutClassGroupXref[] xrefsArray = mapper.convertValue(bodyNode.get("raidLayoutClassGroupXrefs"), RaidLayoutClassGroupXref[].class);
|
||||
List<RaidLayoutClassGroupXref> xrefs = List.of(xrefsArray);
|
||||
|
||||
raidLayoutService.updateRaidLayout(raidLayout, xrefs);
|
||||
|
||||
ObjectNode returnNode = mapper.createObjectNode();
|
||||
returnNode.put("raidLayoutId", raidLayout.getRaidLayoutId().toString());
|
||||
returnNode.put("status", "success");
|
||||
List<String> errors = rlvUtil.validateExistingRaidLayout(raidLayout);
|
||||
if(errors.isEmpty()){
|
||||
raidLayoutService.updateRaidLayout(raidLayout, xrefs);
|
||||
|
||||
returnNode.put("status", "success");
|
||||
returnNode.put("raidLayoutId", raidLayout.getRaidLayoutId().toString());
|
||||
}
|
||||
else{
|
||||
returnNode.put("status", "fail");
|
||||
returnNode.set("errors", mapper.valueToTree(errors));
|
||||
}
|
||||
|
||||
|
||||
return returnNode;
|
||||
}
|
||||
@@ -132,10 +153,19 @@ public class RaidLayoutController{
|
||||
log.info("Deleting Raid Layout {} for Raid Group {}", raidLayoutId, raidGroupId);
|
||||
|
||||
|
||||
raidLayoutService.deleteRaidLayout(raidLayoutId, raidGroupId);
|
||||
|
||||
ObjectNode returnNode = mapper.createObjectNode();
|
||||
returnNode.put("status", "success");
|
||||
RaidLayout raidLayout = raidLayoutService.getRaidLayout(raidLayoutId, raidGroupId);
|
||||
if(raidLayout == null){
|
||||
ArrayNode errorsNode = mapper.createArrayNode();
|
||||
errorsNode.add("Raid Layout doesn't exist");
|
||||
returnNode.put("status", "fail");
|
||||
returnNode.set("errors", errorsNode);
|
||||
}
|
||||
else{
|
||||
raidLayoutService.deleteRaidLayout(raidLayoutId, raidGroupId);
|
||||
|
||||
returnNode.put("status", "success");
|
||||
}
|
||||
|
||||
|
||||
return returnNode;
|
||||
|
||||
@@ -14,6 +14,7 @@ public interface PersonRepository extends PersonCustomRepository, JpaRepository<
|
||||
public void deleteAllByRaidGroupId(UUID raidGroupId);
|
||||
public void deleteAllByRaidGroupIdIn(Iterable<UUID> raidGroupIds);
|
||||
|
||||
public Person findByPersonNameAndRaidGroupId(String personName, UUID raidGroupId);
|
||||
|
||||
public List<Person> findAllByRaidGroupId(UUID raidGroupId);
|
||||
public List<Person> findAllByRaidGroupIdIn(Iterable<UUID> raidGroupIds);
|
||||
|
||||
@@ -15,7 +15,7 @@ public interface PersonCharacterRepository extends PersonCharacterCustomReposito
|
||||
public void deleteAllByPersonIdIn(Iterable<UUID> personIds);
|
||||
|
||||
|
||||
public PersonCharacter findByPersonCharacterId(UUID personCharacterId);
|
||||
public PersonCharacter findByPersonIdAndCharacterName(UUID personId, String characterName);
|
||||
public List<PersonCharacter> findAllByPersonId(UUID personId);
|
||||
public List<PersonCharacter> findAllByPersonId(UUID personId, PageRequest pageRequest);
|
||||
public List<PersonCharacter> findAllByPersonIdAndCharacterNameContainingIgnoreCase(UUID personId, String searchTerm, PageRequest pageRequest);
|
||||
|
||||
@@ -11,6 +11,8 @@ import com.mattrixwv.raidbuilder.entity.RaidGroup;
|
||||
|
||||
|
||||
public interface RaidGroupRepository extends RaidGroupCustomRepository, JpaRepository<RaidGroup, UUID>{
|
||||
public RaidGroup findByRaidGroupNameAndGameId(String raidGroupName, UUID gameId);
|
||||
|
||||
public List<RaidGroup> findAllByGameId(UUID gameId);
|
||||
public List<RaidGroup> findAllByGameId(UUID gameId, PageRequest pageRequest);
|
||||
public List<RaidGroup> findAllByRaidGroupNameContainingIgnoreCase(String searchTerm, PageRequest pageRequest);
|
||||
|
||||
@@ -17,6 +17,7 @@ public interface RaidLayoutRepository extends RaidLayoutCustomRepository, JpaRep
|
||||
|
||||
|
||||
public RaidLayout findByRaidLayoutIdAndRaidGroupId(UUID raidLayoutId, UUID raidGroupId);
|
||||
public RaidLayout findByRaidLayoutNameAndRaidGroupId(String raidLayoutName, UUID raidGroupId);
|
||||
public List<RaidLayout> findAllByRaidGroupId(UUID raidGroupId);
|
||||
public List<RaidLayout> findAllByRaidGroupId(UUID raidGroupId, PageRequest pageRequest);
|
||||
public List<RaidLayout> findAllByRaidGroupIdIn(Iterable<UUID> raidGroupIds);
|
||||
|
||||
@@ -21,12 +21,12 @@ public class GameCalendarEventService{
|
||||
|
||||
|
||||
//Write
|
||||
public void createGameCalendarEvent(GameCalendarEvent gce){
|
||||
gceRepository.save(gce);
|
||||
public GameCalendarEvent createGameCalendarEvent(GameCalendarEvent gce){
|
||||
return gceRepository.save(gce);
|
||||
}
|
||||
|
||||
public void updateGameCalendarEvent(GameCalendarEvent gce){
|
||||
gceRepository.save(gce);
|
||||
public GameCalendarEvent updateGameCalendarEvent(GameCalendarEvent gce){
|
||||
return gceRepository.save(gce);
|
||||
}
|
||||
|
||||
public void deleteGameCalendarEvent(UUID gceId){
|
||||
@@ -39,6 +39,10 @@ public class GameCalendarEventService{
|
||||
|
||||
|
||||
//Read
|
||||
public GameCalendarEvent getById(UUID gceId){
|
||||
return gceRepository.findById(gceId).orElse(null);
|
||||
}
|
||||
|
||||
public List<GameCalendarEvent> getByGameId(UUID gameId){
|
||||
return gceRepository.findAllByGameId(gameId);
|
||||
}
|
||||
|
||||
@@ -46,6 +46,14 @@ public class PersonCharacterService{
|
||||
|
||||
|
||||
//Read
|
||||
public PersonCharacter getById(UUID personCharacterId){
|
||||
return personCharacterRepository.findById(personCharacterId).orElse(null);
|
||||
}
|
||||
|
||||
public PersonCharacter getByPersonIdAndCharacterName(UUID personId, String characterName){
|
||||
return personCharacterRepository.findByPersonIdAndCharacterName(personId, characterName);
|
||||
}
|
||||
|
||||
public List<PersonCharacter> getByPersonId(UUID personId){
|
||||
return personCharacterRepository.findAllByPersonId(personId);
|
||||
}
|
||||
|
||||
@@ -65,6 +65,11 @@ public class PersonService{
|
||||
}
|
||||
}
|
||||
|
||||
public Person getPersonByName(String personName, UUID raidGroupId){
|
||||
return personRepository.findByPersonNameAndRaidGroupId(personName, raidGroupId);
|
||||
|
||||
}
|
||||
|
||||
public List<Person> getPeopleByRaidGroup(UUID raidGroupId, int page, int pageSize){
|
||||
return personRepository.findAllByRaidGroupId(raidGroupId, PageRequest.of(page, pageSize, Sort.by("personName").ascending()));
|
||||
}
|
||||
|
||||
@@ -45,6 +45,10 @@ public class RaidGroupCalendarEventService{
|
||||
|
||||
|
||||
//Read
|
||||
public RaidGroupCalendarEvent getByRaidGroupCalendarEventId(UUID rgceId){
|
||||
return rgceRepository.findById(rgceId).orElse(null);
|
||||
}
|
||||
|
||||
public List<RaidGroupCalendarEvent> getByRaidGroupId(UUID raidGroupId){
|
||||
return rgceRepository.findAllByRaidGroupId(raidGroupId);
|
||||
}
|
||||
|
||||
@@ -61,6 +61,10 @@ public class RaidGroupRequestService{
|
||||
|
||||
|
||||
//Read
|
||||
public RaidGroupRequest getById(UUID raidGroupRequestId){
|
||||
return rgrRepository.findById(raidGroupRequestId).orElseThrow();
|
||||
}
|
||||
|
||||
public List<RaidGroupRequest> getByAccountId(UUID accountId){
|
||||
return rgrRepository.findAllByAccountId(accountId);
|
||||
}
|
||||
|
||||
@@ -151,6 +151,11 @@ public class RaidGroupService{
|
||||
return raidGroupRepository.findById(raidGroupId).orElse(null);
|
||||
}
|
||||
|
||||
public RaidGroup getByRaidGroupName(String raidGroupName, UUID gameId){
|
||||
return raidGroupRepository.findByRaidGroupNameAndGameId(raidGroupName, gameId);
|
||||
|
||||
}
|
||||
|
||||
public List<RaidGroup> getRaidGroups(int page, int pageSize){
|
||||
return raidGroupRepository.findAll(PageRequest.of(page, pageSize, Sort.by("raidGroupName").ascending())).getContent();
|
||||
}
|
||||
|
||||
@@ -55,6 +55,10 @@ public class RaidInstancePersonCharacterXrefService{
|
||||
|
||||
|
||||
//Read
|
||||
public RaidInstancePersonCharacterXref getById(UUID ripcxId){
|
||||
return raidInstancePersonCharacterXrefRepository.findById(ripcxId).orElseThrow();
|
||||
}
|
||||
|
||||
public List<RaidInstancePersonCharacterXref> getByRaidInstanceId(UUID raidInstanceId){
|
||||
return raidInstancePersonCharacterXrefRepository.findAllByRaidInstanceId(raidInstanceId);
|
||||
}
|
||||
|
||||
@@ -75,6 +75,10 @@ public class RaidLayoutService{
|
||||
return raidLayoutRepository.findByRaidLayoutIdAndRaidGroupId(raidLayoutId, raidGroupId);
|
||||
}
|
||||
|
||||
public RaidLayout getRaidLayoutByName(String raidLayoutName, UUID raidGroupId){
|
||||
return raidLayoutRepository.findByRaidLayoutNameAndRaidGroupId(raidLayoutName, raidGroupId);
|
||||
}
|
||||
|
||||
public List<RaidLayout> getRaidLayoutsByRaidGroupId(UUID raidGroupId, int page, int pageSize){
|
||||
return raidLayoutRepository.findAllByRaidGroupId(raidGroupId, PageRequest.of(page, pageSize, Sort.by("raidLayoutName").ascending()));
|
||||
}
|
||||
|
||||
@@ -0,0 +1,191 @@
|
||||
package com.mattrixwv.raidbuilder.util.validation;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.mattrixwv.raidbuilder.entity.Game;
|
||||
import com.mattrixwv.raidbuilder.entity.GameCalendarEvent;
|
||||
import com.mattrixwv.raidbuilder.entity.RaidGroup;
|
||||
import com.mattrixwv.raidbuilder.entity.RaidGroupCalendarEvent;
|
||||
import com.mattrixwv.raidbuilder.service.GameCalendarEventService;
|
||||
import com.mattrixwv.raidbuilder.service.GameService;
|
||||
import com.mattrixwv.raidbuilder.service.RaidGroupCalendarEventService;
|
||||
import com.mattrixwv.raidbuilder.service.RaidGroupService;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
public class CalendarEventValidationUtil{
|
||||
private final GameCalendarEventService gceService;
|
||||
private final RaidGroupCalendarEventService rgceService;
|
||||
private final GameService gameService;
|
||||
private final RaidGroupService raidGroupService;
|
||||
|
||||
|
||||
public List<String> validateNewGameCalendarEvent(GameCalendarEvent gameCalendarEvent){
|
||||
ArrayList<String> errors = new ArrayList<>();
|
||||
|
||||
//Game Calendar Event
|
||||
if(gameCalendarEvent.getGameCalendarEventId() != null){
|
||||
errors.add("Should be creating a new event rather than updating an existing event");
|
||||
}
|
||||
|
||||
//Game ID
|
||||
if(gameCalendarEvent.getGameId() == null){
|
||||
errors.add("Game ID is required");
|
||||
}
|
||||
else{
|
||||
Game game = gameService.getGameById(gameCalendarEvent.getGameId());
|
||||
if(game == null){
|
||||
errors.add("Game ID is invalid");
|
||||
}
|
||||
}
|
||||
|
||||
//Event Name
|
||||
if((gameCalendarEvent.getEventName() == null) || (gameCalendarEvent.getEventName().trim().isEmpty())){
|
||||
errors.add("Event name is required");
|
||||
}
|
||||
|
||||
//Event Dates
|
||||
if(gameCalendarEvent.getEventStartDate() == null){
|
||||
errors.add("Event start date is required");
|
||||
}
|
||||
if(gameCalendarEvent.getEventEndDate() == null){
|
||||
errors.add("Event end date is required");
|
||||
}
|
||||
if(gameCalendarEvent.getEventStartDate().compareTo(gameCalendarEvent.getEventEndDate()) > 0){
|
||||
errors.add("Event start date must be before event end date");
|
||||
}
|
||||
|
||||
return errors;
|
||||
}
|
||||
|
||||
public List<String> validateExistingGameCalendarEvent(GameCalendarEvent gameCalendarEvent){
|
||||
ArrayList<String> errors = new ArrayList<>();
|
||||
|
||||
//Game Calendar Event
|
||||
if(gameCalendarEvent.getGameCalendarEventId() == null){
|
||||
errors.add("Game calendar event ID is required");
|
||||
return errors;
|
||||
}
|
||||
GameCalendarEvent existingGameCalendarEvent = gceService.getById(gameCalendarEvent.getGameCalendarEventId());
|
||||
if(existingGameCalendarEvent == null){
|
||||
errors.add("Game calendar event ID is invalid");
|
||||
}
|
||||
|
||||
//Game ID
|
||||
if(gameCalendarEvent.getGameId() == null){
|
||||
errors.add("Game ID is required");
|
||||
}
|
||||
else{
|
||||
Game game = gameService.getGameById(gameCalendarEvent.getGameId());
|
||||
if(game == null){
|
||||
errors.add("Game ID is invalid");
|
||||
}
|
||||
}
|
||||
|
||||
//Event Name
|
||||
if((gameCalendarEvent.getEventName() == null) || (gameCalendarEvent.getEventName().trim().isEmpty())){
|
||||
errors.add("Event name is required");
|
||||
}
|
||||
|
||||
//Event Dates
|
||||
if(gameCalendarEvent.getEventStartDate() == null){
|
||||
errors.add("Event start date is required");
|
||||
}
|
||||
if(gameCalendarEvent.getEventEndDate() == null){
|
||||
errors.add("Event end date is required");
|
||||
}
|
||||
if(gameCalendarEvent.getEventStartDate().compareTo(gameCalendarEvent.getEventEndDate()) > 0){
|
||||
errors.add("Event start date must be before event end date");
|
||||
}
|
||||
|
||||
return errors;
|
||||
}
|
||||
|
||||
public List<String> validateNewRaidGroupCalendarEvent(RaidGroupCalendarEvent raidGroupCalendarEvent){
|
||||
List<String> errors = new ArrayList<>();
|
||||
|
||||
//Check the ID
|
||||
if(raidGroupCalendarEvent.getRaidGroupCalendarEventId() != null){
|
||||
errors.add("Should be creating a new event rather than updating an existing event");
|
||||
}
|
||||
|
||||
//Check the Raid Group ID
|
||||
if(raidGroupCalendarEvent.getRaidGroupId() == null){
|
||||
errors.add("Raid Group ID is required");
|
||||
}
|
||||
else{
|
||||
RaidGroup raidGroup = raidGroupService.getByRaidGroupId(raidGroupCalendarEvent.getRaidGroupId());
|
||||
if(raidGroup == null){
|
||||
errors.add("Raid Group ID is invalid");
|
||||
}
|
||||
}
|
||||
|
||||
//Check the event name
|
||||
if((raidGroupCalendarEvent.getEventName() == null) || (raidGroupCalendarEvent.getEventName().trim().isEmpty())){
|
||||
errors.add("Event name is required");
|
||||
}
|
||||
|
||||
//Check the event dates
|
||||
if(raidGroupCalendarEvent.getEventStartDate() == null){
|
||||
errors.add("Event start date is required");
|
||||
}
|
||||
else if(raidGroupCalendarEvent.getEventEndDate() == null){
|
||||
errors.add("Event end date is required");
|
||||
}
|
||||
else if(raidGroupCalendarEvent.getEventStartDate().compareTo(raidGroupCalendarEvent.getEventEndDate()) > 0){
|
||||
errors.add("Event start date must be before event end date");
|
||||
}
|
||||
|
||||
return errors;
|
||||
}
|
||||
|
||||
public List<String> validateExistingRaidGroupCalendarEvent(RaidGroupCalendarEvent raidGroupCalendarEvent){
|
||||
List<String> errors = new ArrayList<>();
|
||||
|
||||
//Check the ID
|
||||
if(raidGroupCalendarEvent.getRaidGroupCalendarEventId() == null){
|
||||
errors.add("Raid Group Calendar Event ID is required");
|
||||
return errors;
|
||||
}
|
||||
RaidGroupCalendarEvent existingRaidGroupCalendarEvent = rgceService.getByRaidGroupCalendarEventId(raidGroupCalendarEvent.getRaidGroupCalendarEventId());
|
||||
if(existingRaidGroupCalendarEvent == null){
|
||||
errors.add("Raid Group Calendar Event ID is invalid");
|
||||
}
|
||||
|
||||
//Check the Raid Group ID
|
||||
if(raidGroupCalendarEvent.getRaidGroupId() == null){
|
||||
errors.add("Raid Group ID is required");
|
||||
}
|
||||
else{
|
||||
RaidGroup raidGroup = raidGroupService.getByRaidGroupId(raidGroupCalendarEvent.getRaidGroupId());
|
||||
if(raidGroup == null){
|
||||
errors.add("Raid Group ID is invalid");
|
||||
}
|
||||
}
|
||||
|
||||
//Check the event name
|
||||
if((raidGroupCalendarEvent.getEventName() == null) || (raidGroupCalendarEvent.getEventName().trim().isEmpty())){
|
||||
errors.add("Event name is required");
|
||||
}
|
||||
|
||||
//Check the event dates
|
||||
if(raidGroupCalendarEvent.getEventStartDate() == null){
|
||||
errors.add("Event start date is required");
|
||||
}
|
||||
else if(raidGroupCalendarEvent.getEventEndDate() == null){
|
||||
errors.add("Event end date is required");
|
||||
}
|
||||
else if(raidGroupCalendarEvent.getEventStartDate().compareTo(raidGroupCalendarEvent.getEventEndDate()) > 0){
|
||||
errors.add("Event start date must be before event end date");
|
||||
}
|
||||
|
||||
return errors;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
package com.mattrixwv.raidbuilder.util.validation;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.mattrixwv.raidbuilder.entity.ClassGroup;
|
||||
import com.mattrixwv.raidbuilder.entity.RaidGroup;
|
||||
import com.mattrixwv.raidbuilder.service.ClassGroupService;
|
||||
import com.mattrixwv.raidbuilder.service.RaidGroupService;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
public class ClassGroupValidationUtil{
|
||||
private final ClassGroupService classGroupService;
|
||||
private final RaidGroupService raidGroupService;
|
||||
|
||||
|
||||
public List<String> validateNewClassGroup(ClassGroup classGroup){
|
||||
ArrayList<String> errors = new ArrayList<>();
|
||||
|
||||
//Class Group ID
|
||||
if(classGroup.getClassGroupId() != null){
|
||||
errors.add("Class group ID must be null");
|
||||
}
|
||||
|
||||
//Raid Group ID
|
||||
if(classGroup.getRaidGroupId() == null){
|
||||
errors.add("Raid group ID is required");
|
||||
}
|
||||
RaidGroup raidGroup = raidGroupService.getByRaidGroupId(classGroup.getRaidGroupId());
|
||||
if(raidGroup == null){
|
||||
errors.add("Raid group ID is invalid");
|
||||
}
|
||||
|
||||
//Class Group Name
|
||||
if((classGroup.getClassGroupName() == null) || (classGroup.getClassGroupName().trim().isEmpty())){
|
||||
errors.add("Class group name is required");
|
||||
}
|
||||
|
||||
return errors;
|
||||
}
|
||||
|
||||
public List<String> validateExistingClassGroup(ClassGroup classGroup){
|
||||
ArrayList<String> errors = new ArrayList<>();
|
||||
|
||||
//Class Group Id
|
||||
if(classGroup.getClassGroupId() == null){
|
||||
errors.add("Class group ID is required");
|
||||
return errors;
|
||||
}
|
||||
ClassGroup existingClassGroup = classGroupService.getClassGroup(classGroup.getClassGroupId(), classGroup.getRaidGroupId());
|
||||
if(existingClassGroup == null){
|
||||
errors.add("Class group ID is invalid");
|
||||
}
|
||||
|
||||
//Raid Group ID
|
||||
if(classGroup.getRaidGroupId() == null){
|
||||
errors.add("Raid group ID is required");
|
||||
}
|
||||
else{
|
||||
RaidGroup raidGroup = raidGroupService.getByRaidGroupId(classGroup.getRaidGroupId());
|
||||
if(raidGroup == null){
|
||||
errors.add("Raid group ID is invalid");
|
||||
}
|
||||
}
|
||||
|
||||
//Class Group Name
|
||||
if((classGroup.getClassGroupName() == null) || (classGroup.getClassGroupName().trim().isEmpty())){
|
||||
errors.add("Class group name is required");
|
||||
}
|
||||
|
||||
return errors;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
package com.mattrixwv.raidbuilder.util.validation;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.mattrixwv.raidbuilder.entity.Game;
|
||||
import com.mattrixwv.raidbuilder.entity.GameClass;
|
||||
import com.mattrixwv.raidbuilder.service.GameClassService;
|
||||
import com.mattrixwv.raidbuilder.service.GameService;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
public class GameClassValidationUtil{
|
||||
private final GameService gameService;
|
||||
private final GameClassService gameClassService;
|
||||
|
||||
|
||||
public List<String> validateNewGameClass(GameClass gameClass){
|
||||
ArrayList<String> errors = new ArrayList<>();
|
||||
|
||||
//Game Class ID
|
||||
if(gameClass.getGameClassId() != null){
|
||||
errors.add("Game class ID must be null");
|
||||
}
|
||||
|
||||
//Game ID
|
||||
if(gameClass.getGameId() == null){
|
||||
errors.add("Game ID is required");
|
||||
}
|
||||
Game game = gameService.getGameById(gameClass.getGameId());
|
||||
if(game == null){
|
||||
errors.add("Game ID is invalid");
|
||||
}
|
||||
|
||||
//Game Class Name
|
||||
if((gameClass.getGameClassName() == null) || (gameClass.getGameClassName().trim().isEmpty())){
|
||||
errors.add("Game class name is required");
|
||||
}
|
||||
|
||||
|
||||
return errors;
|
||||
}
|
||||
|
||||
public List<String> validateExistingGameClass(GameClass gameClass){
|
||||
ArrayList<String> errors = new ArrayList<>();
|
||||
|
||||
//Game Class ID
|
||||
if(gameClass.getGameClassId() == null){
|
||||
errors.add("Game class ID is required");
|
||||
return errors;
|
||||
}
|
||||
GameClass existingGameClass = gameClassService.getById(gameClass.getGameClassId());
|
||||
if(existingGameClass == null){
|
||||
errors.add("Game class ID is invalid");
|
||||
}
|
||||
|
||||
//Game ID
|
||||
if(gameClass.getGameId() == null){
|
||||
errors.add("Game ID is required");
|
||||
}
|
||||
else{
|
||||
Game game = gameService.getGameById(gameClass.getGameId());
|
||||
if(game == null){
|
||||
errors.add("Game ID is invalid");
|
||||
}
|
||||
}
|
||||
|
||||
//Game Class Name
|
||||
if((gameClass.getGameClassName() == null) || (gameClass.getGameClassName().trim().isEmpty())){
|
||||
errors.add("Game class name is required");
|
||||
}
|
||||
|
||||
|
||||
return errors;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
package com.mattrixwv.raidbuilder.util.validation;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.mattrixwv.raidbuilder.entity.Game;
|
||||
import com.mattrixwv.raidbuilder.service.GameService;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
public class GameValidationUtil{
|
||||
private final GameService gameService;
|
||||
|
||||
|
||||
public List<String> validateNewGame(Game game){
|
||||
ArrayList<String> errors = new ArrayList<>();
|
||||
|
||||
//Game ID
|
||||
if(game.getGameId() != null){
|
||||
errors.add("Game ID must be null");
|
||||
}
|
||||
|
||||
//Game Name
|
||||
if((game.getGameName() == null) || (game.getGameName().trim().isEmpty())){
|
||||
errors.add("Game name is required");
|
||||
}
|
||||
|
||||
return errors;
|
||||
}
|
||||
|
||||
public List<String> validateExistingGame(Game game){
|
||||
ArrayList<String> errors = new ArrayList<>();
|
||||
|
||||
//Game ID
|
||||
if(game.getGameId() == null){
|
||||
errors.add("Game ID is required");
|
||||
return errors;
|
||||
}
|
||||
|
||||
Game existingGame = gameService.getGameById(game.getGameId());
|
||||
if(existingGame == null){
|
||||
errors.add("Game ID is invalid");
|
||||
}
|
||||
|
||||
//Game Name
|
||||
if((game.getGameName() == null) || (game.getGameName().trim().isEmpty())){
|
||||
errors.add("Game name is required");
|
||||
}
|
||||
|
||||
return errors;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,132 @@
|
||||
package com.mattrixwv.raidbuilder.util.validation;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.mattrixwv.raidbuilder.entity.GameClass;
|
||||
import com.mattrixwv.raidbuilder.entity.Person;
|
||||
import com.mattrixwv.raidbuilder.entity.PersonCharacter;
|
||||
import com.mattrixwv.raidbuilder.service.GameClassService;
|
||||
import com.mattrixwv.raidbuilder.service.PersonCharacterService;
|
||||
import com.mattrixwv.raidbuilder.service.PersonService;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
public class PersonCharacterValidationUtil{
|
||||
private final GameClassService gameClassService;
|
||||
private final PersonService person;
|
||||
private final PersonCharacterService personCharacterService;
|
||||
|
||||
|
||||
public List<String> validateNewPersonCharacter(PersonCharacter personCharacter, UUID raidGroupId){
|
||||
ArrayList<String> errors = new ArrayList<>();
|
||||
|
||||
//Person Character ID
|
||||
if(personCharacter.getPersonCharacterId() != null){
|
||||
errors.add("Person character ID must be null");
|
||||
}
|
||||
|
||||
//Person ID
|
||||
if(personCharacter.getPersonId() == null){
|
||||
errors.add("Person ID is required");
|
||||
}
|
||||
else{
|
||||
Person existingPerson = person.getPerson(personCharacter.getPersonId(), raidGroupId);
|
||||
if(existingPerson == null){
|
||||
errors.add("Person ID is invalid");
|
||||
}
|
||||
}
|
||||
|
||||
//Game Class ID
|
||||
if(personCharacter.getGameClassId() == null){
|
||||
errors.add("Game class ID is required");
|
||||
}
|
||||
else{
|
||||
GameClass existingGameClass = gameClassService.getById(personCharacter.getGameClassId());
|
||||
if(existingGameClass == null){
|
||||
errors.add("Game class ID is invalid");
|
||||
}
|
||||
}
|
||||
|
||||
//Character Name
|
||||
if((personCharacter.getCharacterName() == null) || (personCharacter.getCharacterName().trim().isEmpty())){
|
||||
errors.add("Character name is required");
|
||||
}
|
||||
else{
|
||||
PersonCharacter existingPersonCharacter = personCharacterService.getByPersonIdAndCharacterName(personCharacter.getPersonId(), personCharacter.getCharacterName());
|
||||
if(existingPersonCharacter != null){
|
||||
errors.add("Character name already exists for this person");
|
||||
}
|
||||
}
|
||||
|
||||
//Rating
|
||||
if((personCharacter.getCharacterRating() < 0) || personCharacter.getCharacterRating() > 10){
|
||||
errors.add("Character rating must be between 0 and 10");
|
||||
}
|
||||
|
||||
|
||||
return errors;
|
||||
}
|
||||
|
||||
public List<String> validateExistingPersonCharacter(PersonCharacter personCharacter, UUID raidGroupId){
|
||||
ArrayList<String> errors = new ArrayList<>();
|
||||
|
||||
//Person Character ID
|
||||
if(personCharacter.getPersonCharacterId() == null){
|
||||
errors.add("Person character ID is required");
|
||||
return errors;
|
||||
}
|
||||
PersonCharacter existingPersonCharacter = personCharacterService.getById(personCharacter.getPersonCharacterId());
|
||||
if(existingPersonCharacter == null){
|
||||
errors.add("Person character ID is invalid");
|
||||
}
|
||||
|
||||
//Person ID
|
||||
if(personCharacter.getPersonId() == null){
|
||||
errors.add("Person ID is required");
|
||||
}
|
||||
else{
|
||||
Person existingPerson = person.getPerson(personCharacter.getPersonId(), raidGroupId);
|
||||
if(existingPerson == null){
|
||||
errors.add("Person ID is invalid");
|
||||
}
|
||||
}
|
||||
|
||||
//Game Class ID
|
||||
if(personCharacter.getGameClassId() == null){
|
||||
errors.add("Game class ID is required");
|
||||
}
|
||||
else{
|
||||
GameClass existingGameClass = gameClassService.getById(personCharacter.getGameClassId());
|
||||
if(existingGameClass == null){
|
||||
errors.add("Game class ID is invalid");
|
||||
}
|
||||
}
|
||||
|
||||
//Character Name
|
||||
if((personCharacter.getCharacterName() == null) || (personCharacter.getCharacterName().trim().isEmpty())){
|
||||
errors.add("Character name is required");
|
||||
}
|
||||
else{
|
||||
existingPersonCharacter = personCharacterService.getByPersonIdAndCharacterName(personCharacter.getPersonId(), personCharacter.getCharacterName());
|
||||
if(existingPersonCharacter != null){
|
||||
errors.add("Character name already exists for this person");
|
||||
}
|
||||
}
|
||||
|
||||
//Rating
|
||||
if((personCharacter.getCharacterRating() < 0) || personCharacter.getCharacterRating() > 10){
|
||||
errors.add("Character rating must be between 0 and 10");
|
||||
}
|
||||
|
||||
|
||||
return errors;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
package com.mattrixwv.raidbuilder.util.validation;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.mattrixwv.raidbuilder.entity.Person;
|
||||
import com.mattrixwv.raidbuilder.entity.RaidGroup;
|
||||
import com.mattrixwv.raidbuilder.service.PersonService;
|
||||
import com.mattrixwv.raidbuilder.service.RaidGroupService;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
public class PersonValidationUtil{
|
||||
private final PersonService personService;
|
||||
private final RaidGroupService raidGroupService;
|
||||
|
||||
|
||||
public List<String> validateNewPerson(Person person){
|
||||
ArrayList<String> errors = new ArrayList<>();
|
||||
|
||||
//Person ID
|
||||
if(person.getPersonId() != null){
|
||||
errors.add("Person ID must be null");
|
||||
}
|
||||
|
||||
//Raid Group ID
|
||||
if(person.getRaidGroupId() == null){
|
||||
errors.add("Raid Group ID is required");
|
||||
}
|
||||
else{
|
||||
RaidGroup raidGroup = raidGroupService.getByRaidGroupId(person.getRaidGroupId());
|
||||
if(raidGroup == null){
|
||||
errors.add("Raid Group ID is invalid");
|
||||
}
|
||||
}
|
||||
|
||||
//Person Name
|
||||
if((person.getPersonName() == null) || (person.getPersonName().trim().isEmpty())){
|
||||
errors.add("Person name is required");
|
||||
}
|
||||
Person existingPerson = personService.getPersonByName(person.getPersonName(), person.getRaidGroupId());
|
||||
if(existingPerson != null){
|
||||
errors.add("Person name already exists");
|
||||
}
|
||||
|
||||
|
||||
return errors;
|
||||
}
|
||||
|
||||
public List<String> validateExistingPerson(Person person){
|
||||
ArrayList<String> errors = new ArrayList<>();
|
||||
|
||||
//Person ID
|
||||
if(person.getPersonId() == null){
|
||||
errors.add("Person ID is required");
|
||||
return errors;
|
||||
}
|
||||
Person existingPerson = personService.getPerson(person.getPersonId(), person.getRaidGroupId());
|
||||
if(existingPerson == null){
|
||||
errors.add("Person ID is invalid");
|
||||
}
|
||||
|
||||
//Raid Group ID
|
||||
if(person.getRaidGroupId() == null){
|
||||
errors.add("Raid Group ID is required");
|
||||
}
|
||||
else{
|
||||
RaidGroup raidGroup = raidGroupService.getByRaidGroupId(person.getRaidGroupId());
|
||||
if(raidGroup == null){
|
||||
errors.add("Raid Group ID is invalid");
|
||||
}
|
||||
}
|
||||
|
||||
//Person Name
|
||||
if((person.getPersonName() == null) || (person.getPersonName().trim().isEmpty())){
|
||||
errors.add("Person name is required");
|
||||
}
|
||||
existingPerson = personService.getPersonByName(person.getPersonName(), person.getRaidGroupId());
|
||||
if((existingPerson != null) && (!existingPerson.getPersonId().equals(person.getPersonId()))){
|
||||
errors.add("Person name already exists");
|
||||
}
|
||||
|
||||
|
||||
return errors;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
package com.mattrixwv.raidbuilder.util.validation;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.mattrixwv.raidbuilder.entity.RaidGroup;
|
||||
import com.mattrixwv.raidbuilder.entity.RaidGroupRequest;
|
||||
import com.mattrixwv.raidbuilder.service.AccountService;
|
||||
import com.mattrixwv.raidbuilder.service.RaidGroupRequestService;
|
||||
import com.mattrixwv.raidbuilder.service.RaidGroupService;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
public class RaidGroupRequestValidationUtil{
|
||||
private final AccountService accountService;
|
||||
private final RaidGroupService raidGroupService;
|
||||
private final RaidGroupRequestService raidGroupRequestService;
|
||||
|
||||
|
||||
public List<String> validateNewRaidGroupRequest(RaidGroupRequest raidGroupRequest){
|
||||
ArrayList<String> errors = new ArrayList<>();
|
||||
|
||||
|
||||
//Raid Group Request ID
|
||||
if(raidGroupRequest.getRaidGroupRequestId() != null){
|
||||
errors.add("Raid Group Request ID should not exist");
|
||||
}
|
||||
|
||||
//Raid Group ID
|
||||
if(raidGroupRequest.getRaidGroupId() == null){
|
||||
errors.add("Raid Group ID is required");
|
||||
}
|
||||
else{
|
||||
RaidGroup existingRaidGroup = raidGroupService.getByRaidGroupId(raidGroupRequest.getRaidGroupId());
|
||||
if(existingRaidGroup == null){
|
||||
errors.add("Raid Group ID does not exist");
|
||||
}
|
||||
}
|
||||
|
||||
//Account ID
|
||||
if(raidGroupRequest.getAccountId() == null){
|
||||
errors.add("Account ID is required");
|
||||
}
|
||||
else{
|
||||
if(accountService.getByAccountId(raidGroupRequest.getAccountId()) == null){
|
||||
errors.add("Account ID does not exist");
|
||||
}
|
||||
}
|
||||
|
||||
return errors;
|
||||
}
|
||||
|
||||
public List<String> validateExistingRaidGroupRequest(RaidGroupRequest raidGroupRequest){
|
||||
ArrayList<String> errors = new ArrayList<>();
|
||||
|
||||
|
||||
//Raid Group Request ID
|
||||
if(raidGroupRequest.getRaidGroupRequestId() == null){
|
||||
errors.add("Raid Group Request ID is required");
|
||||
return errors;
|
||||
}
|
||||
RaidGroupRequest existingRaidGroupRequest = raidGroupRequestService.getById(raidGroupRequest.getRaidGroupRequestId());
|
||||
if(existingRaidGroupRequest == null){
|
||||
errors.add("Raid Group Request ID does not exist");
|
||||
}
|
||||
|
||||
//Raid Group ID
|
||||
if(raidGroupRequest.getRaidGroupId() == null){
|
||||
errors.add("Raid Group ID is required");
|
||||
}
|
||||
else{
|
||||
RaidGroup existingRaidGroup = raidGroupService.getByRaidGroupId(raidGroupRequest.getRaidGroupId());
|
||||
if(existingRaidGroup == null){
|
||||
errors.add("Raid Group ID does not exist");
|
||||
}
|
||||
}
|
||||
|
||||
//Account ID
|
||||
if(raidGroupRequest.getAccountId() == null){
|
||||
errors.add("Account ID is required");
|
||||
}
|
||||
else{
|
||||
if(accountService.getByAccountId(raidGroupRequest.getAccountId()) == null){
|
||||
errors.add("Account ID does not exist");
|
||||
}
|
||||
}
|
||||
|
||||
return errors;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
package com.mattrixwv.raidbuilder.util.validation;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.mattrixwv.raidbuilder.entity.Game;
|
||||
import com.mattrixwv.raidbuilder.entity.RaidGroup;
|
||||
import com.mattrixwv.raidbuilder.service.GameService;
|
||||
import com.mattrixwv.raidbuilder.service.RaidGroupService;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
public class RaidGroupValidationUtil{
|
||||
private final GameService gameService;
|
||||
private final RaidGroupService raidGroupService;
|
||||
|
||||
|
||||
public List<String> validateNewRaidGroup(RaidGroup raidGroup){
|
||||
ArrayList<String> errors = new ArrayList<>();
|
||||
|
||||
|
||||
//Raid Group ID
|
||||
if(raidGroup.getRaidGroupId() != null){
|
||||
errors.add("Raid Group ID must be null");
|
||||
}
|
||||
|
||||
//Game ID
|
||||
if(raidGroup.getGameId() == null){
|
||||
errors.add("Game ID is required");
|
||||
}
|
||||
else{
|
||||
Game existingGame = gameService.getGameById(raidGroup.getGameId());
|
||||
if(existingGame == null){
|
||||
errors.add("Game ID is invalid");
|
||||
}
|
||||
}
|
||||
|
||||
//Raid Group Name
|
||||
if((raidGroup.getRaidGroupName() == null) || (raidGroup.getRaidGroupName().trim().isEmpty())){
|
||||
errors.add("Raid group name is required");
|
||||
}
|
||||
RaidGroup existingRaidGroup = raidGroupService.getByRaidGroupName(raidGroup.getRaidGroupName(), raidGroup.getGameId());
|
||||
if(existingRaidGroup != null){
|
||||
errors.add("Raid group name already exists");
|
||||
}
|
||||
|
||||
return errors;
|
||||
}
|
||||
|
||||
public List<String> validateExistingRaidGroup(RaidGroup raidGroup){
|
||||
ArrayList<String> errors = new ArrayList<>();
|
||||
|
||||
//Raid Group ID
|
||||
if(raidGroup.getRaidGroupId() == null){
|
||||
errors.add("Raid Group ID is required");
|
||||
return errors;
|
||||
}
|
||||
RaidGroup existingRaidGroup = raidGroupService.getByRaidGroupId(raidGroup.getRaidGroupId());
|
||||
if(existingRaidGroup == null){
|
||||
errors.add("Raid Group ID is invalid");
|
||||
}
|
||||
|
||||
//Game ID
|
||||
if(raidGroup.getGameId() == null){
|
||||
errors.add("Game ID is required");
|
||||
}
|
||||
else{
|
||||
Game existingGame = gameService.getGameById(raidGroup.getGameId());
|
||||
if(existingGame == null){
|
||||
errors.add("Game ID is invalid");
|
||||
}
|
||||
}
|
||||
|
||||
//Raid Group Name
|
||||
if((raidGroup.getRaidGroupName() == null) || (raidGroup.getRaidGroupName().trim().isEmpty())){
|
||||
errors.add("Raid group name is required");
|
||||
}
|
||||
existingRaidGroup = raidGroupService.getByRaidGroupName(raidGroup.getRaidGroupName(), raidGroup.getGameId());
|
||||
if((existingRaidGroup != null) && (!existingRaidGroup.getRaidGroupId().equals(raidGroup.getRaidGroupId()))){
|
||||
errors.add("Raid group name already exists");
|
||||
}
|
||||
|
||||
return errors;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
package com.mattrixwv.raidbuilder.util.validation;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.mattrixwv.raidbuilder.entity.RaidInstance;
|
||||
import com.mattrixwv.raidbuilder.service.RaidGroupService;
|
||||
import com.mattrixwv.raidbuilder.service.RaidInstanceService;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
public class RaidInstanceValidationUtil{
|
||||
private final RaidGroupService raidGroupService;
|
||||
private final RaidInstanceService raidInstanceService;
|
||||
|
||||
|
||||
public List<String> validateNewRaidInstance(RaidInstance raidInstance){
|
||||
ArrayList<String> errors = new ArrayList<>();
|
||||
|
||||
|
||||
//Raid Instance ID
|
||||
if(raidInstance.getRaidInstanceId() != null){
|
||||
errors.add("Raid Instance ID should not be provided");
|
||||
}
|
||||
|
||||
//Raid Group ID
|
||||
if(raidInstance.getRaidGroupId() == null){
|
||||
errors.add("Raid Group ID is required");
|
||||
}
|
||||
else{
|
||||
if(raidGroupService.getByRaidGroupId(raidInstance.getRaidGroupId()) == null){
|
||||
errors.add("Raid Group ID is invalid");
|
||||
}
|
||||
}
|
||||
|
||||
//Dates
|
||||
if(raidInstance.getRaidStartDate() == null){
|
||||
errors.add("Start date is required");
|
||||
}
|
||||
if(raidInstance.getRaidEndDate() == null){
|
||||
errors.add("End date is required");
|
||||
}
|
||||
if((raidInstance.getRaidStartDate() != null) && (raidInstance.getRaidEndDate() != null) && (raidInstance.getRaidStartDate().compareTo(raidInstance.getRaidEndDate()) > 0)){
|
||||
errors.add("Start date must be before end date");
|
||||
}
|
||||
|
||||
return errors;
|
||||
}
|
||||
|
||||
public List<String> validateExistingRaidInstance(RaidInstance raidInstance){
|
||||
ArrayList<String> errors = new ArrayList<>();
|
||||
|
||||
|
||||
//Raid Instance ID
|
||||
if(raidInstance.getRaidInstanceId() == null){
|
||||
errors.add("Raid Instance ID should not be provided");
|
||||
return errors;
|
||||
}
|
||||
RaidInstance existingRaidInstance = raidInstanceService.findById(raidInstance.getRaidInstanceId());
|
||||
if(existingRaidInstance != null){
|
||||
errors.add("Raid Instance ID is invalid");
|
||||
}
|
||||
|
||||
//Raid Group ID
|
||||
if(raidInstance.getRaidGroupId() == null){
|
||||
errors.add("Raid Group ID is required");
|
||||
}
|
||||
else{
|
||||
if(raidGroupService.getByRaidGroupId(raidInstance.getRaidGroupId()) == null){
|
||||
errors.add("Raid Group ID is invalid");
|
||||
}
|
||||
}
|
||||
|
||||
//Dates
|
||||
if(raidInstance.getRaidStartDate() == null){
|
||||
errors.add("Start date is required");
|
||||
}
|
||||
if(raidInstance.getRaidEndDate() == null){
|
||||
errors.add("End date is required");
|
||||
}
|
||||
if((raidInstance.getRaidStartDate() != null) && (raidInstance.getRaidEndDate() != null) && (raidInstance.getRaidStartDate().compareTo(raidInstance.getRaidEndDate()) > 0)){
|
||||
errors.add("Start date must be before end date");
|
||||
}
|
||||
|
||||
return errors;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,111 @@
|
||||
package com.mattrixwv.raidbuilder.util.validation;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.mattrixwv.raidbuilder.entity.RaidLayout;
|
||||
import com.mattrixwv.raidbuilder.service.RaidGroupService;
|
||||
import com.mattrixwv.raidbuilder.service.RaidLayoutService;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
public class RaidLayoutValidationUtil{
|
||||
private final RaidGroupService raidGroupService;
|
||||
private final RaidLayoutService raidLayoutService;
|
||||
|
||||
|
||||
public List<String> validateNewRaidLayout(RaidLayout raidLayout){
|
||||
ArrayList<String> errors = new ArrayList<>();
|
||||
|
||||
|
||||
//Raid Layout ID
|
||||
if(raidLayout.getRaidGroupId() != null){
|
||||
errors.add("Raid Group ID must be null");
|
||||
}
|
||||
|
||||
//Raid Group ID
|
||||
if(raidLayout.getRaidGroupId() == null){
|
||||
errors.add("Raid Group ID is required");
|
||||
}
|
||||
else{
|
||||
if(raidGroupService.getByRaidGroupId(raidLayout.getRaidGroupId()) == null){
|
||||
errors.add("Raid Group ID is invalid");
|
||||
}
|
||||
}
|
||||
|
||||
//Raid Layout Name
|
||||
if((raidLayout.getRaidLayoutName() == null) || (raidLayout.getRaidLayoutName().trim().length() == 0)){
|
||||
errors.add("Raid Layout Name is required");
|
||||
}
|
||||
else{
|
||||
RaidLayout existingRaidLayout = raidLayoutService.getRaidLayoutByName(raidLayout.getRaidLayoutName(), raidLayout.getRaidGroupId());
|
||||
if(existingRaidLayout != null){
|
||||
errors.add("Raid Layout Name already exists");
|
||||
}
|
||||
}
|
||||
|
||||
//Raid Size
|
||||
if(raidLayout.getRaidSize() <= 0){
|
||||
errors.add("Raid Size must be greater than 0");
|
||||
}
|
||||
else if(raidLayout.getRaidSize() > 100){
|
||||
errors.add("Raid Size must be less than or equal to 100");
|
||||
}
|
||||
|
||||
|
||||
return errors;
|
||||
}
|
||||
|
||||
public List<String> validateExistingRaidLayout(RaidLayout raidLayout){
|
||||
ArrayList<String> errors = new ArrayList<>();
|
||||
|
||||
|
||||
//Raid Layout ID
|
||||
if(raidLayout.getRaidLayoutId() == null){
|
||||
errors.add("Raid Layout ID is required");
|
||||
return errors;
|
||||
}
|
||||
RaidLayout existingRaidLayout = raidLayoutService.getRaidLayout(raidLayout.getRaidLayoutId(), raidLayout.getRaidGroupId());
|
||||
if(existingRaidLayout == null){
|
||||
errors.add("Raid Layout ID is invalid");
|
||||
}
|
||||
|
||||
//Raid Group ID
|
||||
if(raidLayout.getRaidGroupId() == null){
|
||||
errors.add("Raid Group ID is required");
|
||||
}
|
||||
else{
|
||||
if(raidGroupService.getByRaidGroupId(raidLayout.getRaidGroupId()) == null){
|
||||
errors.add("Raid Group ID is invalid");
|
||||
}
|
||||
}
|
||||
|
||||
//Raid Layout Name
|
||||
if((raidLayout.getRaidLayoutName() == null) || (raidLayout.getRaidLayoutName().trim().length() == 0)){
|
||||
errors.add("Raid Layout Name is required");
|
||||
}
|
||||
else{
|
||||
existingRaidLayout = raidLayoutService.getRaidLayoutByName(raidLayout.getRaidLayoutName(), raidLayout.getRaidGroupId());
|
||||
if(existingRaidLayout != null){
|
||||
errors.add("Raid Layout Name already exists");
|
||||
}
|
||||
}
|
||||
|
||||
//Raid Size
|
||||
if(raidLayout.getRaidSize() <= 0){
|
||||
errors.add("Raid Size must be greater than 0");
|
||||
}
|
||||
else if(raidLayout.getRaidSize() > 100){
|
||||
errors.add("Raid Size must be less than or equal to 100");
|
||||
}
|
||||
|
||||
|
||||
return errors;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user