133 lines
4.0 KiB
Java
133 lines
4.0 KiB
Java
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;
|
|
}
|
|
}
|