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("date") String date,
								   @RequestParam("group") String group){
		Map<String,Object> map=new HashMap<>();
		System.out.println("Inside AttendanceController");
		List<Attendance> list= appointmentService.get(date,group);
		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;
	}
	

}

@@ -932,20 +932,21 @@
 tParam(%22
-date
+group
 %22) Strin
@@ -947,20 +947,21 @@
  String 
-date
+group
 ,%0A%09%09%09%09%09%09
@@ -972,37 +972,36 @@
  @RequestParam(%22
-group
+date
 %22) String group)
@@ -994,21 +994,20 @@
  String 
-group
+date
 )%7B%0A%09%09Map
@@ -1148,18 +1148,18 @@
 get(
-date,
 group
+,date
 );%0A%09

order changed of params