My contributions in java was setting up and creating the backend api. This is meant to contain all of the cards, or data in our project.
CardGeneration, Service , controller, main, jpa repository, classes
One improvement that was suggested in an earlier review was to create a larger dataset to demonstrate the varying complexities of the sorting algorithms better, so I changed the dataset from containing 52 records (like a deck) to 500 cards.
Generation and Service Classes:
@Configuration
public class CardGeneration {
@Bean
CommandLineRunner commandLineRunner(
CardJpaRepository repository) {
return args -> {
List<Card> cards = new ArrayList<>();
for (int rank = 1; rank <= 500; rank++) {
Card card = new Card(rank);
cards.add(card);
}
repository.saveAll(cards);
};
}
@Service
public class CardService {
private final CardJpaRepository cardRepository;
@Autowired
public CardService(CardJpaRepository cardRepository) {
this.cardRepository = cardRepository;
}
public List<List<Card>> splitCardsRandomly(List<Card> cards) {
// Shuffle the cards randomly
Collections.shuffle(cards);
// Split the cards into two halves
int halfSize = cards.size() / 2;
List<Card> firstHalf = new ArrayList<>(cards.subList(0, halfSize));
List<Card> secondHalf = new ArrayList<>(cards.subList(halfSize, cards.size()));
List<List<Card>> splitCards = new ArrayList<>();
splitCards.add(firstHalf);
splitCards.add(secondHalf);
return splitCards;
}
// commit change
public void saveCards(List<Card> cards) {
cardRepository.saveAll(cards);
}
}
Java Fundamental: class extension can be seen in JPA repository file. JPA repository is an interface which is a part of the Spring Data repository support and provides methods for common database operations (like save, delete, findById, etc.) without the need for manual implementation. The use of this class extension was very helpful!
I plan to add something like ranks so I could add a compareto method as mentioned by Mort in indicator tech talk. Additionally I would create cards as objects with rank and suit variables instead of using an imperative generation method. However we were sort of in a time crunch because we did ideation incorrectly.
Demo/Summary Video
Youtube Link
Creating Backend Endpoints - Backend
Generation and Service Classes:
Endpoint:
Postman:
Key Commit Backend
Creating Test Analysis File - Frontend
Key Commit Frontend
Commit History
Frontend:
Backend:
Retrospective
I plan to add something like ranks so I could add a compareto method as mentioned by Mort in indicator tech talk. Additionally I would create cards as objects with rank and suit variables instead of using an imperative generation method. However we were sort of in a time crunch because we did ideation incorrectly.