commit 41eaff83c4e4c0d284b354ecfa3c12c6b08baa83 Author: Nicolas Massé Date: Mon Feb 25 16:11:59 2019 +0100 first version diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..48143bc --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "lab-instructions/themes/learn"] + path = lab-instructions/themes/learn + url = https://github.com/matcornic/hugo-theme-learn.git diff --git a/backend-springboot/pom.xml b/backend-springboot/pom.xml new file mode 100644 index 0000000..c4c9364 --- /dev/null +++ b/backend-springboot/pom.xml @@ -0,0 +1,50 @@ + + + 4.0.0 + + com.github.lbroudoux + beer-catalog + 0.0.1-SNAPSHOT + jar + + spring-boot-hello + Demo project for Spring Boot + + + org.springframework.boot + spring-boot-starter-parent + 1.4.2.RELEASE + + + + + UTF-8 + UTF-8 + 1.8 + + + + + org.springframework.boot + spring-boot-starter-web + + + + org.springframework.boot + spring-boot-starter-test + test + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + + diff --git a/backend-springboot/src/main/java/com/github/lbroudoux/beer/Beer.java b/backend-springboot/src/main/java/com/github/lbroudoux/beer/Beer.java new file mode 100644 index 0000000..11adff6 --- /dev/null +++ b/backend-springboot/src/main/java/com/github/lbroudoux/beer/Beer.java @@ -0,0 +1,89 @@ +/* +MIT License + +Copyright (c) 2018 Laurent BROUDOUX + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +*/ +package com.github.lbroudoux.beer; + +/** + * @author laurent + */ +public class Beer { + + private String name; + private String country; + private String type; + private Float rating; + private String status; + + + public Beer(){ + + } + + public Beer(String name, String country, String type, Float rating, String status) { + this.name = name; + this.country = country; + this.type = type; + this.rating = rating; + this.status = status; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getCountry() { + return country; + } + + public void setCountry(String country) { + this.country = country; + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + public Float getRating() { + return rating; + } + + public void setRating(Float rating) { + this.rating = rating; + } + + public String getStatus() { + return status; + } + + public void setStatus(String status) { + this.status = status; + } +} diff --git a/backend-springboot/src/main/java/com/github/lbroudoux/beer/BeerCatalogApplication.java b/backend-springboot/src/main/java/com/github/lbroudoux/beer/BeerCatalogApplication.java new file mode 100644 index 0000000..ea0ad85 --- /dev/null +++ b/backend-springboot/src/main/java/com/github/lbroudoux/beer/BeerCatalogApplication.java @@ -0,0 +1,38 @@ +/* +MIT License + +Copyright (c) 2018 Laurent BROUDOUX + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +*/ +package com.github.lbroudoux.beer; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +/** + * @author laurent + */ +@SpringBootApplication +public class BeerCatalogApplication { + + public static void main(String[] args) { + SpringApplication.run(BeerCatalogApplication.class, args); + } +} diff --git a/backend-springboot/src/main/java/com/github/lbroudoux/beer/BeerCatalogController.java b/backend-springboot/src/main/java/com/github/lbroudoux/beer/BeerCatalogController.java new file mode 100644 index 0000000..b11c1b7 --- /dev/null +++ b/backend-springboot/src/main/java/com/github/lbroudoux/beer/BeerCatalogController.java @@ -0,0 +1,57 @@ +/* +MIT License + +Copyright (c) 2018 Laurent BROUDOUX + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +*/ +package com.github.lbroudoux.beer; + +import org.springframework.web.bind.annotation.*; + +import java.util.List; + +/** + * @author laurent + */ +@RestController +@RequestMapping("/api") +public class BeerCatalogController { + + @CrossOrigin + @RequestMapping(method = RequestMethod.GET, value = "/beer") + public List getBeers( + @RequestParam(value = "page", required = false, defaultValue = "0") int page) { + return BeerRepository.getBeers(); + } + + @CrossOrigin + @RequestMapping(method = RequestMethod.GET, value = "/beer/{name}") + public Beer getBeer( + @PathVariable("name") String name) { + return BeerRepository.findByName(name); + } + + @CrossOrigin + @RequestMapping(method = RequestMethod.GET, value = "/beer/findByStatus/{status}") + public List getByStatus( + @PathVariable("status") String status) { + return BeerRepository.findByStatus(status); + } +} diff --git a/backend-springboot/src/main/java/com/github/lbroudoux/beer/BeerRepository.java b/backend-springboot/src/main/java/com/github/lbroudoux/beer/BeerRepository.java new file mode 100644 index 0000000..ac934d6 --- /dev/null +++ b/backend-springboot/src/main/java/com/github/lbroudoux/beer/BeerRepository.java @@ -0,0 +1,66 @@ +/* +MIT License + +Copyright (c) 2018 Laurent BROUDOUX + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +*/ +package com.github.lbroudoux.beer; + +import java.util.*; +import java.util.stream.Collectors; + +/** + * @author laurent + */ +public class BeerRepository { + + private static Map beers = new HashMap<>(); + + static { + beers.put("Rodenbach", new Beer("Rodenbach", "Belgium", "Brown ale", 4.2f, "available")); + beers.put("Westmalle Triple", new Beer("Westmalle Triple", "Belgium", "Trappist", 3.8f, "available")); + beers.put("Weissbier", new Beer("Weissbier", "Germany", "Wheat", 4.1f, "out_of_stock")); + beers.put("Orval", new Beer("Orval", "Belgium", "Trappist", 4.3f, "available")); + beers.put("Rochefort", new Beer("Rochefort", "Belgium", "Trappist", 4.1f, "out_of_stock")); + beers.put("Floreffe", new Beer("Floreffe", "Belgium", "Abbey", 3.4f, "out_of_stock")); + beers.put("Maredsous", new Beer("Maredsous", "Belgium", "Abbey", 3.9f, "available")); + beers.put("Pilsener", new Beer("Pilsener", "Germany", "Pale beer", 3.2f, "available")); + beers.put("Bock", new Beer("Bock", "Germany", "Dark beer", 3.7f, "available")); + } + + public static List getBeers() { + return new ArrayList<>(beers.values()); + } + + public static Beer findByName(String name) { + if (beers.containsKey(name)) { + return beers.get(name); + } + return null; + } + + public static List findByStatus(String status) { + List results = beers.values().stream() + .filter(beer -> beer.getStatus().equals(status)) + .collect(Collectors.toList()); + + return results; + } +} diff --git a/backend-springboot/src/main/resources/application.properties b/backend-springboot/src/main/resources/application.properties new file mode 100644 index 0000000..e69de29 diff --git a/lab-instructions/themes/learn b/lab-instructions/themes/learn new file mode 160000 index 0000000..4fc4354 --- /dev/null +++ b/lab-instructions/themes/learn @@ -0,0 +1 @@ +Subproject commit 4fc43548b52be044166cde53845d7f36cdb15ad4