Skip to content
Snippets Groups Projects
Verified Commit abf19aed authored by Adam Krídl's avatar Adam Krídl
Browse files

Implement CityController

It's remaining to implement methods involving assignment of Country to City
parent 5af150bd
No related branches found
No related tags found
No related merge requests found
...@@ -2,8 +2,11 @@ package cz.muni.fi.pa165.core.rest; ...@@ -2,8 +2,11 @@ package cz.muni.fi.pa165.core.rest;
import cz.muni.fi.pa165.core.api.CityApi; import cz.muni.fi.pa165.core.api.CityApi;
import cz.muni.fi.pa165.core.api.CityApiDelegate; import cz.muni.fi.pa165.core.api.CityApiDelegate;
import cz.muni.fi.pa165.core.facade.city.CityFacade;
import cz.muni.fi.pa165.core.facade.country.CountryFacade;
import cz.muni.fi.pa165.core.model.CityDto; import cz.muni.fi.pa165.core.model.CityDto;
import cz.muni.fi.pa165.core.model.NewCityDtoRequest; import cz.muni.fi.pa165.core.model.NewCityDtoRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
...@@ -12,6 +15,15 @@ import java.util.List; ...@@ -12,6 +15,15 @@ import java.util.List;
@RestController @RestController
public class CityController implements CityApiDelegate { public class CityController implements CityApiDelegate {
private final CityFacade<Long> cityFacade;
private final CountryFacade<Long> countryFacade;
@Autowired
public CityController(CityFacade<Long> cityFacade, CountryFacade<Long> countryFacade) {
this.cityFacade = cityFacade;
this.countryFacade = countryFacade;
}
/** /**
* POST /api/cities/{cityId}/countries/{countryId} : Assign country to a city. * POST /api/cities/{cityId}/countries/{countryId} : Assign country to a city.
* *
...@@ -23,7 +35,8 @@ public class CityController implements CityApiDelegate { ...@@ -23,7 +35,8 @@ public class CityController implements CityApiDelegate {
*/ */
@Override @Override
public ResponseEntity<CityDto> assignCountry(Long cityId, Long countryId) { public ResponseEntity<CityDto> assignCountry(Long cityId, Long countryId) {
return CityApiDelegate.super.assignCountry(cityId, countryId); // TODO: Implement me
return null;
} }
/** /**
...@@ -37,7 +50,7 @@ public class CityController implements CityApiDelegate { ...@@ -37,7 +50,7 @@ public class CityController implements CityApiDelegate {
*/ */
@Override @Override
public ResponseEntity<CityDto> createCity(NewCityDtoRequest newCityDtoRequest) { public ResponseEntity<CityDto> createCity(NewCityDtoRequest newCityDtoRequest) {
return CityApiDelegate.super.createCity(newCityDtoRequest); return ResponseEntity.ok(cityFacade.save(newCityDtoRequest));
} }
/** /**
...@@ -50,7 +63,8 @@ public class CityController implements CityApiDelegate { ...@@ -50,7 +63,8 @@ public class CityController implements CityApiDelegate {
*/ */
@Override @Override
public ResponseEntity<Void> deleteCity(Long id) { public ResponseEntity<Void> deleteCity(Long id) {
return CityApiDelegate.super.deleteCity(id); cityFacade.deleteById(id);
return null;
} }
/** /**
...@@ -64,7 +78,8 @@ public class CityController implements CityApiDelegate { ...@@ -64,7 +78,8 @@ public class CityController implements CityApiDelegate {
*/ */
@Override @Override
public ResponseEntity<Void> deleteCountryAssignment(Long cityId, Long countryId) { public ResponseEntity<Void> deleteCountryAssignment(Long cityId, Long countryId) {
return CityApiDelegate.super.deleteCountryAssignment(cityId, countryId); // TODO: Implement me
return null;
} }
/** /**
...@@ -77,7 +92,7 @@ public class CityController implements CityApiDelegate { ...@@ -77,7 +92,7 @@ public class CityController implements CityApiDelegate {
*/ */
@Override @Override
public ResponseEntity<CityDto> getCityById(Long id) { public ResponseEntity<CityDto> getCityById(Long id) {
return CityApiDelegate.super.getCityById(id); return ResponseEntity.of(cityFacade.findById(id));
} }
/** /**
...@@ -89,7 +104,7 @@ public class CityController implements CityApiDelegate { ...@@ -89,7 +104,7 @@ public class CityController implements CityApiDelegate {
*/ */
@Override @Override
public ResponseEntity<List<CityDto>> getAllCities() { public ResponseEntity<List<CityDto>> getAllCities() {
return CityApiDelegate.super.getAllCities(); return ResponseEntity.ok(cityFacade.findAll());
} }
/** /**
...@@ -104,7 +119,7 @@ public class CityController implements CityApiDelegate { ...@@ -104,7 +119,7 @@ public class CityController implements CityApiDelegate {
*/ */
@Override @Override
public ResponseEntity<CityDto> updateCity(Long id, NewCityDtoRequest newCityDtoRequest) { public ResponseEntity<CityDto> updateCity(Long id, NewCityDtoRequest newCityDtoRequest) {
return CityApiDelegate.super.updateCity(id, newCityDtoRequest); return ResponseEntity.ok(cityFacade.update(id, newCityDtoRequest));
} }
/** /**
...@@ -118,6 +133,7 @@ public class CityController implements CityApiDelegate { ...@@ -118,6 +133,7 @@ public class CityController implements CityApiDelegate {
*/ */
@Override @Override
public ResponseEntity<CityDto> updateCountryAssignment(Long cityId, Long countryId) { public ResponseEntity<CityDto> updateCountryAssignment(Long cityId, Long countryId) {
return CityApiDelegate.super.updateCountryAssignment(cityId, countryId); // TODO: Implement me
return null;
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment