conveniance modification: added registry and getters for modules to BaseHandler
Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
This commit is contained in:
@@ -25,13 +25,12 @@ import org.json.JSONArray;
|
||||
|
||||
public class TagModule extends BaseHandler implements TagService {
|
||||
private final SqliteDb tagDb;
|
||||
private final ModuleRegistry registry;
|
||||
|
||||
public TagModule(ModuleRegistry registry, Configuration config) {
|
||||
super(registry);
|
||||
var tagDbFile = config.get(CONFIG_DATABASE).orElseThrow(() -> missingFieldException(CONFIG_DATABASE));
|
||||
var bmDbFile = config.get(de.srsoftware.umbrella.bookmarks.Constants.CONFIG_DATABASE).orElseThrow(() -> missingFieldException(de.srsoftware.umbrella.bookmarks.Constants.CONFIG_DATABASE));
|
||||
tagDb = new SqliteDb(connect(tagDbFile),connect(bmDbFile));
|
||||
this.registry = registry.add(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -44,7 +43,7 @@ public class TagModule extends BaseHandler implements TagService {
|
||||
addCors(ex);
|
||||
try {
|
||||
Optional<Token> token = SessionToken.from(ex).map(Token::of);
|
||||
var user = registry.userService().loadUser(token);
|
||||
var user = userService().loadUser(token);
|
||||
if (user.isEmpty()) return unauthorized(ex);
|
||||
var module = path.pop();
|
||||
if (module == null) throw unprocessable("Module missing in path.");
|
||||
@@ -63,7 +62,7 @@ public class TagModule extends BaseHandler implements TagService {
|
||||
public boolean doGet(Path path, HttpExchange ex) throws IOException {
|
||||
addCors(ex);
|
||||
try {
|
||||
var user = registry.userService().refreshSession(ex);
|
||||
var user = userService().refreshSession(ex);
|
||||
if (user.isEmpty()) return unauthorized(ex);
|
||||
var module = path.pop();
|
||||
if (module == null) throw unprocessable("Module missing in path.");
|
||||
@@ -87,7 +86,7 @@ public class TagModule extends BaseHandler implements TagService {
|
||||
addCors(ex);
|
||||
try {
|
||||
Optional<Token> token = SessionToken.from(ex).map(Token::of);
|
||||
var user = registry.userService().loadUser(token);
|
||||
var user = userService().loadUser(token);
|
||||
if (user.isEmpty()) return unauthorized(ex);
|
||||
var module = path.pop();
|
||||
if (module == null) throw unprocessable("Module missing in path.");
|
||||
|
||||
Reference in New Issue
Block a user