Skip to content

Instantly share code, notes, and snippets.

@otoloye
Created April 14, 2018 16:49
Show Gist options
  • Save otoloye/79ac85c4ac0ea88a58813bce7f29381f to your computer and use it in GitHub Desktop.
Save otoloye/79ac85c4ac0ea88a58813bce7f29381f to your computer and use it in GitHub Desktop.
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