package com.bill.electricity.controller;
import com.bill.electricity.entity.Bill;
import com.bill.electricity.repository.BillRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@RestController
@RequestMapping("/api/bills")
@CrossOrigin(origins = "*")
public class BillController {
@Autowired
private BillRepository billRepository;
@GetMapping
public List getAllBills() {
return billRepository.findAll();
}
@GetMapping("/{id}")
public Bill getBillById(@PathVariable Long id) {
return billRepository.findById(id)
.orElseThrow(() -> new RuntimeException("Bill not found with id " + id));
}
}
Submit your DMCA takedown request here to
report copyright infringement.