fi.evolver.ai.vaadin.UserProfileRepository Maven / Gradle / Ivy
package fi.evolver.ai.vaadin;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;
import fi.evolver.ai.vaadin.entity.UserProfile;
import fi.evolver.ai.vaadin.util.AuthUtils;
@Repository
@Transactional
public interface UserProfileRepository extends JpaRepository {
public UserProfile findUserProfileByUsername(String username);
default UserProfile findOrCreateUserProfile() {
String username = AuthUtils.getEmail();
if (username == null)
return null;
UserProfile profile = findUserProfileByUsername(username);
if (profile != null)
return profile;
profile = new UserProfile(username);
save(profile);
return profile;
}
}