package com.nearsoft.myflights.controllers;

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.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.nearsoft.myflights.model.Airport;
import com.nearsoft.myflights.service.AirportService;

@Controller
@RequestMapping("/airports")
public class AirportController {

	@Autowired
	AirportService airportService;
	
	public AirportController() {
		// TODO Auto-generated constructor stub
	}
//	public AirportController(AirportService airportService) {
//		this.airportService = airportService;
//	}
	
	@RequestMapping("index")
	@ResponseBody
	public Airport hi() {
		Airport airport = new Airport();
		airport.setId(1);
		return airport;
	}
	
	@RequestMapping(value = {"code"}, params = {"c"}, method = {RequestMethod.GET})
	@ResponseBody
	public Airport airportByCode(@RequestParam(value ="c")  String name) {
		return airportService.getAirportByCode(name);
	}
	
	@RequestMapping(value = {"word"}, params = {"w"}, method = {RequestMethod.GET})
	@ResponseBody
	public Map<String, List<Airport>> listAirportsByKeyword(@RequestParam(value ="w")  String word) {
		if(word.equalsIgnoreCase("")) {
			return null;
		} else {
			Map<String, List<Airport>> airports = airportService.getAirportsByKeyword(word);
			return airports;
		}
	}
	
}

@@ -197,16 +197,77 @@
 roller;%0A
+import org.springframework.web.bind.annotation.PathVariable;%0A
 import o
@@ -636,24 +636,16 @@
 pping(%22/
-airports
 %22)%0Apubli
@@ -926,13 +926,17 @@
 ng(%22
-index
+airportHi
 %22)%0A%09
@@ -1302,28 +1302,23 @@
 = %7B%22
-word%22%7D, params = %7B%22w
+airports/%7Bword%7D
 %22%7D, 
@@ -1424,33 +1424,20 @@
 rd(@
-RequestParam(value =%22w%22) 
+PathVariable
  Str

The endpoint for airport api from emberjs app should be host/MyFlights/airports/{word}