Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions .idea/To-Do-Back-End.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/encodings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions .idea/jarRepositories.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,48 +1,16 @@
package com.assigment.todoapp.repository;

import java.util.List;
import java.util.stream.Collectors;

import org.springframework.stereotype.Repository;
import java.util.UUID;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you know the pros and cons of using uuid?


import com.assigment.todoapp.domain.ToDoItem;


/*
@Repository
public interface ToDoRepository extends JpaRepository<ToDoItem, UUID> to create the interface and use de Database
*/

@Repository
public class ToDoRepository { // interface


private List<ToDoItem> todoItems;

public ToDoRepository(List<ToDoItem> todoItems) {
this.todoItems = todoItems;
}

public List<ToDoItem> fetchAllToDoItems () {
return todoItems;
}

public List<ToDoItem> findByDone(boolean aux) {
return todoItems.stream()
.filter(item -> item.isDone() == aux)
.collect(Collectors.toList());
}

public List<ToDoItem> findByNameContainingIgnoreCase(String name) {
return todoItems.stream()
.filter(item -> item.getName().toLowerCase().contains(name.toLowerCase()))
.collect(Collectors.toList());
}

public List<ToDoItem> findByPriority(String priority) {
return todoItems.stream()
.filter(item -> item.getPriority().equalsIgnoreCase(priority))
.collect(Collectors.toList());
}

}
public interface ToDoRepository {
List<ToDoItem> fetchAllToDoItems();
List<ToDoItem> findByDone(boolean done);
List<ToDoItem> findByNameContainingIgnoreCase(String name);
List<ToDoItem> findByPriority(String priority);
ToDoItem findById(UUID id);
void save(ToDoItem todoItem);
void deleteById(UUID id);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package com.assigment.todoapp.repository;

import java.util.List;
import java.util.UUID;
import java.util.stream.Collectors;

import org.springframework.stereotype.Repository;

import com.assigment.todoapp.domain.ToDoItem;

@Repository
public class ToDoRepositoryImpl implements ToDoRepository {

private final List<ToDoItem> todoItems;

public ToDoRepositoryImpl(List<ToDoItem> todoItems) {
this.todoItems = todoItems;
}

@Override
public List<ToDoItem> fetchAllToDoItems() {
return todoItems;
}

@Override
public List<ToDoItem> findByDone(boolean done) {
return todoItems.stream()
.filter(item -> item.isDone() == done)
.collect(Collectors.toList());
}

@Override
public List<ToDoItem> findByNameContainingIgnoreCase(String name) {
return todoItems.stream()
.filter(item -> item.getName().toLowerCase().contains(name.toLowerCase()))
.collect(Collectors.toList());
}

@Override
public List<ToDoItem> findByPriority(String priority) {
return todoItems.stream()
.filter(item -> item.getPriority().equalsIgnoreCase(priority))
.collect(Collectors.toList());
}

@Override
public ToDoItem findById(UUID id) {
return todoItems.stream()
.filter(item -> item.getId().equals(id))
.findFirst()
.orElseThrow(() -> new RuntimeException("ToDoItem not found"));
}

@Override
public void save(ToDoItem todoItem) {
todoItems.add(todoItem);
}

@Override
public void deleteById(UUID id) {
todoItems.removeIf(item -> item.getId().equals(id));
}
}
Loading