Created
February 18, 2022 10:54
-
-
Save maneeshaindrachapa/61ca2e4a380135eff34e9ab261c5b5a8 to your computer and use it in GitHub Desktop.
TourService - Tour California Application
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
package com.explore.california.service; | |
import com.explore.california.model.Difficulty; | |
import com.explore.california.model.Region; | |
import com.explore.california.model.Tour; | |
import com.explore.california.model.TourPackage; | |
import com.explore.california.repository.TourPackageRepository; | |
import com.explore.california.repository.TourRepository; | |
import org.springframework.beans.factory.annotation.Autowired; | |
import org.springframework.stereotype.Service; | |
@Service | |
public class TourService { | |
private TourRepository tourRepository; | |
private TourPackageRepository tourPackageRepository; | |
@Autowired | |
public TourService(TourRepository tourRepository, TourPackageRepository tourPackageRepository) { | |
this.tourRepository = tourRepository; | |
this.tourPackageRepository = tourPackageRepository; | |
} | |
/** | |
* Create a new Tour Object and persist it to the Database. | |
* | |
* @param title | |
* @param description | |
* @param blurb | |
* @param price | |
* @param duration | |
* @param bullets | |
* @param keywords | |
* @param tourPackageName | |
* @param difficulty | |
* @param region | |
* @return Tour Entity | |
*/ | |
public Tour createTour(String title, String description, String blurb, Integer price, | |
String duration, String bullets, | |
String keywords, String tourPackageName, Difficulty difficulty, Region region) { | |
TourPackage tourPackage = tourPackageRepository.findById(tourPackageName).orElseThrow(() -> | |
new RuntimeException("Tour package does not exist: " + tourPackageName)); | |
return tourRepository.save(new Tour(title, description, blurb, price, duration, | |
bullets, keywords, tourPackage, difficulty, region)); | |
} | |
/** | |
* Calculate the number of Tours in the Database. | |
* | |
* @return the total. | |
*/ | |
public long total() { | |
return tourRepository.count(); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment