Files
TEST/src/main/java/com/example/fercoganbackend/controller/PujaController.java

67 lines
2.0 KiB
Java

package com.example.fercoganbackend.controller;
import com.example.fercoganbackend.entity.Puja;
import com.example.fercoganbackend.service.PujaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.Optional;
@RestController
@RequestMapping("/api/pujas")
public class PujaController {
@Autowired
private PujaService pujaService;
@GetMapping
public List<Puja> getAll() {
return pujaService.findAll();
}
@GetMapping("/id/{id}")
public ResponseEntity<Puja> getById(@PathVariable Long id) {
return pujaService.findById(id)
.map(ResponseEntity::ok)
.orElse(ResponseEntity.notFound().build());
}
@GetMapping("/informe/{remateId}")
public List<Puja> getForInforme(@PathVariable Long remateId){
return pujaService.fingForReporte(remateId);
}
@GetMapping("/remate/{id}")
public List<Puja> getForRemate(@PathVariable Long id){
return pujaService.findForRemtae(id);
}
//get coincidir con lote y remate
@GetMapping("/loteyremate/{loteId}/{remateId}")
public List<Puja> getForLoteAndRemate(@PathVariable Long loteId, @PathVariable Long remateId){
return pujaService.findForLoteAndRemate(loteId,remateId);
}
@PostMapping
public Puja create(@RequestBody Puja puja) {
return pujaService.save(puja);
}
@PutMapping("/{id}")
public ResponseEntity<Puja> update(@PathVariable Long id, @RequestBody Puja remate) {
return pujaService.findById(id)
.map(r -> {
remate.setId(id);
return ResponseEntity.ok(pujaService.save(remate));
})
.orElse(ResponseEntity.notFound().build());
}
@DeleteMapping("/{id}")
public ResponseEntity<Void> delete(@PathVariable Long id) {
pujaService.delete(id);
return ResponseEntity.noContent().build();
}
}