Checkpoint: Added test to ExchangeRepo

Signed-off-by: Marcin Woźniak <y0rune@aol.com>
This commit is contained in:
Marcin Woźniak 2021-01-11 16:21:25 +01:00
parent 5e459ac429
commit 76faedc40d
Signed by: y0rune
GPG Key ID: F204C385F57EB348
2 changed files with 49 additions and 43 deletions

View File

@ -21,4 +21,6 @@ public interface ExchangeRepository extends JpaRepository<Exchange, Long>{
@Query("FROM Exchange WHERE ownerId = ?1") @Query("FROM Exchange WHERE ownerId = ?1")
List<Exchange> getByUserId(@Param("id") Long id); List<Exchange> getByUserId(@Param("id") Long id);
@Query("Select e1,e2 FROM Exchange e1, Exchange e2 WHERE e1.ownedAssignment.group.id = e2.desiredAssignment.id")
List<Object[]> getMatches();
} }

View File

@ -21,7 +21,7 @@ public class ExchangeService {
* @param exchange Instance to save in database * @param exchange Instance to save in database
* @return Exchange Instance contains database id * @return Exchange Instance contains database id
*/ */
public Exchange save(Exchange exchange){ public Exchange save(Exchange exchange) {
return this.repo.save(exchange); return this.repo.save(exchange);
} }
@ -29,7 +29,7 @@ public class ExchangeService {
* @param id Id of exchange in database * @param id Id of exchange in database
* @return Optional Exchange if found * @return Optional Exchange if found
*/ */
public Optional<Exchange> getById(Long id){ public Optional<Exchange> getById(Long id) {
return this.repo.findById(id); return this.repo.findById(id);
} }
@ -37,14 +37,14 @@ public class ExchangeService {
* @param id Id of user * @param id Id of user
* @return List of exchanges that belong to user * @return List of exchanges that belong to user
*/ */
public List<Exchange> getByUserId(Long id){ public List<Exchange> getByUserId(Long id) {
return this.repo.getByUserId(id); return this.repo.getByUserId(id);
} }
/** /**
* @param entity Exchange entity which we would like to delete * @param entity Exchange entity which we would like to delete
*/ */
public void deleteExchange(Exchange entity){ public void deleteExchange(Exchange entity) {
this.repo.delete(entity); this.repo.delete(entity);
} }
@ -53,7 +53,11 @@ public class ExchangeService {
* @param group Desired group * @param group Desired group
* @return Optional with Exchange if exist * @return Optional with Exchange if exist
*/ */
public Optional<Exchange> checkForExchange(Assignment assignment, Groups group){ public Optional<Exchange> checkForExchange(Assignment assignment, Groups group) {
return this.repo.checkForExchange(assignment, group); return this.repo.checkForExchange(assignment, group);
} }
public void performExchange() {
}
} }