diff --git a/build.gradle b/build.gradle index 6a1acd3..0cd986f 100644 --- a/build.gradle +++ b/build.gradle @@ -48,6 +48,8 @@ dependencies { implementation 'org.mnode.ical4j:ical4j:4.2.2' + implementation 'org.jooq:jooq:3.20.10' + implementation 'org.springframework.boot:spring-boot-starter-jooq' implementation 'org.springframework.boot:spring-boot-starter-oauth2-client' implementation 'org.springframework.boot:spring-boot-starter-thymeleaf' diff --git a/src/main/java/de/jottyfan/bico/config/SecurityConfig.java b/src/main/java/de/jottyfan/bico/config/SecurityConfig.java index 32cf44c..4f69627 100644 --- a/src/main/java/de/jottyfan/bico/config/SecurityConfig.java +++ b/src/main/java/de/jottyfan/bico/config/SecurityConfig.java @@ -17,7 +17,7 @@ public class SecurityConfig { SecurityFilterChain filterChain(HttpSecurity http) throws Exception { http.authorizeHttpRequests( // @formatter:off - r -> r.requestMatchers("/", "/error", "/css/**", "/js/**", "/webjars/**", "/template").permitAll() + r -> r.requestMatchers("/", "/error", "/css/**", "/js/**", "/webjars/**", "/template", "/updateTheme/*").permitAll() .requestMatchers("/**").authenticated()) .oauth2Login(l -> l.authorizationEndpoint(e -> e.baseUri("/oauth2/authorize-client"))); // @formatter:on diff --git a/src/main/java/de/jottyfan/bico/modules/next/NextController.java b/src/main/java/de/jottyfan/bico/modules/next/NextController.java index 3a7b25e..3614c2c 100644 --- a/src/main/java/de/jottyfan/bico/modules/next/NextController.java +++ b/src/main/java/de/jottyfan/bico/modules/next/NextController.java @@ -8,31 +8,33 @@ import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestParam; import de.jottyfan.bico.modules.CommonController; /** - * + * * @author jotty - * + * */ @Controller public class NextController extends CommonController { @Autowired private NextService service; - + @GetMapping("/next") - public String getNext(Model model) { - model.addAttribute("list", service.getNext(LocalDate.now())); + public String getNext(@RequestParam(name = "groupname", required = false) String groupname, Model model) { + model.addAttribute("list", service.getNext(LocalDate.now(), groupname)); return "/next"; } - + @GetMapping("/next/{date}") - public String getNextForDate(@PathVariable("date") String dateStr, Model model) { + public String getNextForDate(@PathVariable("date") String dateStr, + @RequestParam(name = "groupname", required = false) String groupname, Model model) { DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); - LocalDate date = LocalDate.parse(dateStr, formatter); - model.addAttribute("list", service.getNext(date)); + LocalDate date = LocalDate.parse(dateStr, formatter); + model.addAttribute("list", service.getNext(date, groupname)); return "/next"; } } diff --git a/src/main/java/de/jottyfan/bico/modules/next/NextRepository.java b/src/main/java/de/jottyfan/bico/modules/next/NextRepository.java index b79dc20..83f0ac9 100644 --- a/src/main/java/de/jottyfan/bico/modules/next/NextRepository.java +++ b/src/main/java/de/jottyfan/bico/modules/next/NextRepository.java @@ -9,9 +9,11 @@ import java.util.List; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import org.jooq.Condition; import org.jooq.DSLContext; import org.jooq.Record4; import org.jooq.SelectSeekStep1; +import org.jooq.impl.DSL; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Repository; @@ -32,15 +34,25 @@ public class NextRepository { /** * get the next dates from date on * - * @param date the date + * @param date the date + * @param classname the classname to filter for * @return the next dates as beans in a list; an empty list at least */ - public List getNext(LocalDate date) { + public List getNext(LocalDate date, String classname) { + Condition filter = DSL.trueCondition(); + if (classname == null) { + filter = DSL.trueCondition(); + } else if (classname.equals("bibleclass")) { + filter = V_CALENDAR.BIBLECLASS.isTrue(); + } else if (classname.equals("youthgroup")) { + filter = V_CALENDAR.YOUTHGROUP.isTrue(); + } SelectSeekStep1, LocalDate> sql = jooq // @formatter:off .selectDistinct(V_CALENDAR.FULLNAME, V_CALENDAR.SLOT_DAY, V_CALENDAR.BIBLECLASS, V_CALENDAR.YOUTHGROUP) .from(V_CALENDAR) .where(V_CALENDAR.SLOT_DAY.ge(date)) + .and(filter) .orderBy(V_CALENDAR.SLOT_DAY.asc()); // @formatter:on LOGGER.trace(sql); @@ -48,7 +60,8 @@ public class NextRepository { List list = new ArrayList<>(); while (i.hasNext()) { Record4 r = i.next(); - list.add(NextBean.of(r.get(V_CALENDAR.FULLNAME), r.get(V_CALENDAR.SLOT_DAY), r.get(V_CALENDAR.BIBLECLASS), r.get(V_CALENDAR.YOUTHGROUP))); + list.add(NextBean.of(r.get(V_CALENDAR.FULLNAME), r.get(V_CALENDAR.SLOT_DAY), r.get(V_CALENDAR.BIBLECLASS), + r.get(V_CALENDAR.YOUTHGROUP))); } return list; } diff --git a/src/main/java/de/jottyfan/bico/modules/next/NextService.java b/src/main/java/de/jottyfan/bico/modules/next/NextService.java index 5bb46bc..a4f5bb8 100644 --- a/src/main/java/de/jottyfan/bico/modules/next/NextService.java +++ b/src/main/java/de/jottyfan/bico/modules/next/NextService.java @@ -9,24 +9,25 @@ import org.springframework.stereotype.Service; import de.jottyfan.bico.modules.next.model.NextBean; /** - * + * * @author jotty - * + * */ @Service public class NextService { @Autowired private NextRepository repository; - + /** * get the next dates - * + * * @param date the date + * @param classname the classname to filter for * @return the list of next dates */ - public List getNext(LocalDate date) { - return repository.getNext(date); + public List getNext(LocalDate date, String classname) { + return repository.getNext(date, classname); } - + } diff --git a/src/main/java/de/jottyfan/bico/modules/profile/ProfileController.java b/src/main/java/de/jottyfan/bico/modules/profile/ProfileController.java index 1319521..e021f48 100644 --- a/src/main/java/de/jottyfan/bico/modules/profile/ProfileController.java +++ b/src/main/java/de/jottyfan/bico/modules/profile/ProfileController.java @@ -1,7 +1,12 @@ package de.jottyfan.bico.modules.profile; +import java.security.Principal; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.ResponseEntity; +import org.springframework.security.oauth2.client.authentication.OAuth2AuthenticationToken; +import org.springframework.security.oauth2.core.user.OAuth2User; +import org.springframework.web.bind.annotation.CrossOrigin; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RestController; @@ -23,12 +28,20 @@ public class ProfileController extends CommonController { * update the theme of the current user * * @param theme the theme + * */ + @CrossOrigin(origins = "*") @PostMapping("/updateTheme/{theme}") - public ResponseEntity updateTheme(@PathVariable("theme") String theme) { - // TODO: add profile's user name - String username = "jotty"; - service.updateTheme(username, theme); + public ResponseEntity updateTheme(@PathVariable("theme") String theme, Principal principal) { + String username = null; + OAuth2AuthenticationToken token = (OAuth2AuthenticationToken) principal; + if (token != null) { + OAuth2User user = token.getPrincipal(); + username = user.getName(); + } + if (username != null) { + service.updateTheme(username, theme); + } return ResponseEntity.ok(null); } diff --git a/src/main/resources/static/js/stylehelp.js b/src/main/resources/static/js/stylehelp.js index 36b620b..b89599d 100644 --- a/src/main/resources/static/js/stylehelp.js +++ b/src/main/resources/static/js/stylehelp.js @@ -8,7 +8,10 @@ toggleDarkMode = function() { url: updateUrl, type: "POST", contentType: "application/json", - dataType: 'json' + dataType: 'json', + xhrFields: { + withCredentials: true + } }); } diff --git a/src/main/resources/templates/next.html b/src/main/resources/templates/next.html index 8c5682a..f48dd76 100644 --- a/src/main/resources/templates/next.html +++ b/src/main/resources/templates/next.html @@ -4,6 +4,10 @@
+
Bibelunt.
diff --git a/src/main/resources/templates/template.html b/src/main/resources/templates/template.html index ec1a633..e4da598 100644 --- a/src/main/resources/templates/template.html +++ b/src/main/resources/templates/template.html @@ -1,5 +1,5 @@ - + Bible Class Organizer @@ -25,10 +25,6 @@