package org.ros.chatto.repository;

import java.util.List;

import org.ros.chatto.model.UserSession;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

@Repository
public interface UserSessionRepository
		extends JpaRepository<UserSession, Long> {
	@Query("select us from UserSession us join fetch us.user where us.user.userName = ?1 ")
	public UserSession findByUserName(String userName);

	@Query("select us from UserSession us join fetch us.user")
	public List<UserSession> findAllUserSessions();

	@Query("select count(us) from UserSession us where us.online=true")
	public Long totalOnlineUsers();
}
