Files
TEST/src/main/java/com/example/fercoganbackend/controller/LoteController.java
andre00bejarano00vaca 2f9142e1b5
Some checks failed
Deploy Spring Boot App / build-and-deploy (push) Has been cancelled
backend con panel admin funcional
2025-10-01 16:45:24 -04:00

52 lines
1.4 KiB
Java

package com.example.fercoganbackend.controller;
import com.example.fercoganbackend.entity.Lote;
import com.example.fercoganbackend.service.LoteService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@RestController
@RequestMapping("/api/lotes")
public class LoteController {
@Autowired
private LoteService loteService;
@GetMapping
public List<Lote> getAll() {
return loteService.findAll();
}
@GetMapping("/{id}")
public ResponseEntity<Lote> getById(@PathVariable Long id) {
return loteService.findById(id)
.map(ResponseEntity::ok)
.orElse(ResponseEntity.notFound().build());
}
@PostMapping
public Lote create(@RequestBody Lote remate) {
return loteService.save(remate);
}
@PutMapping("/{id}")
public ResponseEntity<Lote> update(@PathVariable Long id, @RequestBody Lote remate) {
return loteService.findById(id)
.map(r -> {
remate.setId(id);
return ResponseEntity.ok(loteService.save(remate));
})
.orElse(ResponseEntity.notFound().build());
}
@DeleteMapping("/{id}")
public ResponseEntity<Void> delete(@PathVariable Long id) {
loteService.delete(id);
return ResponseEntity.noContent().build();
}
}