Fibinger Ádám
2019-03-03 464000b3acc64e678a57141c2eb806a5b3d2a01c
commit | author | age
464000 1 package hu.unr.fiber.cardapi.entity;
2
3 import java.util.ArrayList;
4 import java.util.List;
5
6 import hu.unr.fiber.cardapi.rest.CardEntity;
7 import org.springframework.stereotype.Component;
8
9 @Component
10 public class CardInteractor implements CardListBoundaryInterface, CardByIdInterface {
11
12     private CardRepository cardRepository;
13
14     CardInteractor(CardRepository cardRepository) {
15         this.cardRepository = cardRepository;
16     }
17
18     @Override
19     public List<CardEntityInterface> getCardList() {
20
21         List<Card> cardList = this.cardRepository.findAll();
22         List<CardEntityInterface> restCardList = new ArrayList<>();
23
24         for (Card card : cardList) {
25             CardEntity ce = new CardEntity(card.getId());
26             restCardList.add(ce.update(card));
27         }
28
29         return restCardList;
30     }
31
32     @Override
33     public CardEntityInterface getCardById(long id) {
34         if (!this.cardRepository.existsById(id)) {
35             return null;
36         }
37
38         Card c = this.cardRepository.getOne(id);
39         CardEntity ce = new CardEntity(c.getId());
40
41         return ce.update(c);
42     }
43 }