diff --git a/buisnesslogic/src/main/java/com/plannaplan/entities/Exchange.java b/buisnesslogic/src/main/java/com/plannaplan/entities/Exchange.java index 785c681..c0830c4 100644 --- a/buisnesslogic/src/main/java/com/plannaplan/entities/Exchange.java +++ b/buisnesslogic/src/main/java/com/plannaplan/entities/Exchange.java @@ -18,7 +18,7 @@ public class Exchange { private Long id; @OneToOne - @JoinColumn(name = "owned_id") + @JoinColumn(name = "owned_id", unique = true) private Assignment ownedAssignment; @OneToOne diff --git a/buisnesslogic/src/main/java/com/plannaplan/services/ExchangeService.java b/buisnesslogic/src/main/java/com/plannaplan/services/ExchangeService.java index a2f6556..cd31023 100644 --- a/buisnesslogic/src/main/java/com/plannaplan/services/ExchangeService.java +++ b/buisnesslogic/src/main/java/com/plannaplan/services/ExchangeService.java @@ -24,6 +24,12 @@ public class ExchangeService { return this.repo.save(exchange); } + + /** + * @param assignment Assignment to trade for + * @param group Desired group + * @return Optional with Exchange if exist + */ public Optional checkForExchange(Assignment assignment, Groups group){ return this.repo.checkForExchange(assignment, group); } diff --git a/restservice/src/main/java/com/plannaplan/controllers/ExchangeController.java b/restservice/src/main/java/com/plannaplan/controllers/ExchangeController.java index e9a032c..b9c4869 100644 --- a/restservice/src/main/java/com/plannaplan/controllers/ExchangeController.java +++ b/restservice/src/main/java/com/plannaplan/controllers/ExchangeController.java @@ -69,9 +69,8 @@ public class ExchangeController extends TokenBasedController{ final Assignment assignmentInstance = assignment.get(); final Groups groupInstance = group.get(); - final Optional exchangeInstance = this.exchangeService.checkForExchange(assignmentInstance, groupInstance); - if(!(assignmentInstance.getCommision().getCommisionOwner().getId() == asker.getId() && assignmentInstance.isAccepted() && exchangeInstance.isEmpty())){ + if(!(assignmentInstance.getCommision().getCommisionOwner().getId().equals(asker.getId()) && assignmentInstance.isAccepted())){ return new ResponseEntity<>("Some of problems appeared. Check if you have access to given assignment and if it is accepted or the exchange has not been already added.", HttpStatus.BAD_REQUEST); }