Skip to content

Commit

Permalink
add match validation and transaction for api generation
Browse files Browse the repository at this point in the history
  • Loading branch information
syarhei committed Dec 16, 2017
1 parent 2bdb8b1 commit 188893c
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/main/controllers/MatchController.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.transaction.Transactional;
import java.math.BigDecimal;
import java.util.List;

Expand All @@ -31,18 +32,26 @@ public class MatchController extends Controller<Match> {
@Override
public ResponseEntity createEntity(@RequestBody Match object) {
try {
if (object.getTeam1().getId().equals(object.getTeam2().getId()))
return ResponseEntity.status(501).body("Two same teams can not play in one match");

Team team1 = teamService.getById(object.getTeam1().getId());
Team team2 = teamService.getById(object.getTeam2().getId());

if (team1 == null)
return ResponseEntity.status(501).body("Team 1 is not found");
if (team2 == null)
return ResponseEntity.status(501).body("Team 2 is not found");

matchService.generateCoefficients(object, team1, team2);

return super.createEntity(object);
} catch (Exception e) {
return ResponseEntity.status(500).body(e.getMessage());
}

}

@Transactional
@PostMapping("/{primaryKey}/results/generation")
public ResponseEntity generateResult(@PathVariable Integer primaryKey) {
try {
Expand Down

0 comments on commit 188893c

Please sign in to comment.