<repo_name>freak0/yacht<file_sep>/yacht-web/src/main/java/br/com/eltonsantos/yacht/YachtApplication.java
package br.com.eltonsantos.yacht;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class YachtApplication {

    public static void main(String[] args) {
        SpringApplication.run(YachtApplication.class, args);
    }

}

<file_sep>/yacht-data/src/main/java/br/com/eltonsantos/yacht/data/services/CrudService.java
package br.com.eltonsantos.yacht.data.services;

import br.com.eltonsantos.yacht.data.model.BaseEntity;

import java.io.Serializable;
import java.util.Optional;
import java.util.Set;

public interface CrudService<T extends BaseEntity, ID extends Serializable> {

    T save(T object);

    Optional<T> findById(ID id);

    Set<T> findAll();

    void delete(T object);

    void deleteById(ID id);

}
<file_sep>/yacht-web/src/main/java/br/com/eltonsantos/yacht/bootstrap/DataLoader.java
package br.com.eltonsantos.yacht.bootstrap;

import br.com.eltonsantos.yacht.data.model.Checklist;
import br.com.eltonsantos.yacht.data.model.ChecklistGroup;
import br.com.eltonsantos.yacht.data.services.ChecklistGroupService;
import br.com.eltonsantos.yacht.data.services.ChecklistService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

import java.time.LocalDate;
import java.time.Month;

@Component
public class DataLoader implements CommandLineRunner {

    private final ChecklistService checklistService;
    private final ChecklistGroupService checklistGroupService;

    private static final Logger LOG = LoggerFactory.getLogger(DataLoader.class);

    public DataLoader(ChecklistService checklistService, ChecklistGroupService checklistGroupService) {
        this.checklistService = checklistService;
        this.checklistGroupService = checklistGroupService;
    }

    @Override
    public void run(String... args) throws Exception {
        LOG.info("Creating checklist groups...");

        ChecklistGroup australiaChecklistGroup = new ChecklistGroup("Australia travel");
        ChecklistGroup studyListChecklistGroup = new ChecklistGroup("Study list");

        checklistGroupService.save(australiaChecklistGroup);
        checklistGroupService.save(studyListChecklistGroup);

        LOG.info("Checklist groups created.");

        LOG.info("Creating checklists...");

        Checklist luggageChecklist =
                new Checklist("Getting the luggage figured out", LocalDate.of(2018, Month.DECEMBER, 30));
        luggageChecklist.setGroup(australiaChecklistGroup);
        Checklist documentationChecklist =
                new Checklist("Preparing documentation", LocalDate.of(2018, Month.DECEMBER, 22));
        documentationChecklist.setGroup(australiaChecklistGroup);

        Checklist studySpringChecklist =
                new Checklist("Spring studies", LocalDate.of(2019, Month.JANUARY, 7));
        studySpringChecklist.setGroup(studyListChecklistGroup);

        checklistService.save(luggageChecklist);
        checklistService.save(documentationChecklist);
        checklistService.save(studySpringChecklist);

        LOG.info("Checklists created.");
    }

}
<file_sep>/yacht-data/src/main/java/br/com/eltonsantos/yacht/data/model/Task.java
package br.com.eltonsantos.yacht.data.model;

public class Task extends BaseEntity {

    private String name;
    private String description;
    private Boolean checked;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public Boolean getChecked() {
        return checked;
    }

    public void setChecked(Boolean checked) {
        this.checked = checked;
    }
}
<file_sep>/yacht-data/src/test/java/br/com/eltonsantos/yacht/data/services/map/ChecklistServiceMapTest.java
package br.com.eltonsantos.yacht.data.services.map;

import br.com.eltonsantos.yacht.data.model.Checklist;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

import java.time.LocalDate;
import java.util.Optional;
import java.util.Set;

import static java.time.Month.DECEMBER;
import static org.junit.jupiter.api.Assertions.*;

class ChecklistServiceMapTest {

    private static LocalDate XMAS_DATE = LocalDate.of(2018, DECEMBER, 25);

    private ChecklistServiceMap cut;

    @BeforeEach
    void setUp() {
        this.cut = new ChecklistServiceMap();
        this.cut.save(new Checklist("Create tests", LocalDate.of(2018, DECEMBER, 17)));
        this.cut.save(new Checklist("Create more tests", LocalDate.of(2018, DECEMBER, 18)));
        this.cut.save(new Checklist("Create the actual code", LocalDate.of(2018, DECEMBER, 19)));
    }

    @Test
    @DisplayName("When I save a new Checklist, check if its saved using its ID to find it.")
    void save() {
        //when:
        Checklist checklist = new Checklist("<NAME>", XMAS_DATE);
        Checklist returnedChecklist = this.cut.save(checklist);

        //and:
        Optional<Checklist> optChecklistFound = this.cut.findById(4L);

        //then:
        assertTrue(optChecklistFound.isPresent());

        Checklist checklistFound = optChecklistFound.get();

        assertEquals((Object) 4L, checklistFound.getId());
        assertEquals("<NAME>", checklistFound.getName());
        assertEquals(XMAS_DATE, checklistFound.getDueDate());
        assertEquals(returnedChecklist, checklistFound);
    }

    @Test
    @DisplayName("Tests the search for all checklists to see if returns only the 3 bootstraped checklists.")
    void findAll() {
        //when:
        Set<Checklist> checklists = this.cut.findAll();

        //then:
        assertEquals(3, checklists.size());
    }

    @Test
    @DisplayName("When I search for a checklist by its ID, check the checklist to see if its data is as expected.")
    void findById() {
        //when:
        Optional<Checklist> optChecklist = this.cut.findById(1L);

        //then:
        assertTrue(optChecklist.isPresent());

        Checklist checklist = optChecklist.get();

        assertEquals((Object) 1L, checklist.getId());
        assertEquals("Create tests", checklist.getName());
        assertEquals(LocalDate.of(2018, DECEMBER, 17), checklist.getDueDate());
    }

    @Test
    @DisplayName("Tests if a deleted checklist is not returned anymore after been excluded based on its id.")
    void deleteById() {
        //when:
        this.cut.deleteById(2L);
        Optional<Checklist> removedChecklist = this.cut.findById(2L);

        //then:
        assertFalse(removedChecklist.isPresent());
    }

    @Test
    @DisplayName("Tests if a deleted checklist is not returned anymore after been excluded.")
    void delete() {
        //when:
        Checklist checklistToBeRemoved = this.cut.findById(3L).get();
        this.cut.delete(checklistToBeRemoved);
        Optional<Checklist> removedChecklist = this.cut.findById(3L);

        //then:
        assertFalse(removedChecklist.isPresent());
    }
}<file_sep>/yacht-data/src/main/java/br/com/eltonsantos/yacht/data/services/map/ChecklistServiceMap.java
package br.com.eltonsantos.yacht.data.services.map;

import br.com.eltonsantos.yacht.data.model.Checklist;
import br.com.eltonsantos.yacht.data.services.ChecklistService;
import org.springframework.stereotype.Service;

@Service
public class ChecklistServiceMap extends AbstractCrudServiceMap<Checklist, Long> implements ChecklistService {

}
<file_sep>/yacht-data/src/main/java/br/com/eltonsantos/yacht/data/services/ChecklistGroupService.java
package br.com.eltonsantos.yacht.data.services;

import br.com.eltonsantos.yacht.data.model.ChecklistGroup;

public interface ChecklistGroupService extends CrudService<ChecklistGroup, Long> {
}
<file_sep>/yacht-data/src/main/java/br/com/eltonsantos/yacht/data/services/ChecklistService.java
package br.com.eltonsantos.yacht.data.services;

import br.com.eltonsantos.yacht.data.model.Checklist;

public interface ChecklistService extends CrudService<Checklist, Long> {

}
<file_sep>/yacht-data/src/main/java/br/com/eltonsantos/yacht/data/services/map/ChecklistGroupServiceMap.java
package br.com.eltonsantos.yacht.data.services.map;

import br.com.eltonsantos.yacht.data.model.ChecklistGroup;
import br.com.eltonsantos.yacht.data.services.ChecklistGroupService;
import org.springframework.stereotype.Service;

@Service
public class ChecklistGroupServiceMap extends AbstractCrudServiceMap<ChecklistGroup, Long> implements ChecklistGroupService {

}
<file_sep>/README.md
Yet Another Checklist Tool - Using this app to study some more of:
- Spring Boot;
- Reactive Programming;
- Unit tests;
- React;
- Redux.
<file_sep>/yacht-data/src/main/java/br/com/eltonsantos/yacht/data/services/TaskService.java
package br.com.eltonsantos.yacht.data.services;

import br.com.eltonsantos.yacht.data.model.Task;

public interface TaskService extends CrudService<Task, Long> {
}
