Commit 393300ea authored by s7_aigars_v's avatar s7_aigars_v
Browse files

Merge branch 'master' into 'add-new-event-calendar-dropdown'

# Conflicts:
#   src/main/java/com/example/calendar/controller/EventController.java
parents 43222a31 e7efd27b
......@@ -78,17 +78,16 @@ public class CalendarController {
User currUser = findCurrentUser();
//If user doesnt have calendar - redirected to create
try
{
calendarRepo.findAllByUser(currUser).get(0); //TODO RIGHT NOW IT TAKES DEFAULT CALENDAR, IMPLEMENT DROPDOWN.
calendarRepo.findAllByUser(currUser).get(0);
}
catch(Exception e)
{
return "redirect:/welcome";
}
Calendar c1 = calendarRepo.findAllByUser(currUser).get(0); //TODO RIGHT NOW IT TAKES DEFAULT CALENDAR, IMPLEMENT DROPDOWN.
Calendar c1 = calendarRepo.findAllByUser(currUser).get(currUser.getActiveCalendar()); //TODO RIGHT NOW IT TAKES DEFAULT CALENDAR, IMPLEMENT DROPDOWN.
//Get Events By Calendar
ArrayList<Event> allEvents = eventRepo.findAllByCalendar(c1);
......@@ -132,7 +131,8 @@ public class CalendarController {
calendar.setUser(currUser);
calendarRepo.save(calendar);
currUser.setActiveCalendar(currUser.getLastCalendar());
userRepo.save(currUser);
return "redirect:/calendar"; //TODO redirect to new calendar
}
......
......@@ -72,7 +72,7 @@ public class EventController {
try
{
calendarRepo.findAllByUser(currUser).get(0); //TODO RIGHT NOW IT TAKES DEFAULT CALENDAR, IMPLEMENT DROPDOWN.
calendarRepo.findAllByUser(currUser).get(0);
}
catch(Exception e)
{
......
......@@ -39,6 +39,8 @@ public class User {
@OneToMany(mappedBy = "user", cascade = {CascadeType.ALL})
private Collection<Calendar> calendar = new ArrayList<Calendar>();
@Column(name = "activeCalendar")
private int activeCalendar = 0;
public User() {
......@@ -56,6 +58,12 @@ public class User {
calendar.add(newCal);
}
public int getLastCalendar()
{
return calendar.size()-1;
}
//Set & get
public String getUsername() {
......@@ -102,8 +110,16 @@ public class User {
this.calendar = calendar;
}
public int getActiveCalendar() {
return activeCalendar;
}
public void setActiveCalendar(int activeCalendar) {
this.activeCalendar = activeCalendar;
}
@Override
public String toString() {
return "ID= " + user_ID +" " +username + " password=" + password;
return "ID= " + user_ID +" " +username + " password=" + password + "activeCal: " + activeCalendar;
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment