I am making a simple golf game. where there are 2 golf courses, when running the program I want the 2 golf courses added to the DB. I am using service and repository and endpoints for the golfers so new golfers can be added. but for the golf courses that have 3 holes each, I want them to be added automatically when the program runs. I have tried this:
Below is my code snippet. I want to execute addGolfCoursesAtStart() when my app is launched.
@Autowired
GolfCourseService gcs;
public void addGolfCoursesAtStart() {
// create course 1
GolfCourse gc1 = new GolfCourse("Happy Gilmore", 220, 300, 50);
System.out.println("we created a golf course for you named: " +gc1.getName());
System.out.println("this course has the following holes:");
for (Hole hole : gc1.getHoles()) {
System.out.println(hole.getName());
System.out.println("length: " + hole.getLenthHole());
}
gcs.addGolfCourse(gc1);
System.out.println("\n\n");
}
How would I achieve that?