if (trackForm.hasErrors()) {
return badRequest(toJson(TransformValidationErrors.transform(trackForm.errors())));
}
Track formTrack = trackForm.get();
if (formTrack.getId() == null) {
// Nouveau Track
if (Track.findByTitleAndEvent(formTrack.getTitle(),getEvent()) != null) {
return badRequest(toJson(TransformValidationErrors.transform(Messages.get("error.track.already.exist"))));
}
if (Track.findByShortTitleAndEvent(formTrack.getShortTitle(),getEvent()) != null) {
return badRequest(toJson(TransformValidationErrors.transform(Messages.get("error.track.shortTitle.already.exist"))));
}
formTrack.setEvent(getEvent());
formTrack.save();
} else {
// Mise à jour d'un track
Track dbTrack = Track.find.byId(formTrack.getId());
if (!formTrack.getTitle().equals(dbTrack.getTitle())
&& Track.findByTitleAndEvent(formTrack.getTitle(),getEvent()) != null) {
return badRequest(toJson(TransformValidationErrors.transform(Messages.get("error.track.already.exist"))));
}
if (!formTrack.getShortTitle().equals(dbTrack.getShortTitle())
&& Track.findByShortTitleAndEvent(formTrack.getShortTitle(),getEvent()) != null) {
return badRequest(toJson(TransformValidationErrors.transform(Messages.get("error.track.shortTitle.already.exist"))));
}
dbTrack.setTitle(formTrack.getTitle());
dbTrack.setShortTitle(formTrack.getShortTitle());
dbTrack.setDescription(formTrack.getDescription());
dbTrack.update();
}
// HTTP 204 en cas de succès (NO CONTENT)
return noContent();
}