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
0cf882d9
Commit
0cf882d9
authored
Jun 14, 2019
by
s7_spruge_k
Browse files
user can have multiple calendars
parent
4b770530
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
64 additions
and
77 deletions
+64
-77
src/main/java/com/example/calendar/controller/CalendarController.java
...a/com/example/calendar/controller/CalendarController.java
+3
-5
src/main/java/com/example/calendar/controller/EventController.java
...java/com/example/calendar/controller/EventController.java
+16
-1
src/main/java/com/example/calendar/controller/UserController.java
.../java/com/example/calendar/controller/UserController.java
+9
-5
src/main/java/com/example/calendar/models/Calendar.java
src/main/java/com/example/calendar/models/Calendar.java
+9
-6
src/main/java/com/example/calendar/models/Event.java
src/main/java/com/example/calendar/models/Event.java
+2
-31
src/main/java/com/example/calendar/models/User.java
src/main/java/com/example/calendar/models/User.java
+21
-27
src/main/java/com/example/calendar/repo/CalendarRepo.java
src/main/java/com/example/calendar/repo/CalendarRepo.java
+3
-1
src/main/java/com/example/calendar/validator/EventValidator.java
...n/java/com/example/calendar/validator/EventValidator.java
+1
-1
No files found.
src/main/java/com/example/calendar/controller/CalendarController.java
View file @
0cf882d9
...
...
@@ -46,8 +46,8 @@ public class CalendarController {
}
User
currUser
=
userRepo
.
findByUsername
(
username
);
Calendar
c1
=
calendarRepo
.
findByUser
(
currUser
)
;
Calendar
c1
=
calendarRepo
.
find
All
ByUser
(
currUser
)
.
get
(
0
);
//TODO RIGHT NOW IT TAKES DEFAULT CALENDAR, IMPLEMENT DROPDOWN.
System
.
out
.
println
(
currUser
);
System
.
out
.
println
(
c1
);
System
.
out
.
println
(
calendarRepo
.
findAll
());
...
...
@@ -75,7 +75,7 @@ public class CalendarController {
User
currUser
=
userRepo
.
findByUsername
(
username
);
Calendar
c1
=
calendarRepo
.
findByUser
(
currUser
)
;
Calendar
c1
=
calendarRepo
.
find
All
ByUser
(
currUser
)
.
get
(
0
);
//TODO RIGHT NOW IT TAKES DEFAULT CALENDAR, IMPLEMENT DROPDOWN.
//Get Events By Calendar
...
...
@@ -98,6 +98,4 @@ public class CalendarController {
return
"calendar"
;
}
}
src/main/java/com/example/calendar/controller/EventController.java
View file @
0cf882d9
package
com.example.calendar.controller
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
org.springframework.beans.factory.annotation.Autowired
;
...
...
@@ -46,6 +47,20 @@ public class EventController {
public
String
addNewEventGet
(
Model
models
,
Event
event
)
{
List
<
EventType
>
allEventTypes
=
Arrays
.
asList
(
EventType
.
values
());
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
);
ArrayList
<
Calendar
>
allUserCalendars
=
calendarRepo
.
findAllByUser
(
currUser
);
models
.
addAttribute
(
"calendarList"
,
allUserCalendars
);
models
.
addAttribute
(
"eventTypes"
,
allEventTypes
);
return
"addNewEvent"
;
}
...
...
@@ -67,7 +82,7 @@ public class EventController {
username
=
principal
.
toString
();
}
User
currUser
=
userRepo
.
findByUsername
(
username
);
Calendar
c1
=
calendarRepo
.
findByUser
(
currUser
)
;
Calendar
c1
=
calendarRepo
.
find
All
ByUser
(
currUser
)
.
get
(
0
);
//TODO RIGHT NOW IT TAKES DEFAULT CALENDAR, IMPLEMENT DROPDOWN.
event
.
setCalendar
(
c1
);
eventRepo
.
save
(
event
);
...
...
src/main/java/com/example/calendar/controller/UserController.java
View file @
0cf882d9
package
com.example.calendar.controller
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.security.core.context.SecurityContextHolder
;
import
org.springframework.security.core.userdetails.UserDetails
;
...
...
@@ -7,6 +8,7 @@ import org.springframework.stereotype.Controller;
import
org.springframework.ui.Model
;
import
org.springframework.validation.BindingResult
;
import
org.springframework.web.bind.annotation.*
;
import
com.example.calendar.models.User
;
import
com.example.calendar.service.SecurityService
;
import
com.example.calendar.service.UserService
;
...
...
@@ -22,6 +24,7 @@ public class UserController {
@Autowired
private
UserValidator
userValidator
;
@GetMapping
(
"/registration"
)
public
String
registration
(
Model
model
)
{
...
...
@@ -48,14 +51,15 @@ public class UserController {
if
(
bindingResult
.
hasErrors
())
{
System
.
out
.
println
(
"error"
);
return
"registration"
;
userService
.
save
(
userForm
);
return
"registration"
;
}
userForm
.
getCalendar
().
setName
(
userForm
.
getUsername
()
+
" default Calendar"
);
userForm
.
getCalendar
().
setUser
(
userForm
);
userService
.
save
(
userForm
);
securityService
.
autoLogin
(
userForm
.
getUsername
(),
userForm
.
getPasswordConfirm
());
return
"redirect:/calendar"
;
}
...
...
src/main/java/com/example/calendar/models/Calendar.java
View file @
0cf882d9
package
com.example.calendar.models
;
import
java.time.LocalDate
;
import
java.util.ArrayList
;
import
java.util.Collection
;
import
javax.persistence.Column
;
...
...
@@ -10,8 +8,8 @@ import javax.persistence.GeneratedValue;
import
javax.persistence.GenerationType
;
import
javax.persistence.Id
;
import
javax.persistence.JoinColumn
;
import
javax.persistence.ManyToOne
;
import
javax.persistence.OneToMany
;
import
javax.persistence.OneToOne
;
import
javax.persistence.Table
;
@Entity
...
...
@@ -23,7 +21,7 @@ public class Calendar {
@GeneratedValue
(
strategy
=
GenerationType
.
AUTO
)
@Column
(
name
=
"ID_c"
)
private
int
calendar_ID
;
@
One
ToOne
@
Many
ToOne
@JoinColumn
(
name
=
"ID_u"
)
private
User
user
;
@OneToMany
(
mappedBy
=
"calendar"
)
...
...
@@ -50,26 +48,31 @@ public class Calendar {
public
User
getUser
()
{
return
user
;
}
public
void
setUser
(
User
user
)
{
this
.
user
=
user
;
}
public
Collection
<
Event
>
getEvent
()
{
return
event
;
}
public
void
setEvent
(
Collection
<
Event
>
event
)
{
this
.
event
=
event
;
}
public
String
getName
()
{
return
name
;
}
public
void
setName
(
String
name
)
{
this
.
name
=
name
;
}
public
int
getCalendar_ID
()
{
return
calendar_ID
;
}
@Override
public
String
toString
()
{
return
"Calendar [calendar_ID="
+
calendar_ID
+
", user="
+
user
+
", event="
+
event
+
", name="
+
name
+
"]"
;
...
...
src/main/java/com/example/calendar/models/Event.java
View file @
0cf882d9
...
...
@@ -58,8 +58,6 @@ public class Event{
//Set & Get
//TODO unit test
public
String
getName
()
{
return
name
;
}
...
...
@@ -84,9 +82,7 @@ public class Event{
//Cannot be previous date
public
void
setStartDate
(
LocalDate
startDate
)
{
this
.
startDate
=
startDate
;
this
.
startDate
=
startDate
;
}
...
...
@@ -132,35 +128,20 @@ public class Event{
}
public
Calendar
getCalendar
()
{
return
calendar
;
}
public
void
setCalendar
(
Calendar
calendar
)
{
this
.
calendar
=
calendar
;
}
public
void
setAllDayEvent
(
boolean
isAllDayEvent
)
{
this
.
isAllDayEvent
=
isAllDayEvent
;
}
/*Comparator for sorting the list by Student Name*/
public
static
Comparator
<
Event
>
eventDateComp
=
new
Comparator
<
Event
>()
{
...
...
@@ -178,15 +159,5 @@ public class Event{
return
e1
.
getStartTime
().
compareTo
(
e2
.
getStartTime
());
}};
// @Override
// public int compareTo(Event o) {
//
// if (getStartTime() == null || o.getStartTime() == null) {
// return 0;
// }
// return getStartTime().compareTo(o.getStartTime());
// }
//
}
src/main/java/com/example/calendar/models/User.java
View file @
0cf882d9
package
com.example.calendar.models
;
import
java.util.ArrayList
;
import
java.util.Collection
;
import
java.util.Set
;
import
javax.persistence.CascadeType
;
...
...
@@ -9,7 +11,7 @@ import javax.persistence.GeneratedValue;
import
javax.persistence.GenerationType
;
import
javax.persistence.Id
;
import
javax.persistence.ManyToMany
;
import
javax.persistence.OneTo
One
;
import
javax.persistence.OneTo
Many
;
import
javax.persistence.Table
;
import
org.springframework.data.annotation.Transient
;
...
...
@@ -34,11 +36,15 @@ public class User {
@Column
(
name
=
"ID_u"
)
private
int
user_ID
;
@OneTo
One
(
mappedBy
=
"user"
,
cascade
=
{
CascadeType
.
ALL
})
private
Calendar
calendar
=
new
Calendar
();
@OneTo
Many
(
mappedBy
=
"user"
,
cascade
=
{
CascadeType
.
ALL
})
private
Collection
<
Calendar
>
calendar
=
new
ArrayList
<
Calendar
>
();
public
User
()
{
Calendar
defaultCal
=
new
Calendar
();
defaultCal
.
setUser
(
this
);
calendar
.
add
(
defaultCal
);
}
public
User
(
String
username
,
String
password
)
{
...
...
@@ -46,7 +52,11 @@ public class User {
setPassword
(
password
);
}
public
void
addCalendar
(
Calendar
newCal
)
{
newCal
.
setUser
(
this
);
calendar
.
add
(
newCal
);
}
//Set & get
...
...
@@ -57,62 +67,46 @@ public class User {
public
void
setUsername
(
String
username
)
{
this
.
username
=
username
;
}
public
String
getPassword
()
{
return
password
;
}
public
void
setPassword
(
String
password
)
{
this
.
password
=
password
;
}
public
int
getUser_ID
()
{
return
user_ID
;
}
public
String
getPasswordConfirm
()
{
return
passwordConfirm
;
}
public
void
setPasswordConfirm
(
String
passwordConfirm
)
{
this
.
passwordConfirm
=
passwordConfirm
;
}
public
Set
<
Role
>
getRoles
()
{
return
roles
;
}
public
void
setRoles
(
Set
<
Role
>
roles
)
{
this
.
roles
=
roles
;
}
public
Calendar
getCalendar
()
{
public
Collection
<
Calendar
>
getCalendar
()
{
return
calendar
;
}
public
void
setCalendar
(
Calendar
calendar
)
{
public
void
setCalendar
(
Collection
<
Calendar
>
calendar
)
{
this
.
calendar
=
calendar
;
}
@Override
public
String
toString
()
{
return
"User [username="
+
username
+
", password="
+
password
+
", user_ID="
+
user_ID
+
"]"
;
return
"User [username="
+
username
+
", password="
+
password
+
", user_ID="
+
user_ID
+
", calendar="
+
calendar
+
"]"
;
}
}
src/main/java/com/example/calendar/repo/CalendarRepo.java
View file @
0cf882d9
package
com.example.calendar.repo
;
import
java.util.ArrayList
;
import
org.springframework.data.repository.CrudRepository
;
import
org.springframework.stereotype.Repository
;
...
...
@@ -8,5 +10,5 @@ import com.example.calendar.models.User;
@Repository
public
interface
CalendarRepo
extends
CrudRepository
<
Calendar
,
Integer
>{
Calendar
findByUser
(
User
user
);
ArrayList
<
Calendar
>
find
All
ByUser
(
User
user
);
}
src/main/java/com/example/calendar/validator/EventValidator.java
View file @
0cf882d9
...
...
@@ -76,7 +76,7 @@ public class EventValidator implements Validator {
username
=
principal
.
toString
();
}
User
currUser
=
userRepo
.
findByUsername
(
username
);
Calendar
c1
=
calendarRepo
.
findByUser
(
currUser
)
;
Calendar
c1
=
calendarRepo
.
find
All
ByUser
(
currUser
)
.
get
(
0
);
//TODO RIGHT NOW IT TAKES DEFAULT CALENDAR, IMPLEMENT DROPDOWN.
ArrayList
<
Event
>
allUserEvents
=
eventRepo
.
findAllByCalendar
(
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