File tree Expand file tree Collapse file tree 3 files changed +10
-7
lines changed
3-0-spring-framework/3-0-1-hello-spring-mvc/src/main Expand file tree Collapse file tree 3 files changed +10
-7
lines changed Original file line number Diff line number Diff line change 11package com .bobocode .mvc .data ;
22
3-
43import com .bobocode .mvc .model .Note ;
54import org .springframework .stereotype .Component ;
65
76import java .time .LocalDate ;
7+ import java .time .LocalDateTime ;
88import java .util .*;
99
1010@ Component
1111public class Notes {
12- private final Map <UUID , Note > notes = new LinkedHashMap <>();
12+ private final Map <UUID , Note > notesMap = new HashMap <>();
1313
1414 public List <Note > getAll (){
15- return new ArrayList <>(notes .values ());
15+ var noteList = new ArrayList <>(notesMap .values ());
16+ noteList .sort (Comparator .comparing (Note ::getCreatedOn ));
17+ return noteList ;
1618 }
1719
1820 public void add (Note note ) {
1921 note .setId (UUID .randomUUID ());
20- note .setCreationDate ( LocalDate .now ());
21- notes .put (note .getId (), note );
22+ note .setCreatedOn ( LocalDateTime .now ());
23+ notesMap .put (note .getId (), note );
2224 }
2325}
Original file line number Diff line number Diff line change 55import lombok .NonNull ;
66
77import java .time .LocalDate ;
8+ import java .time .LocalDateTime ;
89import java .util .UUID ;
910
1011@ Data
@@ -15,7 +16,7 @@ public class Note {
1516 private String title ;
1617 @ NonNull
1718 private String text ;
18- private LocalDate creationDate ;
19+ private LocalDateTime createdOn ;
1920
2021 public Note (String title , String text ) {
2122 this .title = title ;
Original file line number Diff line number Diff line change @@ -31,7 +31,7 @@ <h1 class="title">My notes</h1>
3131 < div class ="note " th:each ="theNote : ${noteList} ">
3232 < div class ="title_note " th:text ="${theNote.title} "> The title</ div >
3333 < div class ="text_note " th:text ="${theNote.text} "> The text of very long story, or just shopping list</ div >
34- < div class ="date_note " th:text ="${theNote.creationDate } "> 23.04.2021</ div >
34+ < div class ="date_note " th:text ="${theNote.createdOn.toLocalDate() } "> 23.04.2021</ div >
3535 </ div >
3636</ div >
3737
You can’t perform that action at this time.
0 commit comments