<commit_before>package speedtyper.api.controller;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import speedtyper.api.viewmodel.RoomViewModel;
import speedtyper.model.RoomModel;
import speedtyper.service.RoomService;

@Controller
@RequestMapping(value="/rooms")
public class RoomController {
	private static final String SESSION_KEY_PARAM_NAME = "sessionkey";
	
	@Autowired
	RoomService roomService;
	
	@RequestMapping(value="/", method=RequestMethod.GET)
	@ResponseBody
	public List<RoomViewModel> all(@RequestHeader Map<String, String> headers) {
		String sessionKey = headers.get(SESSION_KEY_PARAM_NAME);
		List<RoomViewModel> rooms = null;
		
		if (true) {
			List<RoomModel> roomsModel = roomService.getAvaibleRooms();
			rooms = listRoomModelToViewModel(roomsModel);
		} else {
			throw new IllegalArgumentException("User is not authenticated!");
		}
		
		return rooms;
	}
	
	private List<RoomViewModel> listRoomModelToViewModel(List<RoomModel> rooms) {
		List<RoomViewModel> roomsViewModel = new ArrayList<RoomViewModel>();
		for (RoomModel roomModel : rooms) {
			RoomViewModel roomVM = new RoomViewModel();
			roomVM.setId(roomModel.getId());
			roomVM.setParticipants(roomModel.getParticipantsCount());
			roomVM.setMaxParticipants(roomModel.getMaxParticipants());
			roomVM.setStatus(roomModel.getStatus());
			roomVM.setText(roomModel.getText().getText());
			roomsViewModel.add(roomVM);
		}
		
		return roomsViewModel;
	}

}
<commit_msg>fixed get avaible rooms controller<commit_after>package speedtyper.api.controller;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import speedtyper.api.viewmodel.RoomViewModel;
import speedtyper.model.RoomModel;
import speedtyper.model.UserModel;
import speedtyper.service.RoomService;
import speedtyper.service.UserService;
import speedtyper.service.impl.UserServiceImpl;

@Controller
@RequestMapping(value="/rooms")
public class RoomController {
	private static final String SESSION_KEY_PARAM_NAME = "sessionkey";
	
	@Autowired
	RoomService roomService;
	@Autowired
	private UserService userService;
	
	@RequestMapping(value="/", method=RequestMethod.GET)
	@ResponseBody
	public List<RoomViewModel> all(@RequestHeader Map<String, String> headers) {
		String sessionKey = headers.get(SESSION_KEY_PARAM_NAME);
		List<RoomViewModel> rooms = null;
		
		if (this.isAuthenticated(sessionKey)) {
			List<RoomModel> roomsModel = roomService.getAvaibleRooms();
			rooms = listRoomModelToViewModel(roomsModel);
		} else {
			throw new IllegalArgumentException("User is not authenticated!");
		}
		
		return rooms;
	}
	
	private List<RoomViewModel> listRoomModelToViewModel(List<RoomModel> rooms) {
		List<RoomViewModel> roomsViewModel = new ArrayList<RoomViewModel>();
		for (RoomModel roomModel : rooms) {
			RoomViewModel roomVM = new RoomViewModel();
			roomVM.setId(roomModel.getId());
			roomVM.setCreator(roomModel.getCreator().getUsername());
			roomVM.setParticipants(roomModel.getParticipantsCount());
			roomVM.setMaxParticipants(roomModel.getMaxParticipants());
			roomVM.setStatus(roomModel.getStatus());
			roomVM.setText(roomModel.getText().getText());
			roomsViewModel.add(roomVM);
		}
		
		return roomsViewModel;
	}
	
	private boolean isAuthenticated(String sessionKey) {
		UserModel user = userService.getUserBySessionKey(sessionKey);
		
		if (user == null) {
			return false;
		}
		
		return true;
	}

}

{'fraction_non_alphanumeric': 0.10516160154365653, 'fraction_numerical': 0.0, 'mean_word_length': 6.125429553264605, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '408850', 'n_tokens_mistral': 1317, 'n_tokens_neox': 1178, 'n_words': 219}