90 lines
3.8 KiB
Java
90 lines
3.8 KiB
Java
package com.pmumali.plr.controllers;
|
|
|
|
import java.net.URI;
|
|
import java.util.List;
|
|
|
|
import org.springframework.http.ResponseEntity;
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
import org.springframework.web.bind.annotation.PathVariable;
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
import com.pmumali.plr.dtos.PariDto;
|
|
import com.pmumali.plr.enums.PariType;
|
|
import com.pmumali.plr.models.Pari;
|
|
import com.pmumali.plr.services.PariService;
|
|
|
|
import io.swagger.v3.oas.annotations.Operation;
|
|
import lombok.AllArgsConstructor;
|
|
import lombok.Data;
|
|
|
|
@RestController
|
|
@RequestMapping("/api/paris")
|
|
@Data
|
|
@AllArgsConstructor
|
|
public class PariController {
|
|
private final PariService pariService;
|
|
|
|
@Operation(summary = "Placer un pari")
|
|
@PostMapping
|
|
public ResponseEntity<PariDto> create(@RequestBody PariDto dto) {
|
|
Pari p = pariService.create(dto.courseId(), dto.chevalId(), dto.pariType(), dto.mise(), dto.bettorRef());
|
|
PariDto response = new PariDto(p.getId(), p.getCourse().getId(), p.getCheval().getId(), p.getPariType(),
|
|
p.getMise(), p.getBettorRef());
|
|
return ResponseEntity.created(URI.create("/api/paris/" + p.getId())).body(response);
|
|
}
|
|
|
|
@Operation(summary = "Lister tous les paris")
|
|
@GetMapping
|
|
public ResponseEntity<List<PariDto>> all() {
|
|
List<PariDto> list = pariService.all().stream()
|
|
.map(h -> new PariDto(h.getId(), h.getCourse().getId(), h.getCheval().getId(), h.getPariType(),
|
|
h.getMise(), h.getBettorRef()))
|
|
.toList();
|
|
return ResponseEntity.ok(list);
|
|
}
|
|
|
|
@Operation(summary = "Récupérer un pari par id")
|
|
@GetMapping("/{id}")
|
|
public ResponseEntity<PariDto> one(@PathVariable Long id) {
|
|
Pari p = pariService.get(id);
|
|
PariDto dto = new PariDto(p.getId(), p.getCourse().getId(), p.getCheval().getId(), p.getPariType(), p.getMise(),
|
|
p.getBettorRef());
|
|
return ResponseEntity.ok(dto);
|
|
}
|
|
|
|
// Recherche par type (ex: SIMPLE_GAGNANT)
|
|
@Operation(summary = "Lister les paris par type")
|
|
@GetMapping("/type/{pariType}")
|
|
public ResponseEntity<List<PariDto>> getAllByPariType(@PathVariable PariType pariType) {
|
|
List<PariDto> list = pariService.getParisByPariType(pariType).stream()
|
|
.map(h -> new PariDto(h.getId(), h.getCourse().getId(), h.getCheval().getId(), h.getPariType(),
|
|
h.getMise(), h.getBettorRef()))
|
|
.toList();
|
|
return ResponseEntity.ok(list);
|
|
}
|
|
|
|
// Recherche par course et type
|
|
@Operation(summary = "Lister les paris par course + type")
|
|
@GetMapping("/course/{courseId}/type/{pariType}")
|
|
public ResponseEntity<List<PariDto>> getByCourseAndType(@PathVariable Long courseId,
|
|
@PathVariable PariType pariType) {
|
|
List<PariDto> list = pariService.getParisByCourseAndType(courseId, pariType).stream()
|
|
.map(h -> new PariDto(h.getId(), h.getCourse().getId(), h.getCheval().getId(), h.getPariType(),
|
|
h.getMise(), h.getBettorRef()))
|
|
.toList();
|
|
return ResponseEntity.ok(list);
|
|
}
|
|
|
|
// Somme des mises d'une course / type (utile pour calculs de pools)
|
|
@Operation(summary = "Total des mises pour une course et un type de pari")
|
|
@GetMapping("/course/{courseId}/type/{pariType}/sum")
|
|
public ResponseEntity<java.math.BigDecimal> sumMises(@PathVariable Long courseId, @PathVariable PariType pariType) {
|
|
java.math.BigDecimal total = pariService.sumMiseByCourseIdAndPariType(courseId, pariType);
|
|
return ResponseEntity.ok(total);
|
|
}
|
|
|
|
}
|