-
Notifications
You must be signed in to change notification settings - Fork 794
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1dcf8eb
commit 1b36445
Showing
1 changed file
with
49 additions
and
0 deletions.
There are no files selected for viewing
49 changes: 49 additions & 0 deletions
49
src/main/java/guru/springframework/msscbeerservice/bootstrap/BeerLoader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package guru.springframework.msscbeerservice.bootstrap; | ||
|
||
import guru.springframework.msscbeerservice.domain.Beer; | ||
import guru.springframework.msscbeerservice.repositories.BeerRepository; | ||
import org.springframework.boot.CommandLineRunner; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.math.BigDecimal; | ||
|
||
/** | ||
* Created by jt on 2019-05-17. | ||
*/ | ||
@Component | ||
public class BeerLoader implements CommandLineRunner { | ||
|
||
private final BeerRepository beerRepository; | ||
|
||
public BeerLoader(BeerRepository beerRepository) { | ||
this.beerRepository = beerRepository; | ||
} | ||
|
||
@Override | ||
public void run(String... args) throws Exception { | ||
loadBeerObjects(); | ||
} | ||
|
||
private void loadBeerObjects() { | ||
if(beerRepository.count() == 0){ | ||
|
||
beerRepository.save(Beer.builder() | ||
.beerName("Mango Bobs") | ||
.beerStyle("IPA") | ||
.quantityToBrew(200) | ||
.minOnHand(12) | ||
.upc(337010000001L) | ||
.price(new BigDecimal("12.95")) | ||
.build()); | ||
|
||
beerRepository.save(Beer.builder() | ||
.beerName("Galaxy Cat") | ||
.beerStyle("PALE_ALE") | ||
.quantityToBrew(200) | ||
.minOnHand(12) | ||
.upc(337010000002L) | ||
.price(new BigDecimal("11.95")) | ||
.build()); | ||
} | ||
} | ||
} |