fixed bugs
This commit is contained in:
@@ -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";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<NextBean> getNext(LocalDate date) {
|
||||
public List<NextBean> 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<Record4<String, LocalDate, Boolean, Boolean>, 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<NextBean> list = new ArrayList<>();
|
||||
while (i.hasNext()) {
|
||||
Record4<String, LocalDate, Boolean, Boolean> 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;
|
||||
}
|
||||
|
||||
@@ -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<NextBean> getNext(LocalDate date) {
|
||||
return repository.getNext(date);
|
||||
public List<NextBean> getNext(LocalDate date, String classname) {
|
||||
return repository.getNext(date, classname);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user