From bd6edb7abf1bc25ddf2613a9fa4be03d6f6722d1 Mon Sep 17 00:00:00 2001 From: George Hatzigeorgio Date: Thu, 8 Apr 2021 15:10:39 -0400 Subject: [PATCH 1/2] Commit --- .gitignore | 63 ++- README.md | 25 +- data.sql | 402 +++++++++--------- .../school/countries/models/Country.java | 73 ++++ .../repositories/CountryRepository.java | 7 + 5 files changed, 329 insertions(+), 241 deletions(-) create mode 100644 src/main/java/lambda/school/countries/models/Country.java create mode 100644 src/main/java/lambda/school/countries/repositories/CountryRepository.java diff --git a/.gitignore b/.gitignore index 37e76631..549e00a2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,34 +1,33 @@ -# Jetbrains IntelliJ Idea +HELP.md +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### IntelliJ IDEA ### .idea +*.iws *.iml - -# Linux -# backup files -*~ - -# Windows -# thumbnails -Thumbs.db - -# Mac OS X -# metadata -.DS_Store -# thumbnails -._* - -# GIT -.git/ - -# Java -*.class - -# packages -*.jar -*.war -*.ear - -# Logging -*.log - -# jME (binaries) -*.so +*.ipr + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ diff --git a/README.md b/README.md index 233b9af8..58876538 100644 --- a/README.md +++ b/README.md @@ -10,24 +10,30 @@ A student that completes this project shows that they can: ## Introduction -The countries of the world have many different defining attributes including land size, population, and median age. Below is a list of countries to include in your data. As most people do their research using websites, we are going to create web services to help search this data. We will be returning JSON objects. Nothing fancy for now! +The countries of the world have many different defining attributes including land size, population, and median age. +Below is a list of countries to include in your data. As most people do their research using websites, we are going to +create web services to help search this data. We will be returning JSON objects. Nothing fancy for now! -We will be creating an table for country data. The country model should contain the following fields. The model should be named `Country` and the table `countries` +We will be creating an table for country data. The country model should contain the following fields. The model should +be named `Country` and the table `countries` * String name * long population * long landmasskm2 * int medianage -The model should also include the standard getters and setters. You should use the provided data.sql file to seed your data +The model should also include the standard getters and setters. You should use the provided data.sql file to seed your +data Some Important Notes That Might help: * The sort method must work with `int` - so not `long`. the solution - type casting! See the code snippet below: - `.sort((c1, c2) -> (int)(c1.getPopulation() - c2.getPopulation()))` -* To calculate median for stretch goals - if the list contains an odd number of items, pick the middle one. If the list contains an even number of items, pick either of the two items that lie in the middle. + `.sort((c1, c2) -> (int)(c1.getPopulation() - c2.getPopulation()))` +* To calculate median for stretch goals - if the list contains an odd number of items, pick the middle one. If the list + contains an even number of items, pick either of the two items that lie in the middle. -Using the data.sql at the end, the endpoints will produce the following outputs. Expand to see the suggested outputs! Note that id numbers may vary. +Using the data.sql at the end, the endpoints will produce the following outputs. Expand to see the suggested outputs! +Note that id numbers may vary. To set up this project you will need to @@ -35,7 +41,9 @@ To set up this project you will need to * [ ] Clone your OWN version of the repository (Not Lambda's by mistake!) * [ ] Create a new branch: git checkout -b . * [ ] Push commits: git push -u origin -* [ ] Using the cloned repository as your working directory, create an initial application using the IntelliJ GUI interface remembering to implement the project on your newly created branch, committing changes regularly +* [ ] Using the cloned repository as your working directory, create an initial application using the IntelliJ GUI + interface remembering to implement the project on your newly created branch, committing changes + regularly * [ ] Push commits: git push origin [![Video on how to set up your project](https://img.youtube.com/vi/4Yrm93HxeT8/0.jpg)](https://youtu.be/4Yrm93HxeT8) @@ -1596,7 +1604,8 @@ The following URLs should return the requested data given the parameters * [ ] /names/all - return the names of all the countries alphabetically * [ ] /names/start/{letter} - return the countries alphabetically that begin with the given letter -* [ ] /population/total - return the total population of all countries in the console while returning Http Status OK as the response. +* [ ] /population/total - return the total population of all countries in the console while returning Http Status OK as + the response. * [ ] /population/min - return the country with the smallest population * [ ] /population/max - return the country with the largest population diff --git a/data.sql b/data.sql index ca0bca40..32c2d9de 100644 --- a/data.sql +++ b/data.sql @@ -2,207 +2,207 @@ DELETE FROM countries; INSERT INTO countries (countryid, name, population, landmasskm2, medianage) - VALUES (1, 'China',1420062022,9388211,39), - (2, 'India',1368737513,2973190,28), - (3, 'U.S.',329093110,9147420,38), - (4, 'Indonesia',269536482,1811570,29), - (5, 'Brazil',212392717,8358140,33), - (6, 'Pakistan',204596442,770880,23), - (7, 'Nigeria',200962417,910770,18), - (8, 'Bangladesh',168065920,130170,27), - (9, 'Russia',143895551,16376870,40), - (10, 'Mexico',132328035,1943950,29), - (11, 'Japan',126854745,364555,48), - (12, 'Ethiopia',110135635,1000000,20), - (13, 'Philippines',108106310,298170,25), - (14, 'Egypt',101168745,995450,25), - (15, 'Viet Nam',97429061,310070,33), - (16, 'DR Congo',86727573,2267050,17), - (17, 'Turkey',82961805,769630,32), - (18, 'Iran',82820766,1628550,32), - (19, 'Germany',82438639,348560,47), - (20, 'Thailand',69306160,510890,40), - (21, 'U.K.',66959016,241930,41), - (22, 'France',65480710,547557,42), - (23, 'Tanzania',60913557,885800,18), - (24, 'Italy',59216525,294140,48), - (25, 'South Africa',58065097,1213090,27), - (26, 'Myanmar',54336138,653290,29), - (27, 'Kenya',52214791,569140,20), - (28, 'South Korea',51339238,97230,43), - (29, 'Colombia',49849818,1109500,32), - (30, 'Spain',46441049,498800,46), - (31, 'Uganda',45711874,199810,16), - (32, 'Argentina',45101781,2736690,32), - (33, 'Ukraine',43795220,579320,41), - (34, 'Algeria',42679018,2381740,29), - (35, 'Sudan',42514094,1765048,20), - (36, 'Iraq',40412299,434320,20), - (37, 'Poland',38028278,306230,42), - (38, 'Canada',37279811,9093510,41), - (39, 'Afghanistan',37209007,652860,19), - (40, 'Morocco',36635156,446300,30), - (41, 'Saudi Arabia',34140662,2149690,32), - (42, 'Peru',32933835,1280000,29), - (43, 'Uzbekistan',32807368,425400,28), - (44, 'Venezuela',32779868,882050,29), - (45, 'Malaysia',32454455,328550,30), - (46, 'Angola',31787566,1246700,17), - (47, 'Mozambique',31408823,786380,18), - (48, 'Ghana',30096970,227540,21), - (49, 'Nepal',29942018,143350,25), - (50, 'Yemen',29579986,527970,20), - (51, 'Madagascar',26969642,581795,20), - (52, 'North Korea',25727408,120410,35), - (53, 'Cote dIvoire',25531083,318000,19), - (54, 'Cameroon',25312993,472710,19), - (55, 'Australia',25088636,7682300,38), - (56, 'Taiwan',23758247,35410,42), - (57, 'Niger',23176691,1266700,15), - (58, 'Sri Lanka',21018859,62710,34), - (59, 'Burkina Faso',20321560,273600,18), - (60, 'Malawi',19718743,94280,18), - (61, 'Mali',19689140,1220190,16), - (62, 'Romania',19483360,230170,43), - (63, 'Kazakhstan',18592970,2699700,31), - (64, 'Syria',18499181,183630,22), - (65, 'Chile',18336653,743532,35), - (66, 'Zambia',18137369,743390,18), - (67, 'Guatemala',17577842,107160,23), - (68, 'Zimbabwe',17297495,386850,20), - (69, 'Netherlands',17132908,33720,43), - (70, 'Ecuador',17100444,248360,28), - (71, 'Senegal',16743859,192530,19), - (72, 'Cambodia',16482646,176520,26), - (73, 'Chad',15814345,1259200,17), - (74, 'Somalia',15636171,627340,17), - (75, 'Guinea',13398180,245720,19), - (76, 'South Sudan',13263184,610952,19), - (77, 'Rwanda',12794412,24670,20), - (78, 'Benin',11801595,112760,19), - (79, 'Tunisia',11783168,155360,33), - (80, 'Burundi',11575964,25680,18), - (81, 'Belgium',11562784,30280,42), - (82, 'Cuba',11492046,106440,43), - (83, 'Bolivia',11379861,1083300,25), - (84, 'Haiti',11242856,27560,24), - (85, 'Greece',11124603,128900,45), - (86, 'Dominican Republic',10996774,48320,28), - (87, 'Czech Republic',10630589,77240,43), - (88, 'Portugal',10254666,91590,46), - (89, 'Jordan',10069794,88780,23), - (90, 'Sweden',10053135,410340,41), - (91, 'Azerbaijan',10014575,82658,32), - (92, 'United Arab Emirates',9682088,83600,34), - (93, 'Hungary',9655361,90530,43), - (94, 'Honduras',9568688,111890,25), - (95, 'Belarus',9433874,202910,40), - (96, 'Tajikistan',9292000,139960,23), - (97, 'Austria',8766201,82409,44), - (98, 'Serbia',8733407,87460,41), - (99, 'Switzerland',8608259,39516,43), - (100, 'Papua New Guinea',8586525,452860,23), - (101, 'Israel',8583916,21640,31), - (102, 'Togo',8186384,54390,19), - (103, 'Sierra Leone',7883123,72180,19), - (104, 'Hong Kong',7490776,1050,45), - (105, 'Laos',7064242,230800,24), - (106, 'Bulgaria',6988739,108560,45), - (107, 'Paraguay',6981981,397300,27), - (108, 'Libya',6569864,1759540,29), - (109, 'El Salvador',6445405,20720,28), - (110, 'Nicaragua',6351157,120340,27), - (111, 'Kyrgyzstan',6218616,191800,26), - (112, 'Lebanon',6065922,10230,31), - (113, 'Turkmenistan',5942561,469930,27), - (114, 'Singapore',5868104,700,42), - (115, 'Denmark',5775224,42430,42), - (116, 'Finland',5561389,303890,43), - (117, 'Congo',5542197,341500,19), - (118, 'Slovakia',5450987,48088,41), - (119, 'Norway',5400916,365268,40), - (120, 'Eritrea',5309659,101000,19), - (121, 'State of Palestine',5186790,6020,20), - (122, 'Oman',5001875,309500,31), - (123, 'Costa Rica',4999384,51060,34), - (124, 'Liberia',4977720,96320,19), - (125, 'Ireland',4847139,68890,39), - (126, 'Central African Republic',4825711,622980,18), - (127, 'New Zealand',4792409,263310,38), - (128, 'Mauritania',4661149,1030700,20), - (129, 'Kuwait',4248974,17820,34), - (130, 'Panama',4226197,74340,30), - (131, 'Croatia',4140148,55960,44), - (132, 'Moldova',4029750,32850,38), - (133, 'Georgia',3904204,69490,39), - (134, 'Puerto Rico',3654978,8870,38), - (135, 'Bosnia & Herzegovina',3501774,51000,42), - (136, 'Uruguay',3482156,175020,36), - (137, 'Mongolia',3166244,1553560,29), - (138, 'Albania',2938428,27400,38), - (139, 'Armenia',2936706,28470,36), - (140, 'Jamaica',2906339,10830,31), - (141, 'Lithuania',2864459,62674,43), - (142, 'Qatar',2743901,11610,32), - (143, 'Namibia',2641996,823290,22), - (144, 'Botswana',2374636,566730,26), - (145, 'Lesotho',2292682,30360,22), - (146, 'Gambia',2228075,10120,18), - (147, 'Gabon',2109099,257670,23), - (148, 'TFYR Macedonia',2086720,25220,39), - (149, 'Slovenia',2081900,20140,45), - (150, 'Guinea-Bissau',1953723,28120,19), - (151, 'Latvia',1911108,62200,44), - (152, 'Bahrain',1637896,760,32), - (153, 'Swaziland',1415414,17200,21), - (154, 'Trinidad and Tobago',1375443,5130,36), - (155, 'Equatorial Guinea',1360104,28050,22), - (156, 'Timor-Leste',1352360,14870,18), - (157, 'Estonia',1303798,42390,43), - (158, 'Mauritius',1271368,2030,37), - (159, 'Cyprus',1198427,9240,37), - (160, 'Djibouti',985690,23180,25), - (161, 'Fiji',918757,18270,29), - (162, 'Reunion',889918,2500,36), - (163, 'Comoros',850910,1861,20), - (164, 'Bhutan',826229,38117,29), - (165, 'Guyana',786508,196850,26), - (166, 'Macao',642090,30,39), - (167, 'Solomon Islands',635254,27990,21), - (168, 'Montenegro',629355,13450,39), - (169, 'Luxembourg',596992,2590,40), - (170, 'Western Sahara',582478,266000,28), - (171, 'Suriname',573085,156000,30), - (172, 'Cabo Verde',560349,4030,26), - (173, 'Maldives',451738,300,31), - (174, 'Guadeloupe',448798,1690,43), - (175, 'Brunei',439336,5270,32), - (176, 'Malta',433245,320,42), - (177, 'Bahamas',403095,10010,34), - (178, 'Belize',390231,22810,25), - (179, 'Martinique',385320,1060,46), - (180, 'Iceland',340566,100250,37), - (181, 'French Guiana',296847,82200,25), - (182, 'French Polynesia',288506,3660,33), - (183, 'Vanuatu',288017,12190,23), - (184, 'Barbados',287010,430,40), - (185, 'New Caledonia',283376,18280,33), - (186, 'Mayotte',266380,375,20), - (187, 'Sao Tome & Principe',213379,960,19), - (188, 'Samoa',198909,2830,22), - (189, 'Saint Lucia',180454,610,35), - (190, 'Guam',167245,540,31), - (191, 'Channel Islands',166828,190,44), - (192, 'Curacao',162547,444,42), - (193, 'Kiribati',120428,810,23), - (194, 'St. Vincent & Grenadines',110488,390,32), - (195, 'Tonga',110041,720,22), - (196, 'Grenada',108825,340,29), - (197, 'Micronesia',106983,700,23), - (198, 'Aruba',106053,180,41), - (199, 'U.S. Virgin Islands',104909,350,42), - (200, 'Antigua and Barbuda',104084,440,32), - (201, 'Seychelles',95702,460,36); +VALUES (1, 'China', 1420062022, 9388211, 39), + (2, 'India', 1368737513, 2973190, 28), + (3, 'U.S.', 329093110, 9147420, 38), + (4, 'Indonesia', 269536482, 1811570, 29), + (5, 'Brazil', 212392717, 8358140, 33), + (6, 'Pakistan', 204596442, 770880, 23), + (7, 'Nigeria', 200962417, 910770, 18), + (8, 'Bangladesh', 168065920, 130170, 27), + (9, 'Russia', 143895551, 16376870, 40), + (10, 'Mexico', 132328035, 1943950, 29), + (11, 'Japan', 126854745, 364555, 48), + (12, 'Ethiopia', 110135635, 1000000, 20), + (13, 'Philippines', 108106310, 298170, 25), + (14, 'Egypt', 101168745, 995450, 25), + (15, 'Viet Nam', 97429061, 310070, 33), + (16, 'DR Congo', 86727573, 2267050, 17), + (17, 'Turkey', 82961805, 769630, 32), + (18, 'Iran', 82820766, 1628550, 32), + (19, 'Germany', 82438639, 348560, 47), + (20, 'Thailand', 69306160, 510890, 40), + (21, 'U.K.', 66959016, 241930, 41), + (22, 'France', 65480710, 547557, 42), + (23, 'Tanzania', 60913557, 885800, 18), + (24, 'Italy', 59216525, 294140, 48), + (25, 'South Africa', 58065097, 1213090, 27), + (26, 'Myanmar', 54336138, 653290, 29), + (27, 'Kenya', 52214791, 569140, 20), + (28, 'South Korea', 51339238, 97230, 43), + (29, 'Colombia', 49849818, 1109500, 32), + (30, 'Spain', 46441049, 498800, 46), + (31, 'Uganda', 45711874, 199810, 16), + (32, 'Argentina', 45101781, 2736690, 32), + (33, 'Ukraine', 43795220, 579320, 41), + (34, 'Algeria', 42679018, 2381740, 29), + (35, 'Sudan', 42514094, 1765048, 20), + (36, 'Iraq', 40412299, 434320, 20), + (37, 'Poland', 38028278, 306230, 42), + (38, 'Canada', 37279811, 9093510, 41), + (39, 'Afghanistan', 37209007, 652860, 19), + (40, 'Morocco', 36635156, 446300, 30), + (41, 'Saudi Arabia', 34140662, 2149690, 32), + (42, 'Peru', 32933835, 1280000, 29), + (43, 'Uzbekistan', 32807368, 425400, 28), + (44, 'Venezuela', 32779868, 882050, 29), + (45, 'Malaysia', 32454455, 328550, 30), + (46, 'Angola', 31787566, 1246700, 17), + (47, 'Mozambique', 31408823, 786380, 18), + (48, 'Ghana', 30096970, 227540, 21), + (49, 'Nepal', 29942018, 143350, 25), + (50, 'Yemen', 29579986, 527970, 20), + (51, 'Madagascar', 26969642, 581795, 20), + (52, 'North Korea', 25727408, 120410, 35), + (53, 'Cote dIvoire', 25531083, 318000, 19), + (54, 'Cameroon', 25312993, 472710, 19), + (55, 'Australia', 25088636, 7682300, 38), + (56, 'Taiwan', 23758247, 35410, 42), + (57, 'Niger', 23176691, 1266700, 15), + (58, 'Sri Lanka', 21018859, 62710, 34), + (59, 'Burkina Faso', 20321560, 273600, 18), + (60, 'Malawi', 19718743, 94280, 18), + (61, 'Mali', 19689140, 1220190, 16), + (62, 'Romania', 19483360, 230170, 43), + (63, 'Kazakhstan', 18592970, 2699700, 31), + (64, 'Syria', 18499181, 183630, 22), + (65, 'Chile', 18336653, 743532, 35), + (66, 'Zambia', 18137369, 743390, 18), + (67, 'Guatemala', 17577842, 107160, 23), + (68, 'Zimbabwe', 17297495, 386850, 20), + (69, 'Netherlands', 17132908, 33720, 43), + (70, 'Ecuador', 17100444, 248360, 28), + (71, 'Senegal', 16743859, 192530, 19), + (72, 'Cambodia', 16482646, 176520, 26), + (73, 'Chad', 15814345, 1259200, 17), + (74, 'Somalia', 15636171, 627340, 17), + (75, 'Guinea', 13398180, 245720, 19), + (76, 'South Sudan', 13263184, 610952, 19), + (77, 'Rwanda', 12794412, 24670, 20), + (78, 'Benin', 11801595, 112760, 19), + (79, 'Tunisia', 11783168, 155360, 33), + (80, 'Burundi', 11575964, 25680, 18), + (81, 'Belgium', 11562784, 30280, 42), + (82, 'Cuba', 11492046, 106440, 43), + (83, 'Bolivia', 11379861, 1083300, 25), + (84, 'Haiti', 11242856, 27560, 24), + (85, 'Greece', 11124603, 128900, 45), + (86, 'Dominican Republic', 10996774, 48320, 28), + (87, 'Czech Republic', 10630589, 77240, 43), + (88, 'Portugal', 10254666, 91590, 46), + (89, 'Jordan', 10069794, 88780, 23), + (90, 'Sweden', 10053135, 410340, 41), + (91, 'Azerbaijan', 10014575, 82658, 32), + (92, 'United Arab Emirates', 9682088, 83600, 34), + (93, 'Hungary', 9655361, 90530, 43), + (94, 'Honduras', 9568688, 111890, 25), + (95, 'Belarus', 9433874, 202910, 40), + (96, 'Tajikistan', 9292000, 139960, 23), + (97, 'Austria', 8766201, 82409, 44), + (98, 'Serbia', 8733407, 87460, 41), + (99, 'Switzerland', 8608259, 39516, 43), + (100, 'Papua New Guinea', 8586525, 452860, 23), + (101, 'Israel', 8583916, 21640, 31), + (102, 'Togo', 8186384, 54390, 19), + (103, 'Sierra Leone', 7883123, 72180, 19), + (104, 'Hong Kong', 7490776, 1050, 45), + (105, 'Laos', 7064242, 230800, 24), + (106, 'Bulgaria', 6988739, 108560, 45), + (107, 'Paraguay', 6981981, 397300, 27), + (108, 'Libya', 6569864, 1759540, 29), + (109, 'El Salvador', 6445405, 20720, 28), + (110, 'Nicaragua', 6351157, 120340, 27), + (111, 'Kyrgyzstan', 6218616, 191800, 26), + (112, 'Lebanon', 6065922, 10230, 31), + (113, 'Turkmenistan', 5942561, 469930, 27), + (114, 'Singapore', 5868104, 700, 42), + (115, 'Denmark', 5775224, 42430, 42), + (116, 'Finland', 5561389, 303890, 43), + (117, 'Congo', 5542197, 341500, 19), + (118, 'Slovakia', 5450987, 48088, 41), + (119, 'Norway', 5400916, 365268, 40), + (120, 'Eritrea', 5309659, 101000, 19), + (121, 'State of Palestine', 5186790, 6020, 20), + (122, 'Oman', 5001875, 309500, 31), + (123, 'Costa Rica', 4999384, 51060, 34), + (124, 'Liberia', 4977720, 96320, 19), + (125, 'Ireland', 4847139, 68890, 39), + (126, 'Central African Republic', 4825711, 622980, 18), + (127, 'New Zealand', 4792409, 263310, 38), + (128, 'Mauritania', 4661149, 1030700, 20), + (129, 'Kuwait', 4248974, 17820, 34), + (130, 'Panama', 4226197, 74340, 30), + (131, 'Croatia', 4140148, 55960, 44), + (132, 'Moldova', 4029750, 32850, 38), + (133, 'Georgia', 3904204, 69490, 39), + (134, 'Puerto Rico', 3654978, 8870, 38), + (135, 'Bosnia & Herzegovina', 3501774, 51000, 42), + (136, 'Uruguay', 3482156, 175020, 36), + (137, 'Mongolia', 3166244, 1553560, 29), + (138, 'Albania', 2938428, 27400, 38), + (139, 'Armenia', 2936706, 28470, 36), + (140, 'Jamaica', 2906339, 10830, 31), + (141, 'Lithuania', 2864459, 62674, 43), + (142, 'Qatar', 2743901, 11610, 32), + (143, 'Namibia', 2641996, 823290, 22), + (144, 'Botswana', 2374636, 566730, 26), + (145, 'Lesotho', 2292682, 30360, 22), + (146, 'Gambia', 2228075, 10120, 18), + (147, 'Gabon', 2109099, 257670, 23), + (148, 'TFYR Macedonia', 2086720, 25220, 39), + (149, 'Slovenia', 2081900, 20140, 45), + (150, 'Guinea-Bissau', 1953723, 28120, 19), + (151, 'Latvia', 1911108, 62200, 44), + (152, 'Bahrain', 1637896, 760, 32), + (153, 'Swaziland', 1415414, 17200, 21), + (154, 'Trinidad and Tobago', 1375443, 5130, 36), + (155, 'Equatorial Guinea', 1360104, 28050, 22), + (156, 'Timor-Leste', 1352360, 14870, 18), + (157, 'Estonia', 1303798, 42390, 43), + (158, 'Mauritius', 1271368, 2030, 37), + (159, 'Cyprus', 1198427, 9240, 37), + (160, 'Djibouti', 985690, 23180, 25), + (161, 'Fiji', 918757, 18270, 29), + (162, 'Reunion', 889918, 2500, 36), + (163, 'Comoros', 850910, 1861, 20), + (164, 'Bhutan', 826229, 38117, 29), + (165, 'Guyana', 786508, 196850, 26), + (166, 'Macao', 642090, 30, 39), + (167, 'Solomon Islands', 635254, 27990, 21), + (168, 'Montenegro', 629355, 13450, 39), + (169, 'Luxembourg', 596992, 2590, 40), + (170, 'Western Sahara', 582478, 266000, 28), + (171, 'Suriname', 573085, 156000, 30), + (172, 'Cabo Verde', 560349, 4030, 26), + (173, 'Maldives', 451738, 300, 31), + (174, 'Guadeloupe', 448798, 1690, 43), + (175, 'Brunei', 439336, 5270, 32), + (176, 'Malta', 433245, 320, 42), + (177, 'Bahamas', 403095, 10010, 34), + (178, 'Belize', 390231, 22810, 25), + (179, 'Martinique', 385320, 1060, 46), + (180, 'Iceland', 340566, 100250, 37), + (181, 'French Guiana', 296847, 82200, 25), + (182, 'French Polynesia', 288506, 3660, 33), + (183, 'Vanuatu', 288017, 12190, 23), + (184, 'Barbados', 287010, 430, 40), + (185, 'New Caledonia', 283376, 18280, 33), + (186, 'Mayotte', 266380, 375, 20), + (187, 'Sao Tome & Principe', 213379, 960, 19), + (188, 'Samoa', 198909, 2830, 22), + (189, 'Saint Lucia', 180454, 610, 35), + (190, 'Guam', 167245, 540, 31), + (191, 'Channel Islands', 166828, 190, 44), + (192, 'Curacao', 162547, 444, 42), + (193, 'Kiribati', 120428, 810, 23), + (194, 'St. Vincent & Grenadines', 110488, 390, 32), + (195, 'Tonga', 110041, 720, 22), + (196, 'Grenada', 108825, 340, 29), + (197, 'Micronesia', 106983, 700, 23), + (198, 'Aruba', 106053, 180, 41), + (199, 'U.S. Virgin Islands', 104909, 350, 42), + (200, 'Antigua and Barbuda', 104084, 440, 32), + (201, 'Seychelles', 95702, 460, 36); /* We must tell hibernate the ids that have already been used. diff --git a/src/main/java/lambda/school/countries/models/Country.java b/src/main/java/lambda/school/countries/models/Country.java new file mode 100644 index 00000000..53fd7b69 --- /dev/null +++ b/src/main/java/lambda/school/countries/models/Country.java @@ -0,0 +1,73 @@ +package lambda.school.countries.models; + +import org.springframework.web.bind.annotation.GetMapping; + +import javax.persistence.*; + +@Entity +@Table(name="countries") +public class Country { + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + private long countryid; + + private String name; + + private long population; + + private long landmasskm2; + + private int medianage; + + + public Country() { + } + + public Country(String name, long population, long landmasskm2, int medianage) { + this.name = name; + this.population = population; + this.landmasskm2 = landmasskm2; + this.medianage = medianage; + } + + public long getCountryid() { + return countryid; + } + + public void setCountryid(long countryid) { + this.countryid = countryid; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public long getPopulation() { + return population; + } + + public void setPopulation(long population) { + this.population = population; + } + + public long getLandmasskm2() { + return landmasskm2; + } + + public void setLandmasskm2(long landmasskm2) { + this.landmasskm2 = landmasskm2; + } + + public int getMedianage() { + return medianage; + } + + public void setMedianage(int medianage) { + this.medianage = medianage; + } +} diff --git a/src/main/java/lambda/school/countries/repositories/CountryRepository.java b/src/main/java/lambda/school/countries/repositories/CountryRepository.java new file mode 100644 index 00000000..9896ad59 --- /dev/null +++ b/src/main/java/lambda/school/countries/repositories/CountryRepository.java @@ -0,0 +1,7 @@ +package lambda.school.countries.repositories; + +import lambda.school.countries.models.Country; +import org.springframework.data.repository.CrudRepository; + +public interface CountryRepository extends CrudRepository { +} From ad35386430d9d233090c7fb6aa2f97e3ba899a91 Mon Sep 17 00:00:00 2001 From: George Hatzigeorgio Date: Thu, 8 Apr 2021 16:25:54 -0400 Subject: [PATCH 2/2] Commit --- .../countries/controllers/CheckCountries.java | 8 ++ .../controllers/CountryController.java | 85 +++++++++++++++++++ data.sql => src/main/resources/data.sql | 0 3 files changed, 93 insertions(+) create mode 100644 src/main/java/lambda/school/countries/controllers/CheckCountries.java create mode 100644 src/main/java/lambda/school/countries/controllers/CountryController.java rename data.sql => src/main/resources/data.sql (100%) diff --git a/src/main/java/lambda/school/countries/controllers/CheckCountries.java b/src/main/java/lambda/school/countries/controllers/CheckCountries.java new file mode 100644 index 00000000..983789e3 --- /dev/null +++ b/src/main/java/lambda/school/countries/controllers/CheckCountries.java @@ -0,0 +1,8 @@ +package lambda.school.countries.controllers; + +import lambda.school.countries.models.Country; + +@FunctionalInterface +public interface CheckCountries { + boolean test(Country country); +} diff --git a/src/main/java/lambda/school/countries/controllers/CountryController.java b/src/main/java/lambda/school/countries/controllers/CountryController.java new file mode 100644 index 00000000..6864a5c8 --- /dev/null +++ b/src/main/java/lambda/school/countries/controllers/CountryController.java @@ -0,0 +1,85 @@ +package lambda.school.countries.controllers; + +import lambda.school.countries.models.Country; +import lambda.school.countries.repositories.CountryRepository; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RestController; + +import java.util.ArrayList; +import java.util.List; + +@RestController +public class CountryController { + @Autowired + private CountryRepository countryRepository; + + //http://localhost:2019/names/all + + @GetMapping(value = "/names/all", produces = "application/json") + public ResponseEntity findAllCountries() { + List countries = new ArrayList<>(); + countryRepository.findAll().iterator().forEachRemaining(countries::add); + + return new ResponseEntity<>(countries, HttpStatus.OK); + } + + //http:localhost:2019/population/total + + @GetMapping(value = "/population/total", produces = "application/json") + public ResponseEntity getTotal() { + List countryList = new ArrayList<>(); + countryRepository.findAll().iterator().forEachRemaining(countryList::add); + + double Total = 0.0; + for (Country c : countryList) + Total += c.getPopulation(); + return new ResponseEntity<>(Total, HttpStatus.OK); + + } + + @GetMapping(value = "names/start/{letter}", produces = "application/json") + public ResponseEntity findByName(@PathVariable char letter){ + List countryList = new ArrayList<>(); + countryRepository.findAll().iterator().forEachRemaining(countryList::add); + List filteredList = filterCountries(countryList, + (country -> country.getName().charAt(0)==letter)); + return new ResponseEntity<>(filteredList, HttpStatus.OK); + } + private List filterCountries (List countryList,CheckCountries tester){ + List rtnList = new ArrayList<>(); + for (Country c: countryList){ + if(tester.test(c)){ + rtnList.add(c); + } + } + return rtnList; + } + @GetMapping(value ="/population/min", produces = {"application/json"}) + public ResponseEntity listPopulationMin() + { + List myList = new ArrayList<>(); + countryRepository.findAll().iterator().forEachRemaining(myList::add); + + myList.sort((e1, e2) -> (int)(e1.getPopulation()- (e2.getPopulation()))); + + //MyList.get(0) returns first object based on sort (low) + return new ResponseEntity<>(myList.get(0), HttpStatus.OK); + } +// http://localhost:2021/population/max + + @GetMapping(value ="/population/max", produces = {"application/json"}) + public ResponseEntity listPopulationMax() + { + List myList = new ArrayList<>(); + countryRepository.findAll().iterator().forEachRemaining(myList::add); + + // Sorts High to Low + myList.sort((e1, e2) -> (int)(e2.getPopulation()- (e1.getPopulation()))); + + return new ResponseEntity<>(myList.get(0), HttpStatus.OK); + } +} \ No newline at end of file diff --git a/data.sql b/src/main/resources/data.sql similarity index 100% rename from data.sql rename to src/main/resources/data.sql