Commit 779485ff authored by Khalid Ali's avatar Khalid Ali
Browse files

Add service code

parent 991c0c74
......@@ -3,6 +3,9 @@ package com.gmu.bookshare.persistence;
import com.gmu.bookshare.entity.ShareUser;
import org.springframework.data.repository.CrudRepository;
import java.util.List;
public interface ShareUserRepository extends CrudRepository<ShareUser, Long> {
List<ShareUser> findByEmail(String s);
}
package com.gmu.bookshare.service;
import com.gmu.bookshare.entity.ShareUser;
import com.gmu.bookshare.persistence.ShareUserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class ShareUserService {
......@@ -13,4 +16,14 @@ public class ShareUserService {
public ShareUserService(ShareUserRepository shareUserRepository) {
this.shareUserRepository = shareUserRepository;
}
public ShareUser addShareUser(ShareUser user) {
List<ShareUser> userList = shareUserRepository.findByEmail(user.getEmail());
if (userList.size() > 0) {
return userList.get(0);
} else {
shareUserRepository.save(user);
return user;
}
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment