-
Notifications
You must be signed in to change notification settings - Fork 51
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
Showing
3 changed files
with
65 additions
and
0 deletions.
There are no files selected for viewing
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
31 changes: 31 additions & 0 deletions
31
src/main/java/com/restfulspring/apiexample/service/CityService.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,31 @@ | ||
package com.restfulspring.apiexample.service; | ||
|
||
import com.restfulspring.apiexample.entity.City; | ||
import com.restfulspring.apiexample.entity.Country; | ||
import com.restfulspring.apiexample.repository.CityRepository; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.util.List; | ||
|
||
@Service | ||
public class CityService { | ||
@Autowired | ||
private CityRepository cityRepository; | ||
public List<City> getCities(){ | ||
return cityRepository.findAll(); | ||
} | ||
public City getCity(int id){ | ||
return cityRepository.findById(id).orElse(null); | ||
} | ||
public City addCity(City city){ | ||
return cityRepository.save(city); | ||
} | ||
public City updateCity(int id,City city){ | ||
city.setCityId(id); | ||
return cityRepository.save(city); | ||
} | ||
public void deleteCity(int id){ | ||
cityRepository.deleteById(id); | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
src/main/java/com/restfulspring/apiexample/service/CountryService.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,31 @@ | ||
package com.restfulspring.apiexample.service; | ||
|
||
import com.restfulspring.apiexample.entity.Country; | ||
import com.restfulspring.apiexample.repository.CountryRepository; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.util.List; | ||
|
||
@Service | ||
public class CountryService { | ||
@Autowired | ||
private CountryRepository countryRepository; | ||
|
||
public List<Country> getCountries(){ | ||
return countryRepository.findAll(); | ||
} | ||
public Country getCountry(int id){ | ||
return countryRepository.findById(id).orElse(null); | ||
} | ||
public Country addCountry(Country country){ | ||
return countryRepository.save(country); | ||
} | ||
public Country updateCountry(int id,Country country){ | ||
country.setCountryId(id); | ||
return countryRepository.save(country); | ||
} | ||
public void deleteCountry(int id){ | ||
countryRepository.deleteById(id); | ||
} | ||
} |