From 76faedc40df2998aee15163838b05c3d52942b78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcin=20Wo=C5=BAniak?= Date: Mon, 11 Jan 2021 16:21:25 +0100 Subject: [PATCH] Checkpoint: Added test to ExchangeRepo MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Marcin Woźniak --- .../repositories/ExchangeRepository.java | 8 +- .../plannaplan/services/ExchangeService.java | 84 ++++++++++--------- 2 files changed, 49 insertions(+), 43 deletions(-) diff --git a/buisnesslogic/src/main/java/com/plannaplan/repositories/ExchangeRepository.java b/buisnesslogic/src/main/java/com/plannaplan/repositories/ExchangeRepository.java index 0a1a210..d932eb6 100644 --- a/buisnesslogic/src/main/java/com/plannaplan/repositories/ExchangeRepository.java +++ b/buisnesslogic/src/main/java/com/plannaplan/repositories/ExchangeRepository.java @@ -16,9 +16,11 @@ import org.springframework.stereotype.Repository; public interface ExchangeRepository extends JpaRepository{ @Query("FROM Exchange WHERE owned_id = ?1 AND desired_id = ?2") - Optional checkForExchange(@Param("owned_id") Assignment assignment, @Param("desired_id") Groups group); + Optional checkForExchange(@Param("owned_id") Assignment assignment, @Param("desired_id") Groups group); @Query("FROM Exchange WHERE ownerId = ?1") - List getByUserId(@Param("id") Long id); - + List getByUserId(@Param("id") Long id); + + @Query("Select e1,e2 FROM Exchange e1, Exchange e2 WHERE e1.ownedAssignment.group.id = e2.desiredAssignment.id") + List getMatches(); } diff --git a/buisnesslogic/src/main/java/com/plannaplan/services/ExchangeService.java b/buisnesslogic/src/main/java/com/plannaplan/services/ExchangeService.java index 143f459..3c423b8 100644 --- a/buisnesslogic/src/main/java/com/plannaplan/services/ExchangeService.java +++ b/buisnesslogic/src/main/java/com/plannaplan/services/ExchangeService.java @@ -13,47 +13,51 @@ import org.springframework.stereotype.Service; @Service public class ExchangeService { - - @Autowired - private ExchangeRepository repo; - /** - * @param exchange Instance to save in database - * @return Exchange Instance contains database id - */ - public Exchange save(Exchange exchange){ - return this.repo.save(exchange); - } - - /** - * @param id Id of exchange in database - * @return Optional Exchange if found - */ - public Optional getById(Long id){ - return this.repo.findById(id); - } - - /** - * @param id Id of user - * @return List of exchanges that belong to user - */ - public List getByUserId(Long id){ - return this.repo.getByUserId(id); - } + @Autowired + private ExchangeRepository repo; - /** - * @param entity Exchange entity which we would like to delete - */ - public void deleteExchange(Exchange entity){ - this.repo.delete(entity); - } + /** + * @param exchange Instance to save in database + * @return Exchange Instance contains database id + */ + public Exchange save(Exchange exchange) { + 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); - } + /** + * @param id Id of exchange in database + * @return Optional Exchange if found + */ + public Optional getById(Long id) { + return this.repo.findById(id); + } + + /** + * @param id Id of user + * @return List of exchanges that belong to user + */ + public List getByUserId(Long id) { + return this.repo.getByUserId(id); + } + + /** + * @param entity Exchange entity which we would like to delete + */ + public void deleteExchange(Exchange entity) { + this.repo.delete(entity); + } + + /** + * @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); + } + + public void performExchange() { + + } }