Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
block_note
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Antoine Hazebrouck
block_note
Commits
7f665c11
Commit
7f665c11
authored
2 years ago
by
Antoine Hazebrouck
Browse files
Options
Downloads
Patches
Plain Diff
fix bugs !!! on peut acceder aux notes des autres
parent
1236c720
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/main/java/jez/authentication2/controllers/MainController.java
+14
-19
14 additions, 19 deletions
.../java/jez/authentication2/controllers/MainController.java
with
14 additions
and
19 deletions
src/main/java/jez/authentication2/controllers/MainController.java
+
14
−
19
View file @
7f665c11
...
@@ -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
Us
er
createNewNote
(
User
user
)
{
private
Integ
er
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
n
ote
", user
);
notesService
.
saveNote
(
new
N
ote
);
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"
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment