2021-01-06 13:40:04 +01:00
|
|
|
package com.plannaplan.services;
|
|
|
|
|
2021-01-07 16:51:35 +01:00
|
|
|
import java.util.List;
|
2021-01-06 16:50:08 +01:00
|
|
|
import java.util.Optional;
|
|
|
|
|
|
|
|
import com.plannaplan.entities.Assignment;
|
2021-01-06 13:40:04 +01:00
|
|
|
import com.plannaplan.entities.Exchange;
|
2021-01-06 16:50:08 +01:00
|
|
|
import com.plannaplan.entities.Groups;
|
2021-01-11 16:56:39 +01:00
|
|
|
import com.plannaplan.models.MatchData;
|
2021-01-06 13:40:04 +01:00
|
|
|
import com.plannaplan.repositories.ExchangeRepository;
|
|
|
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
@Service
|
|
|
|
public class ExchangeService {
|
2021-01-11 16:21:25 +01:00
|
|
|
|
2021-01-11 16:56:39 +01:00
|
|
|
@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);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @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() {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// public void getMatches(){
|
|
|
|
// final List<MatchData> matches = this.repo.getMatches().stream().map(m -> {
|
|
|
|
// return (MatchData) m;
|
|
|
|
// });
|
|
|
|
// }
|
2021-01-06 13:40:04 +01:00
|
|
|
}
|