Skip to content

Commit

Permalink
adding bootstrap - closes #7
Browse files Browse the repository at this point in the history
  • Loading branch information
springframeworkguru committed May 17, 2019
1 parent 1dcf8eb commit 1b36445
Showing 1 changed file with 49 additions and 0 deletions.
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());
}
}
}

0 comments on commit 1b36445

Please sign in to comment.