package hu.unr.fiber.cardapi.entity;
|
|
import java.util.ArrayList;
|
import java.util.List;
|
|
import hu.unr.fiber.cardapi.rest.CardEntity;
|
import org.springframework.stereotype.Component;
|
|
@Component
|
public class CardInteractor implements CardListBoundaryInterface, CardByIdInterface {
|
|
private CardRepository cardRepository;
|
|
CardInteractor(CardRepository cardRepository) {
|
this.cardRepository = cardRepository;
|
}
|
|
@Override
|
public List<CardEntityInterface> getCardList() {
|
|
List<Card> cardList = this.cardRepository.findAll();
|
List<CardEntityInterface> restCardList = new ArrayList<>();
|
|
for (Card card : cardList) {
|
CardEntity ce = new CardEntity(card.getId());
|
restCardList.add(ce.update(card));
|
}
|
|
return restCardList;
|
}
|
|
@Override
|
public CardEntityInterface getCardById(long id) {
|
if (!this.cardRepository.existsById(id)) {
|
return null;
|
}
|
|
Card c = this.cardRepository.getOne(id);
|
CardEntity ce = new CardEntity(c.getId());
|
|
return ce.update(c);
|
}
|
}
|