@Override public void createClub(ClubData clubData) { Club existingClub = clubRepository.findByAcronym(clubData.getAcronym()); if (existingClub != null) { throw new ElementAlreadyExistsException("There is already a club with this acronym"); } clubRepository.save(convertClub(clubData)); }
private Club findClub(String acronym) { Club club = clubRepository.findByAcronym(acronym); if (club == null) { throw new ElementNotFoundException( "The club with the acronym " + acronym + " could not be found"); } return club; }
@Override public void updateClub(ClubData clubData) { Club club = findClub(clubData.getAcronym()); club.setName(clubData.getName()); Coach coach = club.getCoach(); coach.setName(clubData.getCoach().getName()); coach.setMail(clubData.getCoach().getEmail()); coach.setTel(clubData.getCoach().getPhoneNumber()); clubRepository.save(club); }