Commit dff1dc8d authored by s7_aigars_v's avatar s7_aigars_v
Browse files

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

# Conflicts:
#   src/main/java/com/example/calendar/controller/EventController.java
parents 9eb1b5fa 7766fbd8
HELP.md
/target/
!.mvn/wrapper/maven-wrapper.jar
db.h2.db
db.lock.db
*.db
### STS ###
.apt_generated
......@@ -32,6 +31,5 @@ db.lock.db
### MAC files ###
.DS_Store
.DS_Store
db.h2.db
db.h2.db.mv.db
package com.example.calendar.controller;
import java.util.ArrayList;
import java.util.Arrays;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -46,6 +47,25 @@ 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> c1 = calendarRepo.findAllByUser(currUser);
models.addAttribute("userCalendars", c1);
models.addAttribute("eventTypes", allEventTypes);
return "addNewEvent";
}
......@@ -73,8 +93,7 @@ public class EventController {
username = principal.toString();
}
User currUser = userRepo.findByUsername(username);
Calendar c1 = calendarRepo.findByUser(currUser);
event.setCalendar(c1);
//Calendar c1 = calendarRepo.findByUser(currUser);
eventRepo.save(event);
calendarRepo.save(c1);
......
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> findAllByUser(User user);
}
<!DOCTYPE html>
<html>
<head>
<title>SimpleCal</title>
</head>
<body>
ok
</body>
</html>
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