-
Notifications
You must be signed in to change notification settings - Fork 0
Refactored code based on Copilot suggestions #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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; | ||
|
|
||
| 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)); | ||
| } | ||
| } |
There was a problem hiding this comment.
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?