backend con panel admin funcional
Some checks failed
Deploy Spring Boot App / build-and-deploy (push) Has been cancelled

This commit is contained in:
2025-10-01 16:45:24 -04:00
parent ef2b6c1870
commit 2f9142e1b5
21 changed files with 719 additions and 3 deletions

View File

@@ -37,6 +37,7 @@ public class SecurityConfig {
.csrf(AbstractHttpConfigurer::disable)
.authorizeHttpRequests(auth -> auth
.requestMatchers("/auth/**").permitAll()
.requestMatchers("/favicon.ico", "/error", "/static/**", "/ws/contador/**", "contador/**", "/api/**").permitAll()
.requestMatchers("/admin/**").hasAnyAuthority("SUPER_USUARIO","ADMIN")
.anyRequest().authenticated()
)

View File

@@ -6,6 +6,8 @@ import com.example.fercoganbackend.entity.Usuario;
import com.example.fercoganbackend.otros.ConfirmadoTF;
import com.example.fercoganbackend.service.ContadorService;
import com.example.fercoganbackend.service.UsuarioService;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.util.Set;
import java.util.List;
@@ -25,13 +27,18 @@ public class AppController {
// Registro
@PostMapping("/auth/registrar")
public String registrar(@RequestParam String username,
@RequestParam String password) {
public ResponseEntity<String> registrar(@RequestParam String username,
@RequestParam String password) {
if (usuarioService.estaRegistrado(username)) {
return ResponseEntity.status(HttpStatus.CONFLICT).body("Usuario ya existe ❌");
}
usuarioService.registrarUsuario(username, password, Set.of(Rol.CLIENTE));
return "Usuario registrado, pendiente de aprobación";
return ResponseEntity.ok("Usuario registrado, pendiente de aprobación");
}
// Verificar si aprobado
@GetMapping("/auth/verificar/{username}")
public ConfirmadoTF verificar(@PathVariable String username) {
@@ -39,6 +46,22 @@ public class AppController {
return aprobado;
}
@GetMapping("/auth/existe/{username}")
public ResponseEntity<ConfirmadoTF> existe(@PathVariable String username) {
ConfirmadoTF aprobado = usuarioService.registradoYAprobado(username);
if (aprobado == null) {
return ResponseEntity.status(HttpStatus.NOT_FOUND).build();
}
if (!aprobado.isConfirmed()) { // supongamos que ConfirmadoTF tiene isAprobado()
return ResponseEntity.status(HttpStatus.UNAUTHORIZED).build();
}
return ResponseEntity.ok(aprobado);
}
// Listar pendientes (solo admin/super)
@GetMapping("/admin/pendientes")
public List<Usuario> pendientes() {

View File

@@ -0,0 +1,50 @@
package com.example.fercoganbackend.controller;
import com.example.fercoganbackend.entity.Cabana;
import com.example.fercoganbackend.service.CabanaService;
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/cabanas")
public class CabanaController {
@Autowired
private CabanaService cabanaService;
@GetMapping
public List<Cabana> getAll() {
return cabanaService.findAll();
}
@GetMapping("/{id}")
public ResponseEntity<Cabana> getById(@PathVariable Long id) {
return cabanaService.findById(id)
.map(ResponseEntity::ok)
.orElse(ResponseEntity.notFound().build());
}
@PostMapping
public Cabana create(@RequestBody Cabana remate) {
return cabanaService.save(remate);
}
@PutMapping("/{id}")
public ResponseEntity<Cabana> update(@PathVariable Long id, @RequestBody Cabana remate) {
return cabanaService.findById(id)
.map(r -> {
remate.setId(id);
return ResponseEntity.ok(cabanaService.save(remate));
})
.orElse(ResponseEntity.notFound().build());
}
@DeleteMapping("/{id}")
public ResponseEntity<Void> delete(@PathVariable Long id) {
cabanaService.delete(id);
return ResponseEntity.noContent().build();
}
}

View File

@@ -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();
}
}

View File

@@ -0,0 +1,50 @@
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;
@RestController
@RequestMapping("/api/pujas")
public class PujaController {
@Autowired
private PujaService pujaService;
@GetMapping
public List<Puja> getAll() {
return pujaService.findAll();
}
@GetMapping("/{id}")
public ResponseEntity<Puja> getById(@PathVariable Long id) {
return pujaService.findById(id)
.map(ResponseEntity::ok)
.orElse(ResponseEntity.notFound().build());
}
@PostMapping
public Puja create(@RequestBody Puja remate) {
return pujaService.save(remate);
}
@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();
}
}

View File

@@ -0,0 +1,51 @@
package com.example.fercoganbackend.controller;
import com.example.fercoganbackend.entity.Remate;
import com.example.fercoganbackend.service.RemateService;
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/remates")
public class RemateController {
@Autowired
private RemateService remateService;
@GetMapping
public List<Remate> getAll() {
return remateService.findAll();
}
@GetMapping("/{id}")
public ResponseEntity<Remate> getById(@PathVariable Long id) {
return remateService.findById(id)
.map(ResponseEntity::ok)
.orElse(ResponseEntity.notFound().build());
}
@PostMapping
public Remate create(@RequestBody Remate remate) {
return remateService.save(remate);
}
@PutMapping("/{id}")
public ResponseEntity<Remate> update(@PathVariable Long id, @RequestBody Remate remate) {
return remateService.findById(id)
.map(r -> {
remate.setId(id);
return ResponseEntity.ok(remateService.save(remate));
})
.orElse(ResponseEntity.notFound().build());
}
@DeleteMapping("/{id}")
public ResponseEntity<Void> delete(@PathVariable Long id) {
remateService.delete(id);
return ResponseEntity.noContent().build();
}
}

View File

@@ -0,0 +1,15 @@
package com.example.fercoganbackend.controller;
import com.example.fercoganbackend.service.UsuarioService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/api/user")
public class UserController {
@Autowired
UsuarioService usuarioService;
}

View File

@@ -0,0 +1,40 @@
package com.example.fercoganbackend.entity;
import jakarta.persistence.*;
// Cabaña
@Entity
@Table(name = "cabanas")
public class Cabana {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String nombre;
private Boolean visible;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getNombre() {
return nombre;
}
public void setNombre(String nombre) {
this.nombre = nombre;
}
public Boolean getVisible() {
return visible;
}
public void setVisible(Boolean visible) {
this.visible = visible;
}
}

View File

@@ -0,0 +1,108 @@
package com.example.fercoganbackend.entity;
import jakarta.persistence.*;
// Lote
@Entity
@Table(name = "lotes")
public class Lote {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String nombre;
private Double precio;
private String raza;
private Double prelance;
private Double puja;
private String estado;
private Boolean visible;
@ManyToOne
@JoinColumn(name = "remate_id")
private Remate remate;
@ManyToOne
@JoinColumn(name = "cabana_id")
private Cabana cabana;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getNombre() {
return nombre;
}
public void setNombre(String nombre) {
this.nombre = nombre;
}
public Double getPrecio() {
return precio;
}
public void setPrecio(Double precio) {
this.precio = precio;
}
public String getRaza() {
return raza;
}
public void setRaza(String raza) {
this.raza = raza;
}
public Double getPrelance() {
return prelance;
}
public void setPrelance(Double prelance) {
this.prelance = prelance;
}
public Double getPuja() {
return puja;
}
public void setPuja(Double puja) {
this.puja = puja;
}
public String getEstado() {
return estado;
}
public void setEstado(String estado) {
this.estado = estado;
}
public Boolean getVisible() {
return visible;
}
public void setVisible(Boolean visible) {
this.visible = visible;
}
public Remate getRemate() {
return remate;
}
public void setRemate(Remate remate) {
this.remate = remate;
}
public Cabana getCabana() {
return cabana;
}
public void setCabana(Cabana cabana) {
this.cabana = cabana;
}
}

View File

@@ -0,0 +1,86 @@
package com.example.fercoganbackend.entity;
import jakarta.persistence.*;
import java.time.LocalDateTime;
// Puja
@Entity
@Table(name = "pujas")
public class Puja {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private LocalDateTime fecha;
private Double monto;
private Boolean visible;
@ManyToOne
@JoinColumn(name = "usuario_id")
private Usuario usuario; // ya lo tienes
@ManyToOne
@JoinColumn(name = "cabana_id")
private Cabana cabana;
@ManyToOne
@JoinColumn(name = "lote_id")
private Lote lote;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public LocalDateTime getFecha() {
return fecha;
}
public void setFecha(LocalDateTime fecha) {
this.fecha = fecha;
}
public Double getMonto() {
return monto;
}
public void setMonto(Double monto) {
this.monto = monto;
}
public Boolean getVisible() {
return visible;
}
public void setVisible(Boolean visible) {
this.visible = visible;
}
public Usuario getUsuario() {
return usuario;
}
public void setUsuario(Usuario usuario) {
this.usuario = usuario;
}
public Cabana getCabana() {
return cabana;
}
public void setCabana(Cabana cabana) {
this.cabana = cabana;
}
public Lote getLote() {
return lote;
}
public void setLote(Lote lote) {
this.lote = lote;
}
}

View File

@@ -0,0 +1,80 @@
package com.example.fercoganbackend.entity;
import jakarta.persistence.*;
import java.time.LocalDate;
// Remate
@Entity
@Table(name = "remates")
public class Remate {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String nombre;
private LocalDate fecha;
private String urlListaLotes;
private String estado;
private Boolean visible;
@ManyToOne
@JoinColumn(name = "cabana_id")
private Cabana cabana;
//getter and setter
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getNombre() {
return nombre;
}
public void setNombre(String nombre) {
this.nombre = nombre;
}
public LocalDate getFecha() {
return fecha;
}
public void setFecha(LocalDate fecha) {
this.fecha = fecha;
}
public String getUrlListaLotes() {
return urlListaLotes;
}
public void setUrlListaLotes(String urlListaLotes) {
this.urlListaLotes = urlListaLotes;
}
public String getEstado() {
return estado;
}
public void setEstado(String estado) {
this.estado = estado;
}
public Boolean getVisible() {
return visible;
}
public void setVisible(Boolean visible) {
this.visible = visible;
}
public Cabana getCabana() {
return cabana;
}
public void setCabana(Cabana cabana) {
this.cabana = cabana;
}
}

View File

@@ -0,0 +1,7 @@
package com.example.fercoganbackend.repository;
import com.example.fercoganbackend.entity.Cabana;
import org.springframework.data.jpa.repository.JpaRepository;
public interface CabanaRepository extends JpaRepository<Cabana, Long> {}

View File

@@ -0,0 +1,6 @@
package com.example.fercoganbackend.repository;
import com.example.fercoganbackend.entity.Lote;
import org.springframework.data.jpa.repository.JpaRepository;
public interface LoteRepository extends JpaRepository<Lote, Long> {}

View File

@@ -0,0 +1,6 @@
package com.example.fercoganbackend.repository;
import com.example.fercoganbackend.entity.Puja;
import org.springframework.data.jpa.repository.JpaRepository;
public interface PujaRepository extends JpaRepository<Puja, Long> {}

View File

@@ -0,0 +1,6 @@
package com.example.fercoganbackend.repository;
import com.example.fercoganbackend.entity.Remate;
import org.springframework.data.jpa.repository.JpaRepository;
public interface RemateRepository extends JpaRepository<Remate, Long> {}

View File

@@ -0,0 +1,32 @@
package com.example.fercoganbackend.service;
import com.example.fercoganbackend.entity.Cabana;
import com.example.fercoganbackend.repository.CabanaRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Optional;
@Service
public class CabanaService {
@Autowired
private CabanaRepository cabanaRepository;
public List<Cabana> findAll() {
return cabanaRepository.findAll();
}
public Optional<Cabana> findById(Long id) {
return cabanaRepository.findById(id);
}
public Cabana save(Cabana remate) {
return cabanaRepository.save(remate);
}
public void delete(Long id) {
cabanaRepository.deleteById(id);
}
}

View File

@@ -0,0 +1,32 @@
package com.example.fercoganbackend.service;
import com.example.fercoganbackend.entity.Lote;
import com.example.fercoganbackend.repository.LoteRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Optional;
@Service
public class LoteService {
@Autowired
private LoteRepository loteRepository;
public List<Lote> findAll() {
return loteRepository.findAll();
}
public Optional<Lote> findById(Long id) {
return loteRepository.findById(id);
}
public Lote save(Lote remate) {
return loteRepository.save(remate);
}
public void delete(Long id) {
loteRepository.deleteById(id);
}
}

View File

@@ -0,0 +1,33 @@
package com.example.fercoganbackend.service;
import com.example.fercoganbackend.entity.Puja;
import com.example.fercoganbackend.repository.PujaRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Optional;
@Service
public class PujaService {
@Autowired
private PujaRepository pujaRepository;
public List<Puja> findAll() {
return pujaRepository.findAll();
}
public Optional<Puja> findById(Long id) {
return pujaRepository.findById(id);
}
public Puja save(Puja remate) {
return pujaRepository.save(remate);
}
public void delete(Long id) {
pujaRepository.deleteById(id);
}
}

View File

@@ -0,0 +1,33 @@
package com.example.fercoganbackend.service;
import com.example.fercoganbackend.entity.Remate;
import com.example.fercoganbackend.repository.RemateRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Optional;
@Service
public class RemateService {
@Autowired
private RemateRepository remateRepository;
public List<Remate> findAll() {
return remateRepository.findAll();
}
public Optional<Remate> findById(Long id) {
return remateRepository.findById(id);
}
public Remate save(Remate remate) {
return remateRepository.save(remate);
}
public void delete(Long id) {
remateRepository.deleteById(id);
}
}

View File

@@ -11,6 +11,8 @@ import org.springframework.stereotype.Service;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.List;
@Service
public class UsuarioDetailsService implements UserDetailsService {
@@ -18,6 +20,7 @@ public class UsuarioDetailsService implements UserDetailsService {
private final UsuarioRepository usuarioRepository;
private final Logger logger = LoggerFactory.getLogger(UsuarioDetailsService.class);
public UsuarioDetailsService(UsuarioRepository usuarioRepository) {
this.usuarioRepository = usuarioRepository;
}

View File

@@ -13,6 +13,9 @@ public class UsuarioService {
private final UsuarioRepository repo;
private final PasswordEncoder encoder;
public List<Usuario> getAll(){
return repo.findAll();
}
public UsuarioService(UsuarioRepository repo, PasswordEncoder encoder) {
this.repo = repo;
this.encoder = encoder;