Skip to content
Snippets Groups Projects
Commit 7f665c11 authored by Antoine Hazebrouck's avatar Antoine Hazebrouck
Browse files

fix bugs !!! on peut acceder aux notes des autres

parent 1236c720
Branches
No related tags found
No related merge requests found
...@@ -32,10 +32,12 @@ public class MainController { ...@@ -32,10 +32,12 @@ public class MainController {
Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
User user = userService.findUserByUsername(authentication.getName()); User user = userService.findUserByUsername(authentication.getName());
// si l'utilisateur a 0 notes // si l'utilisateur a 0 notes
if (user.getNotes().isEmpty()) { if (user.getNotes().isEmpty()) {
user = createNewNote(user); createNewNote(user);
} }
// user = userService.findUserByUsername(user.getUsername());
return "redirect:/notes/%s".formatted(user.getNotes().get(0).getId()); return "redirect:/notes/%s".formatted(user.getNotes().get(0).getId());
} }
...@@ -47,7 +49,7 @@ public class MainController { ...@@ -47,7 +49,7 @@ public class MainController {
// si l'utilisateur a 0 notes // si l'utilisateur a 0 notes
if (user.getNotes().isEmpty()) { if (user.getNotes().isEmpty()) {
user = createNewNote(user); createNewNote(user);
} }
user.getNotes().sort(new Comparator<Note>() { user.getNotes().sort(new Comparator<Note>() {
...@@ -76,16 +78,10 @@ public class MainController { ...@@ -76,16 +78,10 @@ public class MainController {
Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
User user = userService.findUserByUsername(authentication.getName()); User user = userService.findUserByUsername(authentication.getName());
user.getNotes().sort(new Comparator<Note>() { Note current = notesService.findById(note_id);
current.setNote(notes);
@Override notesService.saveNote(current);
public int compare(Note o1, Note o2) {
return o1.getId() - o2.getId();
}
});
user.getNotes().get(note_id - 1).setNote(notes);
userService.saveUser(user);
// select * from users join notes on users.id=notes.user_id; // select * from users join notes on users.id=notes.user_id;
// select * from notes; // select * from notes;
...@@ -97,19 +93,18 @@ public class MainController { ...@@ -97,19 +93,18 @@ public class MainController {
Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
User user = userService.findUserByUsername(authentication.getName()); User user = userService.findUserByUsername(authentication.getName());
user = createNewNote(user); Integer newNoteId = createNewNote(user);
return "redirect:/notes/%s".formatted(user.getNotes().size()); return "redirect:/notes/%s".formatted(newNoteId);
} }
private User createNewNote(User user) { private Integer createNewNote(User user) {
Note newNote = new Note("new note", user); Note newNote = new Note("new note", user);
// Note newNote = new Note(user.getNotes().size() + 1, "new note", user); notesService.saveNote(newNote);
user.getNotes().add(newNote); user.getNotes().add(newNote);
System.out.println("id => " + newNote.getId());
notesService.saveNote(newNote); return newNote.getId();
userService.saveUser(user);
return userService.findUserByUsername(user.getUsername());
} }
@GetMapping(value = "/user") @GetMapping(value = "/user")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment