Commit e6270fc5 authored by s7_spruge_k's avatar s7_spruge_k
Browse files

edit event verifications done

parent 06e8b0b6
......@@ -80,9 +80,13 @@ public class CalendarController {
Calendar c1 = calendarRepo.findByNameAndUser(currUser.getActiveCalendar(), currUser);
//Get Events By Calendar
ArrayList<Event> allEvents = eventRepo.findAllByCalendar(c1);
//Info to fill out calendar.
JsonArray eventArray = new JsonArray();
for (int i = 0; i < allEvents.size(); i++) {
......@@ -97,11 +101,7 @@ public class CalendarController {
List<EventType> allEventTypes = Arrays.asList(EventType.values());
models.addAttribute("calendarName", c1.getName());
models.addAttribute("currentTime", LocalTime.now().toString());
models.addAttribute("eventTypes", allEventTypes);
models.addAttribute("currentDate", LocalDate.now().toString());
models.addAttribute("currentMonth", LocalDate.now().getMonth());
models.addAttribute("currentDay", LocalDate.now().getDayOfWeek());
models.addAttribute("currentUser", currUser);
models.addAttribute("allEvents", eventArray);
......@@ -116,13 +116,52 @@ public class CalendarController {
String[] dateTimeParts = oldDate.split("T");
LocalDate localDate = LocalDate.parse(dateTimeParts[0]);
LocalTime localTime = LocalTime.parse(dateTimeParts[1]);
Calendar c1 = calendarRepo.findByName(currUser.getActiveCalendar());
Calendar c1 = calendarRepo.findByNameAndUser(currUser.getActiveCalendar(), currUser);
Event e1 = eventRepo.findByCalendarAndStartDateAndStartTime(c1, localDate, localTime);
e1.setName(event.getName());
//Simple validations
String tempName = event.getName();
if(tempName.equals(""))
{
tempName = e1.getName();
}
LocalDate tempDate = event.getStartDate();
LocalTime tempTime = event.getStartTime();
LocalDate currentDate = LocalDate.now();
LocalTime currentTime = LocalTime.now();
ArrayList<Event> allEventsInUserCal = eventRepo.findAllByCalendar(c1);
//If user has an event that time - keep previous date.
for (Event e: allEventsInUserCal) {
if(e.getStartDate().equals(tempDate) && e.getStartTime().equals(tempTime))
{
tempDate = e1.getStartDate();
tempTime = e1.getStartTime();
}
}
//Checks if date is not in the past.
if(tempDate.isBefore(currentDate))
{
tempDate = e1.getStartDate();
tempTime= e1.getStartTime();
}
else if(tempDate.equals(currentDate) && tempTime.isBefore(currentTime))
{
tempDate = e1.getStartDate();
tempTime= e1.getStartTime();
}
e1.setName(tempName);
e1.setDescription(event.getDescription());
e1.setStartDate(event.getStartDate());
e1.setStartTime(event.getStartTime());
e1.setStartDate(tempDate);
e1.setStartTime(tempTime);
e1.setEventType(event.getEventType());
eventRepo.save(e1);
......@@ -136,7 +175,7 @@ public class CalendarController {
String[] dateTimeParts = oldDate.split("T");
LocalDate localDate = LocalDate.parse(dateTimeParts[0]);
LocalTime localTime = LocalTime.parse(dateTimeParts[1]);
Calendar c1 = calendarRepo.findByName(currUser.getActiveCalendar());
Calendar c1 = calendarRepo.findByNameAndUser(currUser.getActiveCalendar(), currUser);
Event e1 = eventRepo.findByCalendarAndStartDateAndStartTime(c1, localDate, localTime);
eventRepo.delete(e1);
......
......@@ -10,7 +10,6 @@ import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import com.example.calendar.models.Calendar;
......
......@@ -98,7 +98,7 @@ public class GraphController {
eventCounter.add(0);
continue;
}
for (Event event : eventRepo.findAllByCalendar(c)) {
for (@SuppressWarnings("unused") Event event : eventRepo.findAllByCalendar(c)) {
temp++;
}
......
......@@ -10,10 +10,8 @@ import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToMany;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import org.springframework.data.annotation.Transient;
......
......@@ -5,8 +5,6 @@ import java.time.LocalTime;
import java.util.ArrayList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.stereotype.Component;
import org.springframework.validation.Errors;
import org.springframework.validation.ValidationUtils;
......@@ -14,7 +12,6 @@ import org.springframework.validation.Validator;
import com.example.calendar.models.Calendar;
import com.example.calendar.models.Event;
import com.example.calendar.models.User;
import com.example.calendar.repo.CalendarRepo;
import com.example.calendar.repo.EventRepo;
import com.example.calendar.repo.UserRepo;
......
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