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 getAll() { return loteService.findAll(); } @GetMapping("/{id}") public ResponseEntity 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 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 delete(@PathVariable Long id) { loteService.delete(id); return ResponseEntity.noContent().build(); } }