Created
February 18, 2022 10:55
-
-
Save maneeshaindrachapa/f6e61d5623268fd12d1b90e68714111e to your computer and use it in GitHub Desktop.
TourPackageService - 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.TourPackage; | |
import com.explore.california.repository.TourPackageRepository; | |
import org.springframework.beans.factory.annotation.Autowired; | |
import org.springframework.stereotype.Service; | |
@Service | |
public class TourPackageService { | |
private TourPackageRepository tourPackageRepository; | |
@Autowired | |
public TourPackageService(TourPackageRepository tourPackageRepository) { | |
this.tourPackageRepository = tourPackageRepository; | |
} | |
/** | |
* Create a Tour Package | |
* | |
* @param code code of the package | |
* @param name name of the package | |
* @return new or existing tour package | |
*/ | |
public TourPackage createTourPackage(String code, String name) { | |
return tourPackageRepository.findById(code).orElse(tourPackageRepository.save(new TourPackage(code, name))); | |
} | |
/** | |
* Lookup All Tour packages | |
* | |
* @return | |
*/ | |
public Iterable<TourPackage> lookup() { | |
return tourPackageRepository.findAll(); | |
} | |
public long total() { | |
return tourPackageRepository.count(); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment