Checkpoint: Added test to ExchangeRepo
Signed-off-by: Marcin Woźniak <y0rune@aol.com>
This commit is contained in:
parent
5e459ac429
commit
76faedc40d
@ -16,9 +16,11 @@ import org.springframework.stereotype.Repository;
|
||||
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);
|
||||
Optional<Exchange> checkForExchange(@Param("owned_id") Assignment assignment, @Param("desired_id") Groups group);
|
||||
|
||||
@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();
|
||||
}
|
||||
|
@ -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<Exchange> getById(Long id){
|
||||
return this.repo.findById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param id Id of user
|
||||
* @return List of exchanges that belong to user
|
||||
*/
|
||||
public List<Exchange> 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<Exchange> 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<Exchange> getById(Long id) {
|
||||
return this.repo.findById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param id Id of user
|
||||
* @return List of exchanges that belong to user
|
||||
*/
|
||||
public List<Exchange> 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<Exchange> checkForExchange(Assignment assignment, Groups group) {
|
||||
return this.repo.checkForExchange(assignment, group);
|
||||
}
|
||||
|
||||
public void performExchange() {
|
||||
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user