Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
s7_spruge_k
calendar
Commits
650fc19c
Commit
650fc19c
authored
Jun 15, 2019
by
sapn1s
Browse files
Fixed master branch
parent
00d0480d
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
63 deletions
+28
-63
src/main/java/com/example/calendar/controller/CalendarController.java
...a/com/example/calendar/controller/CalendarController.java
+15
-49
src/main/java/com/example/calendar/controller/EventController.java
...java/com/example/calendar/controller/EventController.java
+13
-14
No files found.
src/main/java/com/example/calendar/controller/CalendarController.java
View file @
650fc19c
...
...
@@ -40,9 +40,8 @@ public class CalendarController {
@Autowired
private
CalendarValidator
calendarValidator
;
@GetMapping
(
"/test"
)
public
String
testGet
()
{
public
User
findCurrentUser
()
{
Object
principal
=
SecurityContextHolder
.
getContext
().
getAuthentication
().
getPrincipal
();
String
username
=
""
;
...
...
@@ -53,6 +52,15 @@ public class CalendarController {
}
User
currUser
=
userRepo
.
findByUsername
(
username
);
return
currUser
;
}
@GetMapping
(
"/test"
)
public
String
testGet
()
{
User
currUser
=
findCurrentUser
();
ArrayList
<
Calendar
>
c1
=
calendarRepo
.
findAllByUser
(
currUser
);
//TODO RIGHT NOW IT TAKES DEFAULT CALENDAR, IMPLEMENT DROPDOWN.
System
.
out
.
println
(
currUser
);
...
...
@@ -67,19 +75,7 @@ public class CalendarController {
public
String
calendarGet
(
Model
models
)
{
//Get currently logged in user
Object
principal
=
SecurityContextHolder
.
getContext
().
getAuthentication
().
getPrincipal
();
String
username
=
""
;
if
(
principal
instanceof
UserDetails
)
{
username
=
((
UserDetails
)
principal
).
getUsername
();
}
else
{
username
=
principal
.
toString
();
}
User
currUser
=
userRepo
.
findByUsername
(
username
);
User
currUser
=
findCurrentUser
();
//If user doesnt have calendar - redirected to create
...
...
@@ -132,18 +128,7 @@ public class CalendarController {
}
//Get currently logged in user
Object
principal
=
SecurityContextHolder
.
getContext
().
getAuthentication
().
getPrincipal
();
String
username
=
""
;
if
(
principal
instanceof
UserDetails
)
{
username
=
((
UserDetails
)
principal
).
getUsername
();
}
else
{
username
=
principal
.
toString
();
}
User
currUser
=
userRepo
.
findByUsername
(
username
);
User
currUser
=
findCurrentUser
();
calendar
.
setUser
(
currUser
);
calendarRepo
.
save
(
calendar
);
...
...
@@ -156,16 +141,7 @@ public class CalendarController {
{
//This view will be for first time registered users.
Object
principal
=
SecurityContextHolder
.
getContext
().
getAuthentication
().
getPrincipal
();
String
username
=
""
;
if
(
principal
instanceof
UserDetails
)
{
username
=
((
UserDetails
)
principal
).
getUsername
();
}
else
{
username
=
principal
.
toString
();
}
User
currUser
=
userRepo
.
findByUsername
(
username
);
User
currUser
=
findCurrentUser
();
ArrayList
<
Calendar
>
calList
=
calendarRepo
.
findAllByUser
(
currUser
);
...
...
@@ -184,18 +160,8 @@ public class CalendarController {
return
"addNewCalendar"
;
}
Object
principal
=
SecurityContextHolder
.
getContext
().
getAuthentication
().
getPrincipal
();
User
currUser
=
findCurrentUser
();
String
username
=
""
;
if
(
principal
instanceof
UserDetails
)
{
username
=
((
UserDetails
)
principal
).
getUsername
();
}
else
{
username
=
principal
.
toString
();
}
User
currUser
=
userRepo
.
findByUsername
(
username
);
calendar
.
setUser
(
currUser
);
calendarRepo
.
save
(
calendar
);
...
...
src/main/java/com/example/calendar/controller/EventController.java
View file @
650fc19c
...
...
@@ -43,12 +43,8 @@ public class EventController {
@Autowired
private
EventValidator
eventValidator
;
@GetMapping
(
value
=
"/add-new-event"
)
public
String
addNewEventGet
(
Model
models
,
Event
event
)
public
User
findCurrentUser
()
{
List
<
EventType
>
allEventTypes
=
Arrays
.
asList
(
EventType
.
values
());
Object
principal
=
SecurityContextHolder
.
getContext
().
getAuthentication
().
getPrincipal
();
String
username
=
""
;
...
...
@@ -57,8 +53,19 @@ public class EventController {
}
else
{
username
=
principal
.
toString
();
}
User
currUser
=
userRepo
.
findByUsername
(
username
);
return
currUser
;
}
@GetMapping
(
value
=
"/add-new-event"
)
public
String
addNewEventGet
(
Model
models
,
Event
event
)
{
List
<
EventType
>
allEventTypes
=
Arrays
.
asList
(
EventType
.
values
());
User
currUser
=
findCurrentUser
();
//If user doesnt have calendar - redirected to create
...
...
@@ -87,15 +94,7 @@ public class EventController {
return
"addNewEvent"
;
}
Object
principal
=
SecurityContextHolder
.
getContext
().
getAuthentication
().
getPrincipal
();
String
username
=
""
;
if
(
principal
instanceof
UserDetails
)
{
username
=
((
UserDetails
)
principal
).
getUsername
();
}
else
{
username
=
principal
.
toString
();
}
User
currUser
=
userRepo
.
findByUsername
(
username
);
User
currUser
=
findCurrentUser
();
Calendar
c1
=
calendarRepo
.
findAllByUser
(
currUser
).
get
(
0
);
//TODO RIGHT NOW IT TAKES DEFAULT CALENDAR, IMPLEMENT DROPDOWN.
event
.
setCalendar
(
c1
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment