Fibinger Ádám
2019-03-03 464000b3acc64e678a57141c2eb806a5b3d2a01c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
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);
    }
}