backend con panel admin funcional
Some checks failed
Deploy Spring Boot App / build-and-deploy (push) Has been cancelled
Some checks failed
Deploy Spring Boot App / build-and-deploy (push) Has been cancelled
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user