Created
April 14, 2018 16:49
-
-
Save otoloye/79ac85c4ac0ea88a58813bce7f29381f to your computer and use it in GitHub Desktop.
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.otoloye.RestWithSpringBoot.controller; | |
import com.otoloye.RestWithSpringBoot.model.Package; | |
import com.otoloye.RestWithSpringBoot.repository.PackageRepository; | |
import org.springframework.beans.factory.annotation.Autowired; | |
import org.springframework.web.bind.annotation.*; | |
import java.util.List; | |
@RestController | |
public class PackageController { | |
@Autowired | |
private PackageRepository packageRepository; | |
@GetMapping("/packages") | |
public List<Package> getAllPackages() { | |
return packageRepository.findAll(); | |
} | |
@GetMapping("/packages/{id}") | |
public Package getPackage(@PathVariable int id) { | |
return packageRepository.findById(id); | |
} | |
@PostMapping("/packages") | |
public void createPackage(@RequestBody Package pkg) { | |
packageRepository.save(pkg); | |
} | |
@DeleteMapping("/packages/{id}") | |
public Package deletePackage(@PathVariable int id) { | |
return packageRepository.deleteById(id); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment