Checkpoints: WORKS but not for all
Signed-off-by: Marcin Woźniak <y0rune@aol.com>
This commit is contained in:
parent
df7701ebc8
commit
b633d2c2df
@ -1,11 +1,20 @@
|
|||||||
package com.plannaplan.repositories;
|
package com.plannaplan.repositories;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
import com.plannaplan.entities.Assignment;
|
||||||
import com.plannaplan.entities.Exchange;
|
import com.plannaplan.entities.Exchange;
|
||||||
|
import com.plannaplan.entities.Groups;
|
||||||
|
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
import org.springframework.data.jpa.repository.Query;
|
||||||
|
import org.springframework.data.repository.query.Param;
|
||||||
import org.springframework.stereotype.Repository;
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
@Repository
|
@Repository
|
||||||
public interface ExchangeRepository extends JpaRepository<Exchange, Long>{
|
public interface ExchangeRepository extends JpaRepository<Exchange, Long>{
|
||||||
|
|
||||||
|
@Query("FROM Exchange WHERE owned_id = ?1 AND desired_id = ?2")
|
||||||
|
Optional<Exchange> checkForExchange(@Param("owned_id") Assignment assignment, @Param("desired_id") Groups group);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,10 @@
|
|||||||
package com.plannaplan.services;
|
package com.plannaplan.services;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
import com.plannaplan.entities.Assignment;
|
||||||
import com.plannaplan.entities.Exchange;
|
import com.plannaplan.entities.Exchange;
|
||||||
|
import com.plannaplan.entities.Groups;
|
||||||
import com.plannaplan.repositories.ExchangeRepository;
|
import com.plannaplan.repositories.ExchangeRepository;
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
@ -19,4 +23,8 @@ public class ExchangeService {
|
|||||||
public Exchange save(Exchange exchange){
|
public Exchange save(Exchange exchange){
|
||||||
return this.repo.save(exchange);
|
return this.repo.save(exchange);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Optional<Exchange> checkForExchange(Assignment assignment, Groups group){
|
||||||
|
return this.repo.checkForExchange(assignment, group);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -68,13 +68,17 @@ public class ExchangeController extends TokenBasedController{
|
|||||||
}
|
}
|
||||||
|
|
||||||
final Assignment assignmentInstance = assignment.get();
|
final Assignment assignmentInstance = assignment.get();
|
||||||
|
final Groups groupInstance = group.get();
|
||||||
|
final Optional<Exchange> exchangeInstance = this.exchangeService.checkForExchange(assignmentInstance, groupInstance);
|
||||||
|
|
||||||
if(!(assignmentInstance.getCommision().getCommisionOwner().getId() == asker.getId() && assignmentInstance.isAccepted())){
|
if(!(assignmentInstance.getCommision().getCommisionOwner().getId() == asker.getId() && assignmentInstance.isAccepted() && exchangeInstance.isEmpty())){
|
||||||
return new ResponseEntity<>("Some of problems appeared. Check if you have access to given assignment and if it is accepted", HttpStatus.BAD_REQUEST);
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.exchangeService.save(new Exchange(assignment.get(), group.get()));
|
this.exchangeService.save(new Exchange(assignmentInstance, groupInstance));
|
||||||
|
|
||||||
return new ResponseEntity<>("Success", HttpStatus.OK);
|
return new ResponseEntity<>("Success", HttpStatus.OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user