File tree Expand file tree Collapse file tree
src/main/java/com/lambdaschool/countries/demo Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11package com .lambdaschool .countries .demo ;
22
33import org .springframework .web .bind .annotation .RequestMapping ;
4+ import org .springframework .web .bind .annotation .RequestParam ;
45import org .springframework .web .bind .annotation .RestController ;
56
67import java .util .ArrayList ;
910@ RequestMapping ("/names" )
1011
1112public class CountryNameController {
13+ @ RequestMapping ("/begin" )
14+ public ArrayList <Country > filteredCountry (@ RequestParam (value ="letter" )String letter ){
15+ ArrayList <Country > filtered = new ArrayList <>();
16+ for (Country a : CountriesApplication .countryList .countryList ) {
17+ String name = a .getName ();
18+ String firstLetter = "" ;
19+ firstLetter = String .valueOf (name .charAt (0 ));
20+ if (firstLetter .equals (letter .toUpperCase ())){
21+ filtered .add (a );
22+ }
23+ }
24+
25+ return filtered ;
26+ }
27+
28+
1229 @ RequestMapping ("/all" )
13- public ArrayList <Country > getCountryDetails () {
30+ public ArrayList <Country > getAllCountry () {
1431 CountriesApplication .countryList .countryList .sort ((c1 , c2 )-> c1 .getName ().compareToIgnoreCase (c2 .getName ()));
1532 return CountriesApplication .countryList .countryList ;
1633 }
You can’t perform that action at this time.
0 commit comments