arreglamos pujaaaaa, ahora se puede editar las pujas sin problemas, antes no guardaba los cambios de las puja solo actualizaba el socket, ahora los datos persisten

This commit is contained in:
2025-12-24 10:03:32 -04:00
parent f80add65dd
commit e5b699945c
4 changed files with 45 additions and 7 deletions

View File

@@ -2,19 +2,28 @@ package com.example.fercoganbackend.controller;
import com.example.fercoganbackend.component.ContadorWebSocketHandler;
import com.example.fercoganbackend.dto.CorregirRequest;
import com.example.fercoganbackend.entity.Puja;
import com.example.fercoganbackend.service.ContadorService;
import com.example.fercoganbackend.service.PujaService;
import jakarta.persistence.EntityNotFoundException;
import org.springframework.web.bind.annotation.*;
import java.util.Optional;
@RestController
@RequestMapping("/contador")
public class ContadorController {
private final ContadorService contadorService;
private final ContadorWebSocketHandler webSocketHandler;
private final PujaService pujaService;
public ContadorController(ContadorService contadorService,
ContadorWebSocketHandler webSocketHandler) {
public ContadorController(
ContadorService contadorService,
ContadorWebSocketHandler webSocketHandler,
PujaService pujaService) {
this.contadorService = contadorService;
this.webSocketHandler = webSocketHandler;
this.pujaService = pujaService;
}
@PostMapping("/incrementar/{remate}/{lote}")
@@ -46,20 +55,41 @@ public class ContadorController {
return valor;
}
@PostMapping("/corregir/{remate}/{lote}")
@PutMapping("/corregir/pujaid/{id}/remateid/{remate}/loteid/{lote}")
public int corregirValor(
@PathVariable Long id,
@PathVariable String remate,
@PathVariable String lote,
@RequestBody CorregirRequest request) {
// Convertir IDs de String a Long
Long remateId = Long.valueOf(remate);
Long loteId = Long.valueOf(lote);
// Buscar la puja correspondiente por lote y remate
Puja puja = pujaService.findForIdAndLoteAndRemate(id, loteId, remateId)
.orElseThrow(() ->
new EntityNotFoundException(
"No existe puja para remate " + remate + " y lote " + lote
)
);
// Actualizar el monto de la puja y persistir
puja.setMonto((double) request.getNuevoValor());
pujaService.save(puja);
// Actualizar contador en memoria
String roomKey = remate + "-" + lote;
int nuevoValor = request.getNuevoValor();
contadorService.setContador(roomKey, nuevoValor);
// Notificar a clientes vía WebSocket
webSocketHandler.broadcastToRoom(remate, lote, String.valueOf(nuevoValor));
// Retornar el nuevo valor
return nuevoValor;
}
}

View File

@@ -7,6 +7,7 @@ import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.Optional;
@RestController
@RequestMapping("/api/pujas")
@@ -38,7 +39,7 @@ public class PujaController {
//get coincidir con lote y remate
@GetMapping("/loteyremate/{loteId}/{remateId}")
public List<Puja> getForLoteAndRemate(@PathVariable Long loteId,@PathVariable Long remateId){
public List<Puja> getForLoteAndRemate(@PathVariable Long loteId, @PathVariable Long remateId){
return pujaService.findForLoteAndRemate(loteId,remateId);
}

View File

@@ -7,6 +7,7 @@ import org.springframework.data.jpa.repository.Query;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Optional;
public interface PujaRepository extends JpaRepository<Puja, Long> {
@@ -14,6 +15,8 @@ public interface PujaRepository extends JpaRepository<Puja, Long> {
List<Puja> findByLote_IdAndLote_Remate_Id(Long loteId, Long remateId);
Optional<Puja> findByIdAndLote_IdAndLote_Remate_Id(Long id, Long loteId, Long remateId);
List<Puja> findByLote_IdAndLote_Remate_IdAndFechaAfter(
Long loteId,
Long remateId,

View File

@@ -40,8 +40,12 @@ public class PujaService {
return pujaRepository.findByLote_Remate_Id(id);
}
public List<Puja> findForLoteAndRemate(Long loteId, Long remateId){
return pujaRepository.findByLote_IdAndLote_Remate_Id(loteId,remateId);
public List<Puja> findForLoteAndRemate( Long loteId, Long remateId){
return pujaRepository.findByLote_IdAndLote_Remate_Id( loteId,remateId);
}
public Optional<Puja> findForIdAndLoteAndRemate(Long Id, Long loteId, Long remateId){
return pujaRepository.findByIdAndLote_IdAndLote_Remate_Id( Id, loteId,remateId);
}
public List<Puja> findForLoteAndRemateAndDate(Long loteId, Long remateId, LocalDateTime fecha){