コード例 #1
0
  @Override
  public Contact create(Contact contact) throws ContactServiceException {

    Contact contactBD = contactRepository.findOneByEmail(contact.getEmail());

    if (contactBD == null) {
      return contactRepository.saveAndFlush(contact);
    }

    throw new ContactServiceException();
  }
コード例 #2
0
  @Override
  public Contact delete(Integer id) throws ContactServiceException {

    Contact contactBD = contactRepository.findOne(id);

    if (contactBD == null) {
      throw new ContactServiceException();
    }

    contactRepository.delete(contactBD);
    return contactBD;
  }
コード例 #3
0
  @Override
  public Contact update(Integer id, Contact contact) throws ContactServiceException {

    Contact contactBD = contactRepository.findOne(id);

    if (contactBD == null) {
      throw new ContactServiceException();
    }

    contactBD.setName(contact.getName());
    contactBD.setEmail(contact.getEmail());
    return contactRepository.saveAndFlush(contactBD);
  }
コード例 #4
0
  @Override
  public Contact view(Integer id) throws ContactServiceException {

    Contact contact = contactRepository.findOne(id);

    if (contact == null) {
      throw new ContactServiceException();
    }

    return contact;
  }
コード例 #5
0
 @Override
 public List<Contact> list() {
   return contactRepository.findAll();
 }