implemented models and logic for Cheval, Course, CourseCheval and Pari.
This commit is contained in:
13
src/main/java/com/pmumali/plr/PlrApplication.java
Normal file
13
src/main/java/com/pmumali/plr/PlrApplication.java
Normal file
@@ -0,0 +1,13 @@
|
||||
package com.pmumali.plr;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication
|
||||
public class PlrApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(PlrApplication.class, args);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
package com.pmumali.plr.controllers;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
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.PutMapping;
|
||||
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.ChevalDto;
|
||||
import com.pmumali.plr.models.Cheval;
|
||||
import com.pmumali.plr.services.ChevalService;
|
||||
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@RestController
|
||||
@RequestMapping("/api/chevaux")
|
||||
public class ChevalController {
|
||||
private final ChevalService chevalService;
|
||||
|
||||
@Operation(summary = "Créer un cheval")
|
||||
@PostMapping
|
||||
public ResponseEntity<ChevalDto> create(@RequestBody ChevalDto dto) {
|
||||
Cheval ch = new Cheval();
|
||||
ch.setNom(dto.nom());
|
||||
ch.setNumero(dto.numero());
|
||||
ch.setNomEcurie(dto.nomEcurie());
|
||||
ch.setBirthYear(dto.birthYear());
|
||||
|
||||
ch = chevalService.create(ch);
|
||||
|
||||
ChevalDto response = new ChevalDto(ch.getId(), ch.getNom(), ch.getNumero(), ch.getNomEcurie(),
|
||||
ch.getBirthYear());
|
||||
return ResponseEntity.created(URI.create("/api/chevaux/" + ch.getId())).body(response);
|
||||
}
|
||||
|
||||
@Operation(summary = "Lister tous les chevaux")
|
||||
@GetMapping
|
||||
public ResponseEntity<List<ChevalDto>> all() {
|
||||
List<ChevalDto> list = chevalService.all().stream()
|
||||
.map(h -> new ChevalDto(h.getId(), h.getNom(), h.getNumero(), h.getNomEcurie(), h.getBirthYear()))
|
||||
.toList();
|
||||
return ResponseEntity.ok(list);
|
||||
}
|
||||
|
||||
@Operation(summary = "Récupérer un cheval par id")
|
||||
@GetMapping("/{id}")
|
||||
public ResponseEntity<ChevalDto> one(@PathVariable Long id) {
|
||||
Cheval h = chevalService.get(id);
|
||||
ChevalDto dto = new ChevalDto(h.getId(), h.getNom(), h.getNumero(), h.getNomEcurie(), h.getBirthYear());
|
||||
return ResponseEntity.ok(dto);
|
||||
}
|
||||
|
||||
@Operation(summary = "Mettre à jour un cheval")
|
||||
@PutMapping("/{id}")
|
||||
public ResponseEntity<ChevalDto> update(@PathVariable Long id, @RequestBody ChevalDto dto) {
|
||||
Cheval ch = new Cheval();
|
||||
ch.setNom(dto.nom());
|
||||
ch.setNumero(dto.numero());
|
||||
ch.setNomEcurie(dto.nomEcurie());
|
||||
ch.setBirthYear(dto.birthYear());
|
||||
|
||||
ch = chevalService.update(id, ch);
|
||||
ChevalDto response = new ChevalDto(ch.getId(), ch.getNom(), ch.getNumero(), ch.getNomEcurie(),
|
||||
ch.getBirthYear());
|
||||
return ResponseEntity.ok(response);
|
||||
}
|
||||
|
||||
@Operation(summary = "Supprimer un cheval")
|
||||
@DeleteMapping("/{id}")
|
||||
public ResponseEntity<Void> delete(@PathVariable Long id) {
|
||||
chevalService.delete(id);
|
||||
return ResponseEntity.noContent().build();
|
||||
}
|
||||
}
|
||||
221
src/main/java/com/pmumali/plr/controllers/CourseController.java
Normal file
221
src/main/java/com/pmumali/plr/controllers/CourseController.java
Normal file
@@ -0,0 +1,221 @@
|
||||
package com.pmumali.plr.controllers;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.springframework.dao.DataIntegrityViolationException;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
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.PutMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.pmumali.plr.dtos.BulkChevalCourseRequest;
|
||||
import com.pmumali.plr.dtos.ChevalCourseDto;
|
||||
import com.pmumali.plr.dtos.CourseDto;
|
||||
import com.pmumali.plr.enums.CourseStatue;
|
||||
import com.pmumali.plr.models.ChevalCourse;
|
||||
import com.pmumali.plr.models.Course;
|
||||
import com.pmumali.plr.services.CourseService;
|
||||
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/courses")
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
public class CourseController {
|
||||
private final CourseService courseService;
|
||||
|
||||
@Operation(summary = "Créer une course")
|
||||
@PostMapping
|
||||
public ResponseEntity<CourseDto> create(@RequestBody CourseDto dto) {
|
||||
Course c = new Course();
|
||||
|
||||
c.setNom(dto.nom());
|
||||
c.setLieu(dto.lieu());
|
||||
c.setDepartureDateTime(dto.departureDateTime());
|
||||
c.setStatus(dto.status());
|
||||
|
||||
c = courseService.create(c);
|
||||
CourseDto result = new CourseDto(c.getId(), c.getNom(), c.getLieu(), c.getDepartureDateTime(), c.getStatus());
|
||||
|
||||
return ResponseEntity.created(URI.create("/api/courses/" + c.getId())).body(result);
|
||||
}
|
||||
|
||||
/** GET /api/courses - list all or filter by status ?status=PLANIFIEE */
|
||||
@Operation(summary = "Récupérer une course par son id")
|
||||
@GetMapping("{id}")
|
||||
public ResponseEntity<CourseDto> getCourse(
|
||||
@PathVariable Long id) {
|
||||
Course course = courseService.get(id);
|
||||
CourseDto response = new CourseDto(course.getId(), course.getNom(), course.getLieu(),
|
||||
course.getDepartureDateTime(), course.getStatus());
|
||||
return ResponseEntity.ok(response);
|
||||
}
|
||||
|
||||
/** GET /api/courses - list all or filter by status ?status=PLANIFIEE */
|
||||
@Operation(summary = "Lister tous les courses filtrer ou non par le statue")
|
||||
@GetMapping
|
||||
public ResponseEntity<List<CourseDto>> listAll(
|
||||
@RequestParam(value = "status", required = false) CourseStatue status) {
|
||||
List<Course> courses = (status == null) ? courseService.getAllCourses()
|
||||
: courseService.getCoursesByStatus(status);
|
||||
|
||||
List<CourseDto> dtos = courses.stream()
|
||||
.map(c -> new CourseDto(c.getId(), c.getNom(), c.getLieu(), c.getDepartureDateTime(), c.getStatus()))
|
||||
.toList();
|
||||
|
||||
return ResponseEntity.ok(dtos);
|
||||
}
|
||||
|
||||
/** PUT /api/courses/{id} - update course */
|
||||
@Operation(summary = "Mettre à jour une course")
|
||||
@PutMapping("/{id}")
|
||||
public ResponseEntity<CourseDto> editCourse(@PathVariable Long id, @RequestBody CourseDto dto) {
|
||||
// Build a Course entity from incoming DTO (only filled fields will be applied)
|
||||
Course update = new Course();
|
||||
update.setNom(dto.nom());
|
||||
update.setLieu(dto.lieu());
|
||||
update.setDepartureDateTime(dto.departureDateTime());
|
||||
update.setStatus(dto.status());
|
||||
|
||||
Course updated = courseService.updateCourse(id, update);
|
||||
|
||||
CourseDto result = new CourseDto(updated.getId(), updated.getNom(), updated.getLieu(),
|
||||
updated.getDepartureDateTime(), updated.getStatus());
|
||||
return ResponseEntity.ok(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* DELETE /api/courses/{id}
|
||||
* - default soft delete (cancels the race)
|
||||
* - pass ?hard=true to attempt a hard delete (physical removal)
|
||||
*/
|
||||
@Operation(summary = "Supprimer une course")
|
||||
@DeleteMapping("/{id}")
|
||||
public ResponseEntity<?> deleteCourse(@PathVariable Long id,
|
||||
@RequestParam(value = "hard", required = false, defaultValue = "false") boolean hard) {
|
||||
try {
|
||||
courseService.deleteCourse(id, hard);
|
||||
if (!hard) {
|
||||
// return the cancelled course representation
|
||||
Course c = courseService.get(id);
|
||||
CourseDto dto = new CourseDto(c.getId(), c.getNom(), c.getLieu(), c.getDepartureDateTime(),
|
||||
c.getStatus());
|
||||
return ResponseEntity.ok(dto);
|
||||
} else {
|
||||
// hard delete succeeded: no content
|
||||
return ResponseEntity.noContent().build();
|
||||
}
|
||||
} catch (DataIntegrityViolationException ex) {
|
||||
return ResponseEntity.status(409).body(java.util.Collections.singletonMap("error", ex.getMessage()));
|
||||
}
|
||||
}
|
||||
|
||||
// Ajout d'un cheval à la course -> POST /api/courses/{id}/chevaux
|
||||
@Operation(summary = "Ajouter un cheval à une course")
|
||||
@PostMapping("/{id}/chevaux")
|
||||
public ResponseEntity<ChevalCourseDto> ajouterCheval(@PathVariable Long id, @RequestBody ChevalCourseDto dto) {
|
||||
ChevalCourse rh = courseService.ajouterCheval(id, dto.chevalId(), dto.numeroCheval());
|
||||
|
||||
ChevalCourseDto response = new ChevalCourseDto(
|
||||
rh.getId(),
|
||||
rh.getCourse().getId(),
|
||||
rh.getCheval().getId(),
|
||||
rh.getNumeroCheval(),
|
||||
rh.getNonPartant(),
|
||||
rh.getEstDisqualifie());
|
||||
|
||||
return ResponseEntity.created(URI.create("/api/courses/" + id + "/chevaux/" + rh.getId())).body(response);
|
||||
}
|
||||
|
||||
@Operation(summary = "Ajouter des chevaux à une course")
|
||||
@PostMapping("/{id}/chevaux/bulk")
|
||||
public ResponseEntity<?> bulkAddChevaux(@PathVariable("id") Long id, @RequestBody BulkChevalCourseRequest request) {
|
||||
try {
|
||||
List<ChevalCourse> saved = courseService.ajouterChevauxBulk(id, request);
|
||||
|
||||
List<ChevalCourseDto> dtos = saved.stream()
|
||||
.map(rh -> new ChevalCourseDto(rh.getId(), rh.getCourse().getId(), rh.getCheval().getId(),
|
||||
rh.getNumeroCheval(), rh.getNonPartant(), rh.getEstDisqualifie()))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
return ResponseEntity.created(URI.create("/api/courses/" + id + "/chevaux")).body(dtos);
|
||||
} catch (IllegalArgumentException e) {
|
||||
// doublons dans la requête
|
||||
return ResponseEntity.badRequest().body(Map.of("error", e.getMessage()));
|
||||
} catch (DataIntegrityViolationException e) {
|
||||
// conflit avec la DB (numéro déjà utilisé, contrainte unique)
|
||||
return ResponseEntity.status(409).body(Map.of("error", e.getMessage()));
|
||||
}
|
||||
}
|
||||
|
||||
// Lister les inscriptions d'une course
|
||||
@Operation(summary = "Lister les chevaux inscrits à une course")
|
||||
@GetMapping("/{id}/chevaux")
|
||||
public List<ChevalCourseDto> listChevaux(@PathVariable Long id) {
|
||||
return courseService.getInscriptions(id).stream()
|
||||
.map(rh -> new ChevalCourseDto(rh.getId(), rh.getCourse().getId(), rh.getCheval().getId(),
|
||||
rh.getNumeroCheval(), rh.getNonPartant(), rh.getEstDisqualifie()))
|
||||
.toList();
|
||||
}
|
||||
|
||||
// Marquer un cheval comme non-partant (scratch)
|
||||
@Operation(summary = "Marquer un cheval comme non-partant (NP) à une course")
|
||||
@PutMapping("/cheval-course/{chevalCourseId}/scratch")
|
||||
public ResponseEntity<Void> scratch(@PathVariable Long chevalCourseId, @RequestParam boolean value) {
|
||||
courseService.estNonPartant(chevalCourseId, value);
|
||||
return ResponseEntity.noContent().build();
|
||||
}
|
||||
|
||||
// Déclarer disqualifié
|
||||
@Operation(summary = "Déclarer un cheval comme disqualifié à une course")
|
||||
@PutMapping("/cheval-course/{chevalCourseId}/disqualify")
|
||||
public ResponseEntity<Void> disqualify(@PathVariable Long chevalCourseId, @RequestParam boolean value) {
|
||||
courseService.declarerDisqualifie(chevalCourseId, value);
|
||||
return ResponseEntity.noContent().build();
|
||||
}
|
||||
|
||||
// Supprimer inscription
|
||||
@Operation(summary = "Supprimer un cheval inscrit d'une course")
|
||||
@DeleteMapping("/cheval-course/{chevalCourseId}")
|
||||
public ResponseEntity<Void> removeInscription(@PathVariable Long chevalCourseId) {
|
||||
courseService.removeChevalFromCourse(chevalCourseId);
|
||||
return ResponseEntity.noContent().build();
|
||||
}
|
||||
|
||||
// Autres endpoints utiles : counts
|
||||
@Operation(summary = "Compter les chevaux non-partants à une course")
|
||||
@GetMapping("/{id}/counts/non-partants")
|
||||
public int countNonPartants(@PathVariable Long id) {
|
||||
return courseService.countNonPartants(id);
|
||||
}
|
||||
|
||||
@Operation(summary = "Compter les chevaux partants à une course")
|
||||
@GetMapping("/{id}/counts/valid-participants")
|
||||
public int countValidParticipants(@PathVariable Long id) {
|
||||
return courseService.countValidParticipants(id);
|
||||
}
|
||||
|
||||
@Operation(summary = "Lister les course par statue (PLANIFIEE, EN_COURS, CLOTUREE, ANNULEE)")
|
||||
@GetMapping("/status/{status}")
|
||||
public ResponseEntity<List<CourseDto>> getCoursesByStatus(@PathVariable("status") CourseStatue status) {
|
||||
List<Course> courses = courseService.getCoursesByCourseStatue(status);
|
||||
|
||||
List<CourseDto> dtos = courses.stream()
|
||||
.map(c -> new CourseDto(c.getId(), c.getNom(), c.getLieu(), c.getDepartureDateTime(), c.getStatus()))
|
||||
.toList();
|
||||
|
||||
return ResponseEntity.ok(dtos);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package com.pmumali.plr.dtos;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public record BulkChevalCourseRequest(List<ChevalEntry> entries) {
|
||||
public static record ChevalEntry(Long chevalId, Integer numeroCheval) {
|
||||
}
|
||||
}
|
||||
3
src/main/java/com/pmumali/plr/dtos/ChevalCourseDto.java
Normal file
3
src/main/java/com/pmumali/plr/dtos/ChevalCourseDto.java
Normal file
@@ -0,0 +1,3 @@
|
||||
package com.pmumali.plr.dtos;
|
||||
|
||||
public record ChevalCourseDto(Long id, Long courseId, Long chevalId, Integer numeroCheval, Boolean nonPartant, Boolean estDisqualifie) {}
|
||||
@@ -0,0 +1,3 @@
|
||||
package com.pmumali.plr.dtos;
|
||||
|
||||
public record ChevalCourseEstDisqualifie(Long chevalId, Boolean estDisqualifie) {}
|
||||
@@ -0,0 +1,3 @@
|
||||
package com.pmumali.plr.dtos;
|
||||
|
||||
public record ChevalCourseNonPartantDto(Long chevalId, Integer nonPartant) {}
|
||||
@@ -0,0 +1,3 @@
|
||||
package com.pmumali.plr.dtos;
|
||||
|
||||
public record ChevalCourseNonPartantEtEstDisqualifie(Long chevalId, Boolean nonPartant, Boolean estDisqualifie) {}
|
||||
3
src/main/java/com/pmumali/plr/dtos/ChevalDto.java
Normal file
3
src/main/java/com/pmumali/plr/dtos/ChevalDto.java
Normal file
@@ -0,0 +1,3 @@
|
||||
package com.pmumali.plr.dtos;
|
||||
|
||||
public record ChevalDto(Long id, String nom, Integer numero, String nomEcurie, Integer birthYear) {}
|
||||
7
src/main/java/com/pmumali/plr/dtos/CourseDto.java
Normal file
7
src/main/java/com/pmumali/plr/dtos/CourseDto.java
Normal file
@@ -0,0 +1,7 @@
|
||||
package com.pmumali.plr.dtos;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
import com.pmumali.plr.enums.CourseStatue;
|
||||
|
||||
public record CourseDto(Long id, String nom, String lieu, LocalDateTime departureDateTime, CourseStatue status){}
|
||||
7
src/main/java/com/pmumali/plr/dtos/PariDto.java
Normal file
7
src/main/java/com/pmumali/plr/dtos/PariDto.java
Normal file
@@ -0,0 +1,7 @@
|
||||
package com.pmumali.plr.dtos;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
import com.pmumali.plr.enums.PariType;
|
||||
|
||||
public record PariDto(Long id, Long courseId, Long chevalId, PariType pariType, BigDecimal mise, String bettorRef) {}
|
||||
5
src/main/java/com/pmumali/plr/enums/CourseStatue.java
Normal file
5
src/main/java/com/pmumali/plr/enums/CourseStatue.java
Normal file
@@ -0,0 +1,5 @@
|
||||
package com.pmumali.plr.enums;
|
||||
|
||||
public enum CourseStatue {
|
||||
PLANIFIEE, EN_COURS, CLOTUREE, ANNULEE
|
||||
}
|
||||
5
src/main/java/com/pmumali/plr/enums/PariType.java
Normal file
5
src/main/java/com/pmumali/plr/enums/PariType.java
Normal file
@@ -0,0 +1,5 @@
|
||||
package com.pmumali.plr.enums;
|
||||
|
||||
public enum PariType {
|
||||
SIMPLE_GAGNANT, SIMPLE_PLACE
|
||||
}
|
||||
30
src/main/java/com/pmumali/plr/models/BaseEntite.java
Normal file
30
src/main/java/com/pmumali/plr/models/BaseEntite.java
Normal file
@@ -0,0 +1,30 @@
|
||||
package com.pmumali.plr.models;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.GeneratedValue;
|
||||
import jakarta.persistence.GenerationType;
|
||||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.MappedSuperclass;
|
||||
import jakarta.persistence.PreUpdate;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@MappedSuperclass
|
||||
public abstract class BaseEntite {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
protected Long id;
|
||||
|
||||
@Column(name="created_at")
|
||||
protected LocalDateTime createdAt = LocalDateTime.now();
|
||||
|
||||
@Column(name="updated_at")
|
||||
protected LocalDateTime updatedAt = LocalDateTime.now();
|
||||
|
||||
@PreUpdate protected void onUpdate()
|
||||
{
|
||||
this.updatedAt = LocalDateTime.now();
|
||||
}
|
||||
}
|
||||
26
src/main/java/com/pmumali/plr/models/Cheval.java
Normal file
26
src/main/java/com/pmumali/plr/models/Cheval.java
Normal file
@@ -0,0 +1,26 @@
|
||||
package com.pmumali.plr.models;
|
||||
|
||||
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.Entity;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
|
||||
@Entity
|
||||
@Data
|
||||
@Getter
|
||||
@Setter
|
||||
@EqualsAndHashCode(callSuper=false)
|
||||
public class Cheval extends BaseEntite {
|
||||
private String nom;
|
||||
|
||||
private Integer numero;
|
||||
|
||||
private String nomEcurie;
|
||||
|
||||
@Column(name = "birth_year")
|
||||
private Integer birthYear;
|
||||
}
|
||||
39
src/main/java/com/pmumali/plr/models/ChevalCourse.java
Normal file
39
src/main/java/com/pmumali/plr/models/ChevalCourse.java
Normal file
@@ -0,0 +1,39 @@
|
||||
package com.pmumali.plr.models;
|
||||
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.JoinColumn;
|
||||
import jakarta.persistence.ManyToOne;
|
||||
import jakarta.persistence.Table;
|
||||
import jakarta.persistence.UniqueConstraint;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
|
||||
@Entity
|
||||
@Table(
|
||||
name = "cheval_course",
|
||||
uniqueConstraints = @UniqueConstraint(name="uk_course_numero", columnNames = {"course_id","numero_cheval"})
|
||||
)
|
||||
@Data
|
||||
@Getter
|
||||
@Setter
|
||||
@EqualsAndHashCode(callSuper=false)
|
||||
public class ChevalCourse extends BaseEntite {
|
||||
@ManyToOne(optional = false) @JoinColumn(name="course_id")
|
||||
private Course course;
|
||||
|
||||
@ManyToOne(optional = false) @JoinColumn(name="cheval_id")
|
||||
private Cheval cheval;
|
||||
|
||||
@Column(name="numero_cheval", nullable=false)
|
||||
private Integer numeroCheval;
|
||||
|
||||
@Column(name="non_partant", nullable=false)
|
||||
private Boolean nonPartant = false;
|
||||
|
||||
@Column(name="est_disqualifie", nullable=false)
|
||||
private Boolean estDisqualifie = false;
|
||||
}
|
||||
29
src/main/java/com/pmumali/plr/models/Course.java
Normal file
29
src/main/java/com/pmumali/plr/models/Course.java
Normal file
@@ -0,0 +1,29 @@
|
||||
package com.pmumali.plr.models;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
import com.pmumali.plr.enums.CourseStatue;
|
||||
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.Entity;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
|
||||
@Entity
|
||||
@Data
|
||||
@Getter
|
||||
@Setter
|
||||
@EqualsAndHashCode(callSuper=false)
|
||||
public class Course extends BaseEntite {
|
||||
private String nom;
|
||||
|
||||
private String lieu;
|
||||
|
||||
@Column(name="date_depart")
|
||||
private LocalDateTime departureDateTime;
|
||||
|
||||
private CourseStatue status = CourseStatue.PLANIFIEE;
|
||||
}
|
||||
33
src/main/java/com/pmumali/plr/models/Pari.java
Normal file
33
src/main/java/com/pmumali/plr/models/Pari.java
Normal file
@@ -0,0 +1,33 @@
|
||||
package com.pmumali.plr.models;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
import com.pmumali.plr.enums.PariType;
|
||||
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.ManyToOne;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Data
|
||||
@Entity
|
||||
@Getter
|
||||
@Setter
|
||||
@EqualsAndHashCode(callSuper=false)
|
||||
public class Pari extends BaseEntite {
|
||||
@ManyToOne(optional=false)
|
||||
private Course course;
|
||||
|
||||
@ManyToOne(optional=false)
|
||||
private Cheval cheval;
|
||||
|
||||
private PariType pariType;
|
||||
|
||||
@Column(nullable=false)
|
||||
private BigDecimal mise;
|
||||
|
||||
private String bettorRef;
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package com.pmumali.plr.repositories;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
import com.pmumali.plr.models.ChevalCourse;
|
||||
import com.pmumali.plr.models.Course;
|
||||
|
||||
public interface ChevalCourseRepository extends JpaRepository<ChevalCourse, Long> {
|
||||
// Retourne les chevaux non-partants pour une course
|
||||
List<ChevalCourse> findByCourseAndNonPartantTrue(Course course);
|
||||
|
||||
// Retourne les chevaux disqualifiés pour une course
|
||||
List<ChevalCourse> findByCourseAndEstDisqualifieTrue(Course course);
|
||||
|
||||
// Comptes
|
||||
int countByCourseAndNonPartantTrue(Course course);
|
||||
|
||||
int countByCourseAndEstDisqualifieTrue(Course course);
|
||||
|
||||
// Variantes avec param booléen si tu veux filtrer dynamiquement
|
||||
List<ChevalCourse> findByCourseAndNonPartant(Course course, Boolean nonPartant);
|
||||
|
||||
List<ChevalCourse> findByCourseAndEstDisqualifie(Course course, Boolean estDisqualifie);
|
||||
|
||||
// Exemples utiles déjà présents
|
||||
List<ChevalCourse> findByCourseAndNonPartantFalse(Course course);
|
||||
|
||||
int countByCourseAndNonPartantFalseAndEstDisqualifieFalse(Course course);
|
||||
|
||||
// Récupérer toutes les inscriptions (ordre par numéro cheval utile)
|
||||
List<ChevalCourse> findByCourseOrderByNumeroChevalAsc(Course course);
|
||||
|
||||
boolean existsByCourseAndNumeroCheval(Course course, Integer numeroCheval);
|
||||
|
||||
int countByCourse(Course course);
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package com.pmumali.plr.repositories;
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
import com.pmumali.plr.models.Cheval;
|
||||
|
||||
public interface ChevalRepository extends JpaRepository<Cheval, Long>{}
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.pmumali.plr.repositories;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
import com.pmumali.plr.enums.CourseStatue;
|
||||
import com.pmumali.plr.models.Course;
|
||||
|
||||
public interface CourseRepository extends JpaRepository<Course, Long> {
|
||||
List<Course> findByStatus(CourseStatue status);
|
||||
|
||||
List<Course> findByStatusNot(CourseStatue status);
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.pmumali.plr.repositories;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
|
||||
import com.pmumali.plr.enums.PariType;
|
||||
import com.pmumali.plr.models.Pari;
|
||||
|
||||
public interface PariRepository extends JpaRepository<Pari, Long> {
|
||||
List<Pari> findByCourseIdAndPariType(Long courseId, PariType pariType);
|
||||
|
||||
List<Pari> findByCourseIdAndPariTypeAndChevalId(Long courseId, PariType pariType, Long chevalId);
|
||||
|
||||
List<Pari> findByPariType(PariType pariType);
|
||||
|
||||
@Query("select coalesce(sum(p.mise),0) from Pari p where p.course.id=:courseId and p.pariType=:pariType")
|
||||
BigDecimal sumMiseByCourseIdAndPariType(Long courseId, PariType pariType);
|
||||
|
||||
@Query("select coalesce(sum(p.mise),0) from Pari p where p.course.id=:courseId and p.pariType=:pariType and p.cheval.id=:chevalId")
|
||||
BigDecimal sumMiseByCourseIdAndPariTypeAndChevalId(Long courseId, PariType pariType, Long chevalId);
|
||||
|
||||
int countByCourseId(Long courseId);
|
||||
}
|
||||
45
src/main/java/com/pmumali/plr/services/ChevalService.java
Normal file
45
src/main/java/com/pmumali/plr/services/ChevalService.java
Normal file
@@ -0,0 +1,45 @@
|
||||
package com.pmumali.plr.services;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.pmumali.plr.models.Cheval;
|
||||
import com.pmumali.plr.repositories.ChevalRepository;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
|
||||
@Service
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
public class ChevalService {
|
||||
private final ChevalRepository chevalRepository;
|
||||
|
||||
public Cheval create(Cheval cheval) {
|
||||
return chevalRepository.save(cheval);
|
||||
}
|
||||
|
||||
public List<Cheval> all(){
|
||||
return chevalRepository.findAll();
|
||||
}
|
||||
|
||||
public Cheval get(Long id){
|
||||
return chevalRepository.findById(id).orElseThrow();
|
||||
}
|
||||
|
||||
public Cheval update(Long id, Cheval data){
|
||||
Cheval h = get(id);
|
||||
|
||||
h.setNom(data.getNom());
|
||||
h.setNumero(data.getNumero());
|
||||
h.setNomEcurie(data.getNomEcurie());
|
||||
h.setBirthYear(data.getBirthYear());
|
||||
|
||||
return chevalRepository.save(h);
|
||||
}
|
||||
|
||||
public void delete(Long id){
|
||||
chevalRepository.deleteById(id);
|
||||
}
|
||||
}
|
||||
238
src/main/java/com/pmumali/plr/services/CourseService.java
Normal file
238
src/main/java/com/pmumali/plr/services/CourseService.java
Normal file
@@ -0,0 +1,238 @@
|
||||
package com.pmumali.plr.services;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.springframework.dao.DataIntegrityViolationException;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import com.pmumali.plr.dtos.BulkChevalCourseRequest;
|
||||
import com.pmumali.plr.enums.CourseStatue;
|
||||
import com.pmumali.plr.models.Cheval;
|
||||
import com.pmumali.plr.models.ChevalCourse;
|
||||
import com.pmumali.plr.models.Course;
|
||||
import com.pmumali.plr.repositories.ChevalCourseRepository;
|
||||
import com.pmumali.plr.repositories.ChevalRepository;
|
||||
import com.pmumali.plr.repositories.CourseRepository;
|
||||
import com.pmumali.plr.repositories.PariRepository;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
|
||||
@Service
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
public class CourseService {
|
||||
private final ChevalRepository chevalRepository;
|
||||
private final CourseRepository courseRepository;
|
||||
private final ChevalCourseRepository chevalCourseRepository;
|
||||
private final PariRepository pariRepository;
|
||||
|
||||
// Create a course
|
||||
public Course create(Course course) {
|
||||
return courseRepository.save(course);
|
||||
}
|
||||
|
||||
// Get a course by id
|
||||
public Course get(Long id) {
|
||||
return courseRepository.findById(id).orElseThrow();
|
||||
}
|
||||
|
||||
// Get all courses
|
||||
@Transactional(readOnly = true)
|
||||
public List<Course> getAllCourses() {
|
||||
return courseRepository.findAll();
|
||||
}
|
||||
|
||||
// Get all courses by statue
|
||||
@Transactional(readOnly = true)
|
||||
public List<Course> getCoursesByStatus(CourseStatue status) {
|
||||
return courseRepository.findByStatus(status);
|
||||
}
|
||||
|
||||
// Update a course
|
||||
@Transactional
|
||||
public Course updateCourse(Long id, Course data) {
|
||||
Course existing = get(id);
|
||||
|
||||
// Apply editable fields only
|
||||
if (Objects.nonNull(data.getNom()))
|
||||
existing.setNom(data.getNom());
|
||||
if (Objects.nonNull(data.getLieu()))
|
||||
existing.setLieu(data.getLieu());
|
||||
if (Objects.nonNull(data.getDepartureDateTime()))
|
||||
existing.setDepartureDateTime(data.getDepartureDateTime());
|
||||
if (Objects.nonNull(data.getStatus()))
|
||||
existing.setStatus(data.getStatus());
|
||||
|
||||
return courseRepository.save(existing);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void deleteCourse(Long id, boolean hard) {
|
||||
Course course = get(id);
|
||||
|
||||
if (!hard) {
|
||||
// soft delete: mark as canceled
|
||||
course.setStatus(CourseStatue.ANNULEE);
|
||||
courseRepository.save(course);
|
||||
return;
|
||||
}
|
||||
|
||||
// hard delete: check constraints
|
||||
int pariCount = pariRepository.countByCourseId(id);
|
||||
int inscriptionCount = chevalCourseRepository.countByCourse(course);
|
||||
|
||||
// optional: block if race already started or closed
|
||||
if (course.getStatus() == CourseStatue.EN_COURS || course.getStatus() == CourseStatue.CLOTUREE) {
|
||||
throw new DataIntegrityViolationException(
|
||||
"Cannot hard delete a course which is in progress or already closed.");
|
||||
}
|
||||
|
||||
if (pariCount > 0) {
|
||||
throw new DataIntegrityViolationException(
|
||||
"Cannot hard delete course: there are " + pariCount + " pari(s) linked to this course.");
|
||||
}
|
||||
|
||||
if (inscriptionCount > 0) {
|
||||
throw new DataIntegrityViolationException("Cannot hard delete course: there are " + inscriptionCount
|
||||
+ " cheval-course inscriptions linked to this course.");
|
||||
}
|
||||
|
||||
// safe to delete
|
||||
courseRepository.deleteById(id);
|
||||
}
|
||||
|
||||
// Get all horses by a course (asc)
|
||||
public List<ChevalCourse> getInscriptions(Long courseId) {
|
||||
Course course = get(courseId);
|
||||
return chevalCourseRepository.findByCourseOrderByNumeroChevalAsc(course);
|
||||
}
|
||||
|
||||
public List<ChevalCourse> getNonPartants(Long courseId) {
|
||||
Course course = get(courseId);
|
||||
return chevalCourseRepository.findByCourseAndNonPartantTrue(course);
|
||||
}
|
||||
|
||||
public int countNonPartants(Long courseId) {
|
||||
Course course = get(courseId);
|
||||
return chevalCourseRepository.countByCourseAndNonPartantTrue(course);
|
||||
}
|
||||
|
||||
public int countValidParticipants(Long courseId) {
|
||||
Course course = get(courseId);
|
||||
return chevalCourseRepository.countByCourseAndNonPartantFalseAndEstDisqualifieFalse(course);
|
||||
}
|
||||
|
||||
// Add a horse to a course
|
||||
@Transactional
|
||||
public ChevalCourse ajouterCheval(Long courseId, Long chevalId, Integer numeroCheval) {
|
||||
Course course = get(courseId);
|
||||
Cheval cheval = chevalRepository.findById(chevalId).orElseThrow();
|
||||
|
||||
ChevalCourse cc = new ChevalCourse();
|
||||
|
||||
cc.setCourse(course);
|
||||
cc.setCheval(cheval);
|
||||
cc.setNumeroCheval(numeroCheval);
|
||||
|
||||
return chevalCourseRepository.save(cc);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void estNonPartant(Long chevalCourseId, Boolean nonPartant) {
|
||||
ChevalCourse cc = chevalCourseRepository.findById(chevalCourseId).orElseThrow();
|
||||
|
||||
cc.setNonPartant(nonPartant);
|
||||
|
||||
chevalCourseRepository.save(cc);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void declarerDisqualifie(Long chevalCourseId, Boolean disqualifie) {
|
||||
ChevalCourse cc = chevalCourseRepository.findById(chevalCourseId).orElseThrow();
|
||||
|
||||
cc.setEstDisqualifie(disqualifie);
|
||||
|
||||
chevalCourseRepository.save(cc);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void removeChevalFromCourse(Long chevalCourseId) {
|
||||
chevalCourseRepository.deleteById(chevalCourseId);
|
||||
}
|
||||
|
||||
@Transactional(readOnly = true)
|
||||
public List<Course> getCoursesByCourseStatue(CourseStatue courseStatue) {
|
||||
return courseRepository.findByStatus(courseStatue);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public List<ChevalCourse> ajouterChevauxBulk(Long courseId, BulkChevalCourseRequest request) {
|
||||
Course course = courseRepository.findById(courseId).orElseThrow();
|
||||
|
||||
List<BulkChevalCourseRequest.ChevalEntry> entries = request.entries();
|
||||
if (entries == null || entries.isEmpty()) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
// 1) vérifier doublons dans la requête (par numeroCheval)
|
||||
Set<Integer> seenNum = new HashSet<>();
|
||||
List<Integer> duplicateNums = entries.stream()
|
||||
.map(BulkChevalCourseRequest.ChevalEntry::numeroCheval)
|
||||
.filter(Objects::nonNull)
|
||||
.filter(n -> !seenNum.add(n))
|
||||
.distinct()
|
||||
.collect(Collectors.toList());
|
||||
|
||||
if (!duplicateNums.isEmpty()) {
|
||||
throw new IllegalArgumentException("Duplicate numeroCheval in request: " + duplicateNums);
|
||||
}
|
||||
|
||||
// 2) vérifier si un numero est déjà utilisé dans la course
|
||||
List<Integer> numsToCheck = entries.stream()
|
||||
.map(BulkChevalCourseRequest.ChevalEntry::numeroCheval)
|
||||
.filter(Objects::nonNull)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
List<Integer> conflicts = numsToCheck.stream()
|
||||
.filter(n -> chevalCourseRepository.existsByCourseAndNumeroCheval(course, n))
|
||||
.distinct()
|
||||
.collect(Collectors.toList());
|
||||
|
||||
if (!conflicts.isEmpty()) {
|
||||
throw new DataIntegrityViolationException("Numero(s) already used for course: " + conflicts);
|
||||
}
|
||||
|
||||
// 3) Construire les entités ChevalCourse
|
||||
List<ChevalCourse> toSave = new ArrayList<>(entries.size());
|
||||
for (BulkChevalCourseRequest.ChevalEntry e : entries) {
|
||||
Long chevalId = e.chevalId();
|
||||
Integer numero = e.numeroCheval();
|
||||
|
||||
Cheval cheval = chevalRepository.findById(chevalId).orElseThrow();
|
||||
|
||||
ChevalCourse cc = new ChevalCourse();
|
||||
cc.setCourse(course);
|
||||
cc.setCheval(cheval);
|
||||
cc.setNumeroCheval(numero);
|
||||
// nonPartant et estDisqualifie restent par défaut false
|
||||
|
||||
toSave.add(cc);
|
||||
}
|
||||
|
||||
// 4) saveAll (transactionnel)
|
||||
try {
|
||||
return chevalCourseRepository.saveAll(toSave);
|
||||
} catch (DataIntegrityViolationException ex) {
|
||||
throw new DataIntegrityViolationException(
|
||||
"Constraint violation while saving bulk inscriptions: " + ex.getMessage(), ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
65
src/main/java/com/pmumali/plr/services/PariService.java
Normal file
65
src/main/java/com/pmumali/plr/services/PariService.java
Normal file
@@ -0,0 +1,65 @@
|
||||
package com.pmumali.plr.services;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import com.pmumali.plr.enums.PariType;
|
||||
import com.pmumali.plr.models.Cheval;
|
||||
import com.pmumali.plr.models.Course;
|
||||
import com.pmumali.plr.models.Pari;
|
||||
import com.pmumali.plr.repositories.ChevalCourseRepository;
|
||||
import com.pmumali.plr.repositories.ChevalRepository;
|
||||
import com.pmumali.plr.repositories.CourseRepository;
|
||||
import com.pmumali.plr.repositories.PariRepository;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
|
||||
@Service
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
public class PariService {
|
||||
private final PariRepository pariRepository;
|
||||
private final CourseRepository courseRepository;
|
||||
private final ChevalRepository chevalRepository;
|
||||
private final ChevalCourseRepository chevalCourseRepository;
|
||||
|
||||
@Transactional
|
||||
public Pari create(Long courseId, Long chevalId, PariType pariType, BigDecimal mise, String bettorRef) {
|
||||
Cheval cheval = chevalRepository.findById(chevalId).orElseThrow();
|
||||
Course course = courseRepository.findById(courseId).orElseThrow();
|
||||
|
||||
Pari p = new Pari();
|
||||
|
||||
p.setCheval(cheval);
|
||||
p.setCourse(course);
|
||||
p.setPariType(pariType);
|
||||
p.setMise(mise);
|
||||
p.setBettorRef(bettorRef);
|
||||
|
||||
return pariRepository.save(p);
|
||||
}
|
||||
|
||||
public Pari get(Long id) {
|
||||
return pariRepository.findById(id).orElseThrow();
|
||||
}
|
||||
|
||||
public List<Pari> all() {
|
||||
return pariRepository.findAll();
|
||||
}
|
||||
|
||||
public List<Pari> getParisByPariType(PariType pariType) {
|
||||
return pariRepository.findByPariType(pariType);
|
||||
}
|
||||
|
||||
public List<Pari> getParisByCourseAndType(Long courseId, PariType pariType) {
|
||||
return pariRepository.findByCourseIdAndPariType(courseId, pariType);
|
||||
}
|
||||
|
||||
public java.math.BigDecimal sumMiseByCourseIdAndPariType(Long courseId, PariType pariType) {
|
||||
return pariRepository.sumMiseByCourseIdAndPariType(courseId, pariType);
|
||||
}
|
||||
}
|
||||
28
src/main/resources/application.yml
Normal file
28
src/main/resources/application.yml
Normal file
@@ -0,0 +1,28 @@
|
||||
server:
|
||||
port: 8080
|
||||
|
||||
spring:
|
||||
application:
|
||||
name: plr
|
||||
datasource:
|
||||
url: jdbc:postgresql://localhost:5432/pmu
|
||||
username: postgres
|
||||
password:
|
||||
jpa:
|
||||
hibernate:
|
||||
ddl-auto: update
|
||||
properties:
|
||||
hibernate:
|
||||
jdbc:
|
||||
time_zone: UTC
|
||||
open-in-view: false
|
||||
flyway:
|
||||
enabled: false
|
||||
locations: classpath:db/migration
|
||||
|
||||
springdoc:
|
||||
api-docs:
|
||||
path: /v3/api-docs
|
||||
enabled: true
|
||||
swagger-ui:
|
||||
path: /swagger-ui.html
|
||||
Reference in New Issue
Block a user