package asa.controller;

import asa.bean.Attendance;
import asa.service.AttendanceService;
import org.springframework.web.bind.annotation.*;
import org.springframework.http.MediaType;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.*;

@RestController
@RequestMapping("/attendance")
public class AttendanceController {

	@Autowired
	private AttendanceService attendanceService;
	
	
    @RequestMapping(method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE)
    public @ResponseBody Map<String,String> add(@RequestBody Attendance attendance){
        
		  Map<String,String> map=new HashMap<>();
		  if(attendanceService.add(attendance)){
      			map.put("result","success");
		  }
	    	else{
			map.put("result","failed");
		}
		  return map;
    }
	
	
	@RequestMapping(value="/by",method = RequestMethod.GET)
	public @ResponseBody Map<String,Object> viewByGroupAndDate(@RequestParam("group") String group,
								   @RequestParam("date") String date){
		Map<String,Object> map=new HashMap<>();
		System.out.println("Inside AttendanceController");
		List<Attendance> list= appointmentService.get(group,date);
		System.out.println("Length :"+list.size());
		
		if(list.size()!=0){
			map.put("result",new String("success"));
			map.put("list",list);
		}
		else{
			map.put("result",new String("failed"));
		}
			
		return map;
	}
	

}

@@ -1102,13 +1102,8 @@
 ;%0A%09%09
-List%3C
 Atte
@@ -1112,14 +1112,20 @@
 ance
-%3E list
+ attendance 
 = ap
@@ -1164,74 +1164,33 @@
 ;%0A%09%09
-System.out.println(%22Length :%22+list.size());%0A%09%09%0A%09%09if(list.size()!=0
+%0A%09%09%0A%09%09if(attendance!=null
 )%7B%0A%09
@@ -1248,18 +1248,26 @@
 ut(%22
-list%22,list
+object%22,attendance
 );%0A%09

list converted to object