commit
41eaff83c4
8 changed files with 304 additions and 0 deletions
@ -0,0 +1,3 @@ |
|||||
|
[submodule "lab-instructions/themes/learn"] |
||||
|
path = lab-instructions/themes/learn |
||||
|
url = https://github.com/matcornic/hugo-theme-learn.git |
||||
@ -0,0 +1,50 @@ |
|||||
|
<?xml version="1.0" encoding="UTF-8"?> |
||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> |
||||
|
<modelVersion>4.0.0</modelVersion> |
||||
|
|
||||
|
<groupId>com.github.lbroudoux</groupId> |
||||
|
<artifactId>beer-catalog</artifactId> |
||||
|
<version>0.0.1-SNAPSHOT</version> |
||||
|
<packaging>jar</packaging> |
||||
|
|
||||
|
<name>spring-boot-hello</name> |
||||
|
<description>Demo project for Spring Boot</description> |
||||
|
|
||||
|
<parent> |
||||
|
<groupId>org.springframework.boot</groupId> |
||||
|
<artifactId>spring-boot-starter-parent</artifactId> |
||||
|
<version>1.4.2.RELEASE</version> |
||||
|
<relativePath/> <!-- lookup parent from repository --> |
||||
|
</parent> |
||||
|
|
||||
|
<properties> |
||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> |
||||
|
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> |
||||
|
<java.version>1.8</java.version> |
||||
|
</properties> |
||||
|
|
||||
|
<dependencies> |
||||
|
<dependency> |
||||
|
<groupId>org.springframework.boot</groupId> |
||||
|
<artifactId>spring-boot-starter-web</artifactId> |
||||
|
</dependency> |
||||
|
|
||||
|
<dependency> |
||||
|
<groupId>org.springframework.boot</groupId> |
||||
|
<artifactId>spring-boot-starter-test</artifactId> |
||||
|
<scope>test</scope> |
||||
|
</dependency> |
||||
|
</dependencies> |
||||
|
|
||||
|
<build> |
||||
|
<plugins> |
||||
|
<plugin> |
||||
|
<groupId>org.springframework.boot</groupId> |
||||
|
<artifactId>spring-boot-maven-plugin</artifactId> |
||||
|
</plugin> |
||||
|
</plugins> |
||||
|
</build> |
||||
|
|
||||
|
|
||||
|
</project> |
||||
@ -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; |
||||
|
} |
||||
|
} |
||||
@ -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); |
||||
|
} |
||||
|
} |
||||
@ -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<Beer> 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<Beer> getByStatus( |
||||
|
@PathVariable("status") String status) { |
||||
|
return BeerRepository.findByStatus(status); |
||||
|
} |
||||
|
} |
||||
@ -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<String, Beer> 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<Beer> 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<Beer> findByStatus(String status) { |
||||
|
List<Beer> results = beers.values().stream() |
||||
|
.filter(beer -> beer.getStatus().equals(status)) |
||||
|
.collect(Collectors.toList()); |
||||
|
|
||||
|
return results; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1 @@ |
|||||
|
Subproject commit 4fc43548b52be044166cde53845d7f36cdb15ad4 |
||||
Loading…
Reference in new issue