package com.buseni.ecoledimanche.core.api;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import com.buseni.ecoledimanche.account.domain.UserAccount;
import com.buseni.ecoledimanche.account.service.UserAccountService;
import com.buseni.ecoledimanche.core.domain.Eleve;
import com.buseni.ecoledimanche.core.domain.Groupe;
import com.buseni.ecoledimanche.core.domain.Lecon;
import com.buseni.ecoledimanche.core.domain.ThemeLecon;
import com.buseni.ecoledimanche.core.service.EleveService;
import com.buseni.ecoledimanche.core.service.GroupeService;
import com.buseni.ecoledimanche.core.service.LeconService;
import com.buseni.ecoledimanche.core.service.ThemeLeconService;

@RestController
public class ApiRestController {
	
	@Autowired
	private ThemeLeconService themeLeconService;
	
	
	@Autowired
	private UserAccountService  userAccountService;
	
	@Autowired
	private EleveService eleveService;
	
	
	@Autowired
	private GroupeService groupeService;
	

@Autowired
private LeconService leconService;
	
	@GetMapping("/api/themes")
	public List<ThemeLecon>  getThemes(Model model,  Pageable page){

		Page<ThemeLecon> pageThemes = themeLeconService.findAll(page);
		return pageThemes.getContent();
		
		
	}
	
	@GetMapping("/api/groupes")
	public List<Groupe>  getGroupes(Model model,  Pageable page){

		Page<Groupe> pageThemes = groupeService.findAll(page);
		return pageThemes.getContent();
		
		
	}
	
	
	@GetMapping("/api/moniteurs")
	public List<UserAccount>  getMoniteurs(Model model,  Pageable page){

		Page<UserAccount> pageThemes = userAccountService.findAll(page);
		return pageThemes.getContent();
		
		
	}
	
	@GetMapping("/api/lecons")
	public List<Lecon>  getLecons(Model model,  Pageable page){

		Page<Lecon> pageThemes = leconService.findAll(page);
		return pageThemes.getContent();
		
		
	}
	
	@GetMapping("/api/eleves")
	public List<Eleve>  getEleves(Model model,  Pageable page){

		Page<Eleve> pageThemes = eleveService.findAll(page);
		return pageThemes.getContent();
		
		
	}
	
	

}

@@ -314,16 +314,322 @@
 apping;%0A
+import org.springframework.web.bind.annotation.PathVariable;%0Aimport org.springframework.web.bind.annotation.PostMapping;%0Aimport org.springframework.web.bind.annotation.RequestBody;%0Aimport org.springframework.web.bind.annotation.RequestMapping;%0Aimport org.springframework.web.bind.annotation.RequestMethod;%0A
 import o
@@ -683,16 +683,16 @@
 roller;%0A
-
 %0Aimport 
@@ -1263,16 +1263,77 @@
 Service;
+%0Aimport com.buseni.ecoledimanche.exception.BusinessException;
 %0A%0A@RestC
@@ -1844,39 +1844,1009 @@
 etContent();%0A%09%09%0A
-
 %09%09%0A%09%7D%0A%09
+%0A%0A%09@GetMapping(value = %22/api/getTheme/%7BthemeId%7D%22)%0A%09public ThemeLecon getTheme(@PathVariable(%22themeId%22) Integer themeId) %7B%0A%09%09return themeLeconService.findById(themeId);%0A%09%7D%0A %0A%09@PostMapping(value = %22/api/createTheme%22)%0A%09public ThemeLecon createTheme(@RequestBody ThemeLecon theme) %7B%0A%09%09ThemeLecon newTheme = null;%0A%09%09try %7B%0A%09%09%09newTheme=  themeLeconService.addOrUpdate(theme);%0A%09%09%7D catch (BusinessException e) %7B%0A%09%09%09// TODO Auto-generated catch block%0A%09%09%09e.printStackTrace();%0A%09%09%7D%0A%09%09return newTheme;%0A%09%7D%0A %0A%09@PostMapping(value = %22/api/updateTheme%22)%0A%09public ThemeLecon updateTheme(@RequestBody ThemeLecon theme) %7B%0A%09%09ThemeLecon newTheme = null;%0A%09%09try %7B%0A%09%09%09newTheme =  themeLeconService.update(theme);%0A%09%09%7D catch (BusinessException e) %7B%0A%09%09%09// TODO Auto-generated catch block%0A%09%09%09e.printStackTrace();%0A%09%09%7D%0A%09%09return newTheme;%0A%09%7D%0A%09%0A%09@GetMapping(value = %22/api/deleteTheme/%7BthemeId%7D%22)%0A%09public void deleteTheme(@PathVariable(%22themeId%22) Integer themeId) %7B%0A%09%09themeLeconService.delete(themeId);%0A%09%7D%0A%09
 %0A%09@GetMapping(%22/

Add CRUD operations on theme object