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:
@@ -2,19 +2,28 @@ package com.example.fercoganbackend.controller;
|
|||||||
|
|
||||||
import com.example.fercoganbackend.component.ContadorWebSocketHandler;
|
import com.example.fercoganbackend.component.ContadorWebSocketHandler;
|
||||||
import com.example.fercoganbackend.dto.CorregirRequest;
|
import com.example.fercoganbackend.dto.CorregirRequest;
|
||||||
|
import com.example.fercoganbackend.entity.Puja;
|
||||||
import com.example.fercoganbackend.service.ContadorService;
|
import com.example.fercoganbackend.service.ContadorService;
|
||||||
|
import com.example.fercoganbackend.service.PujaService;
|
||||||
|
import jakarta.persistence.EntityNotFoundException;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/contador")
|
@RequestMapping("/contador")
|
||||||
public class ContadorController {
|
public class ContadorController {
|
||||||
private final ContadorService contadorService;
|
private final ContadorService contadorService;
|
||||||
private final ContadorWebSocketHandler webSocketHandler;
|
private final ContadorWebSocketHandler webSocketHandler;
|
||||||
|
private final PujaService pujaService;
|
||||||
|
|
||||||
public ContadorController(ContadorService contadorService,
|
public ContadorController(
|
||||||
ContadorWebSocketHandler webSocketHandler) {
|
ContadorService contadorService,
|
||||||
|
ContadorWebSocketHandler webSocketHandler,
|
||||||
|
PujaService pujaService) {
|
||||||
this.contadorService = contadorService;
|
this.contadorService = contadorService;
|
||||||
this.webSocketHandler = webSocketHandler;
|
this.webSocketHandler = webSocketHandler;
|
||||||
|
this.pujaService = pujaService;
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/incrementar/{remate}/{lote}")
|
@PostMapping("/incrementar/{remate}/{lote}")
|
||||||
@@ -46,20 +55,41 @@ public class ContadorController {
|
|||||||
return valor;
|
return valor;
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/corregir/{remate}/{lote}")
|
@PutMapping("/corregir/pujaid/{id}/remateid/{remate}/loteid/{lote}")
|
||||||
public int corregirValor(
|
public int corregirValor(
|
||||||
|
@PathVariable Long id,
|
||||||
@PathVariable String remate,
|
@PathVariable String remate,
|
||||||
@PathVariable String lote,
|
@PathVariable String lote,
|
||||||
@RequestBody CorregirRequest request) {
|
@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;
|
String roomKey = remate + "-" + lote;
|
||||||
int nuevoValor = request.getNuevoValor();
|
int nuevoValor = request.getNuevoValor();
|
||||||
|
|
||||||
contadorService.setContador(roomKey, nuevoValor);
|
contadorService.setContador(roomKey, nuevoValor);
|
||||||
|
|
||||||
|
// Notificar a clientes vía WebSocket
|
||||||
webSocketHandler.broadcastToRoom(remate, lote, String.valueOf(nuevoValor));
|
webSocketHandler.broadcastToRoom(remate, lote, String.valueOf(nuevoValor));
|
||||||
|
|
||||||
|
// Retornar el nuevo valor
|
||||||
return nuevoValor;
|
return nuevoValor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -7,6 +7,7 @@ import org.springframework.http.ResponseEntity;
|
|||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/api/pujas")
|
@RequestMapping("/api/pujas")
|
||||||
@@ -38,7 +39,7 @@ public class PujaController {
|
|||||||
|
|
||||||
//get coincidir con lote y remate
|
//get coincidir con lote y remate
|
||||||
@GetMapping("/loteyremate/{loteId}/{remateId}")
|
@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);
|
return pujaService.findForLoteAndRemate(loteId,remateId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import org.springframework.data.jpa.repository.Query;
|
|||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
public interface PujaRepository extends JpaRepository<Puja, Long> {
|
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);
|
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(
|
List<Puja> findByLote_IdAndLote_Remate_IdAndFechaAfter(
|
||||||
Long loteId,
|
Long loteId,
|
||||||
Long remateId,
|
Long remateId,
|
||||||
|
|||||||
@@ -40,8 +40,12 @@ public class PujaService {
|
|||||||
return pujaRepository.findByLote_Remate_Id(id);
|
return pujaRepository.findByLote_Remate_Id(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Puja> findForLoteAndRemate(Long loteId, Long remateId){
|
public List<Puja> findForLoteAndRemate( Long loteId, Long remateId){
|
||||||
return pujaRepository.findByLote_IdAndLote_Remate_Id(loteId,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){
|
public List<Puja> findForLoteAndRemateAndDate(Long loteId, Long remateId, LocalDateTime fecha){
|
||||||
|
|||||||
Reference in New Issue
Block a user