aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAdrián Oliva <adrian.oliva@cimat.mx>2023-05-29 21:51:07 -0600
committerAdrián Oliva <adrian.oliva@cimat.mx>2023-05-29 21:51:07 -0600
commit82a11efa31f0a0d259e089e702f58dd9c141ed02 (patch)
tree6b0289fc54bb1c43715289b580bba4212faf1f4d /src
parent1f192c7ad1a7c3854efa5595321783e5b1a3fe81 (diff)
downloadToDo-App-BE-82a11efa31f0a0d259e089e702f58dd9c141ed02.tar.gz
ToDo-App-BE-82a11efa31f0a0d259e089e702f58dd9c141ed02.zip
New get function and sorting problems.
Get function for filtered to dos. Sorting can now compare null objects. Reordered sorting because of a Concurrent Modification Exception.
Diffstat (limited to 'src')
-rw-r--r--src/main/java/com/encora/Main.java7
-rw-r--r--src/main/java/com/encora/ToDosRepository.java12
2 files changed, 10 insertions, 9 deletions
diff --git a/src/main/java/com/encora/Main.java b/src/main/java/com/encora/Main.java
index 7793be9..ea3a2a4 100644
--- a/src/main/java/com/encora/Main.java
+++ b/src/main/java/com/encora/Main.java
@@ -6,10 +6,7 @@ import org.springframework.data.domain.Sort;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;
-import java.util.Collections;
-import java.util.Date;
-import java.util.List;
-import java.util.Objects;
+import java.util.*;
@SpringBootApplication
@RestController
@@ -215,7 +212,7 @@ public class Main {
}
final int pageSize = 10;
- List<ToDos> myToDos = toDosRepository.filteredToDos;
+ List<ToDos> myToDos = toDosRepository.getFilteredToDos();
int fromIndex = (page - 1) * pageSize;
if (myToDos.size() <= fromIndex) {
diff --git a/src/main/java/com/encora/ToDosRepository.java b/src/main/java/com/encora/ToDosRepository.java
index a4c9a10..c4bdcba 100644
--- a/src/main/java/com/encora/ToDosRepository.java
+++ b/src/main/java/com/encora/ToDosRepository.java
@@ -171,7 +171,7 @@ public class ToDosRepository implements JpaRepository<ToDos, Integer> {
break;
case "DueDate":
- comparator = Comparator.comparing(ToDos::getDueDate);
+ comparator = Comparator.comparing(ToDos::getDueDate, Comparator.nullsLast(Comparator.naturalOrder()));
break;
default:
@@ -187,16 +187,20 @@ public class ToDosRepository implements JpaRepository<ToDos, Integer> {
// Filter and then sort all of our to dos.
public void refreshFilteredToDos(Sort sort, String name, String priority, String done) throws Exception {
- this.filteredToDos = this.findAllWithFilter(name, priority, done);
-
try {
Comparator<ToDos> comparator = this.getToDoComparator(sort);
- Collections.sort(this.filteredToDos, comparator);
+
+ this.filteredToDos = this.findAllWithFilter(name, priority, done);
+ this.filteredToDos.sort(comparator);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
+ public List<ToDos> getFilteredToDos() {
+ return this.filteredToDos;
+ }
+
/*
* N O T Y E T D E F I N E D .
*/