Commit 2774b0ee authored by s7_spruge_k's avatar s7_spruge_k
Browse files

fixed view-calendar validations

parent 723d6dcf
......@@ -193,7 +193,7 @@ public class CalendarController {
if(newName.equals(""))
{
newName = currUser.getUsername() + LocalTime.now().getNano();
newName = currUser.getUsername() + LocalTime.now().getHour()+ LocalTime.now().getMinute();
}
......@@ -206,7 +206,7 @@ public class CalendarController {
System.out.println(newName);
Calendar c1 = calendarRepo.findByNameAndUser(currUser.getActiveCalendar(), currUser);
Calendar c1 = calendarRepo.findByNameAndUser(currName, currUser);
System.out.println(c1);
if(c1.getName().equals(currUser.getActiveCalendar()))
......@@ -223,7 +223,8 @@ public class CalendarController {
@PostMapping(value="/view-calendars", params="action=delete")
public String deleteCalendar(Model model, String calName){
Calendar c1 = calendarRepo.findByName(calName);
User currUser = findCurrentUser();
Calendar c1 = calendarRepo.findByNameAndUser(calName, currUser);
ArrayList<Event> allEvents = eventRepo.findAllByCalendar(c1);
for (int i = 0; i < allEvents.size(); i++) {
......@@ -231,13 +232,10 @@ public class CalendarController {
}
calendarRepo.delete(c1);
User currUser = findCurrentUser();
ArrayList<Calendar> allUserCals = calendarRepo.findAllByUser(currUser);
currUser.setActiveCalendar(allUserCals.get(0).getName());
userRepo.save(currUser);
System.out.println(currUser);
System.out.println(allUserCals);
return "redirect:/view-calendars";
}
......
......@@ -128,10 +128,10 @@ public class EventController {
}
Calendar c1 = calendarRepo.findByName(calName);
Calendar c1 = calendarRepo.findByNameAndUser(calName, currUser);
if(c1 == null)
{
c1 = calendarRepo.findByName(currUser.getActiveCalendar());
c1 = calendarRepo.findByNameAndUser(currUser.getActiveCalendar(), currUser);
}
event.setCalendar(c1);
eventRepo.save(event);
......@@ -140,20 +140,4 @@ public class EventController {
}
@GetMapping(value = "/delete-event/{id}")
public String deleteEventGet(Model models, @PathVariable (name = "id") int eventID)
{
try
{
eventRepo.deleteById(eventID);
}
catch(Exception e)
{
return "redirect:/calendar";
}
return "redirect:/calendar";
}
}
......@@ -190,7 +190,7 @@ public class GraphController {
Calendar chosenCalendar = calendarRepo.findByName(calName);
try
{
ArrayList<Event> allEventsInCal = eventRepo.findAllByCalendar(chosenCalendar);
eventRepo.findAllByCalendar(chosenCalendar);
}
catch(Exception e)
{
......
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