Commit 313c710d authored by s7_spruge_k's avatar s7_spruge_k
Browse files

Merge branch 'calendar-controller' into 'master'

Calendar controller

See merge request s7_spruge_k/calendar!10
parents 7aa8f395 3f68917f
package com.example.calendar.controller;
import java.time.LocalDate;
import java.time.LocalTime;
import java.util.ArrayList;
import java.util.Collections;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import com.example.calendar.models.Calendar;
import com.example.calendar.models.Event;
import com.example.calendar.repo.CalendarRepo;
import com.example.calendar.repo.EventRepo;
import com.example.calendar.repo.UserRepo;
@Controller
public class CalendarController {
@Autowired
UserRepo userRepo;
@Autowired
CalendarRepo calendarRepo;
@Autowired
EventRepo eventRepo;
@GetMapping(value = "/month-view")
public String monthViewGet(Model models)
{
models.addAttribute("currentTime", LocalTime.now());
models.addAttribute("currentDate", LocalDate.now());
models.addAttribute("currentMonth", LocalDate.now().getMonth());
//TODO how to pass User?
return "monthView";
}
@GetMapping(value = "/week-view")
public String weekViewGet(Model models)
{
models.addAttribute("currentTime", LocalTime.now());
models.addAttribute("currentDate", LocalDate.now());
models.addAttribute("currentMonth", LocalDate.now().getMonth());
//TODO how to pass User?
return "weekView";
}
@GetMapping(value = "/day-view")
public String dayViewGet(Model models)
{
models.addAttribute("currentTime", LocalTime.now());
models.addAttribute("currentDate", LocalDate.now());
models.addAttribute("currentMonth", LocalDate.now().getMonth());
models.addAttribute("currentDay", LocalDate.now().getDayOfWeek());
//TODO how to pass User?
// //1. Get currently logged in user
//
//
// //2. Get Calendar By User
// Calendar c1 = calendarRepo.findByUser(user);
//
//
// //3. Get Events By Calendar
// ArrayList<Event> todayEvents = eventRepo.findAllByCalendar(c1);
//
// //4. Get Events By currentDay.
// for (Event e : todayEvents) {
// if(!e.getStartDate().equals(LocalDate.now()))
// todayEvents.remove(e); //Neesmu parliecinats vai shitaa strada, ja nu kas var veidot jaunu arrayList
// } //Kura uzglaba vertibas
//
// //Vajag sakartot hronologiski pec laikiem, lai vieglak izmantotu skataa.
// //event klasee ir compareTo, kas salidzina pec laikiem
// Collections.sort(todayEvents);
//
// models.addAttribute("todayEvents", todayEvents);
return "dayView";
}
}
......@@ -16,7 +16,7 @@ import org.springframework.format.annotation.DateTimeFormat;
@Entity
@Table(name = "EventTable")
public class Event {
public class Event implements Comparable<Event>{
@Column(name = "Name")
private String name;
......@@ -168,6 +168,13 @@ public class Event {
super();
}
@Override
public int compareTo(Event o) {
if (getStartTime() == null || o.getStartTime() == null) {
return 0;
}
return getStartTime().compareTo(o.getStartTime());
}
}
......@@ -4,8 +4,9 @@ import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;
import com.example.calendar.models.Calendar;
import com.example.calendar.models.User;
@Repository
public interface CalendarRepo extends CrudRepository<Calendar, Integer>{
Calendar findByUser(User user);
}
package com.example.calendar.repo;
import java.time.LocalDate;
import java.util.ArrayList;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;
import com.example.calendar.models.Calendar;
import com.example.calendar.models.Event;
@Repository
public interface EventRepo extends CrudRepository<Event, Integer> {
ArrayList<Event> findAllByCalendar(Calendar calendar);
ArrayList<Event> findAllByLocalDate(LocalDate localDate);
}
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