preparing item service for use in document service
This commit is contained in:
@@ -15,6 +15,7 @@ dependencies{
|
|||||||
implementation(project(":contact"))
|
implementation(project(":contact"))
|
||||||
implementation(project(":core"))
|
implementation(project(":core"))
|
||||||
implementation(project(":documents"))
|
implementation(project(":documents"))
|
||||||
|
implementation(project(":items"))
|
||||||
implementation(project(":legacy"))
|
implementation(project(":legacy"))
|
||||||
implementation(project(":markdown"))
|
implementation(project(":markdown"))
|
||||||
implementation(project(":messages"))
|
implementation(project(":messages"))
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import de.srsoftware.umbrella.company.CompanyModule;
|
|||||||
import de.srsoftware.umbrella.core.Util;
|
import de.srsoftware.umbrella.core.Util;
|
||||||
import de.srsoftware.umbrella.core.exceptions.UmbrellaException;
|
import de.srsoftware.umbrella.core.exceptions.UmbrellaException;
|
||||||
import de.srsoftware.umbrella.documents.DocumentApi;
|
import de.srsoftware.umbrella.documents.DocumentApi;
|
||||||
|
import de.srsoftware.umbrella.items.ItemApi;
|
||||||
import de.srsoftware.umbrella.legacy.LegacyApi;
|
import de.srsoftware.umbrella.legacy.LegacyApi;
|
||||||
import de.srsoftware.umbrella.markdown.MarkdownApi;
|
import de.srsoftware.umbrella.markdown.MarkdownApi;
|
||||||
import de.srsoftware.umbrella.message.MessageApi;
|
import de.srsoftware.umbrella.message.MessageApi;
|
||||||
@@ -57,12 +58,14 @@ public class Application {
|
|||||||
var userModule = new UserModule(config,messageSystem);
|
var userModule = new UserModule(config,messageSystem);
|
||||||
var companyModule = new CompanyModule(config, userModule);
|
var companyModule = new CompanyModule(config, userModule);
|
||||||
var documentApi = new DocumentApi(companyModule, config);
|
var documentApi = new DocumentApi(companyModule, config);
|
||||||
|
var itemApi = new ItemApi(config,userModule);
|
||||||
var legacyApi = new LegacyApi(userModule.userDb(),config);
|
var legacyApi = new LegacyApi(userModule.userDb(),config);
|
||||||
var markdownApi = new MarkdownApi(userModule);
|
var markdownApi = new MarkdownApi(userModule);
|
||||||
var messageApi = new MessageApi(messageSystem);
|
var messageApi = new MessageApi(messageSystem);
|
||||||
var webHandler = new WebHandler();
|
var webHandler = new WebHandler();
|
||||||
|
|
||||||
documentApi .bindPath("/api/document") .on(server);
|
documentApi .bindPath("/api/document") .on(server);
|
||||||
|
itemApi .bindPath("/api/items") .on(server);
|
||||||
markdownApi .bindPath("/api/markdown") .on(server);
|
markdownApi .bindPath("/api/markdown") .on(server);
|
||||||
messageApi .bindPath("/api/messages") .on(server);
|
messageApi .bindPath("/api/messages") .on(server);
|
||||||
translationModule.bindPath("/api/translations").on(server);
|
translationModule.bindPath("/api/translations").on(server);
|
||||||
|
|||||||
@@ -72,7 +72,7 @@ public abstract class BaseHandler extends PathHandler {
|
|||||||
return sendEmptyResponse(HTTP_UNAUTHORIZED,ex);
|
return sendEmptyResponse(HTTP_UNAUTHORIZED,ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean notImplemented(HttpExchange ex,String message,Object clazz) throws IOException{
|
public boolean notImplemented(HttpExchange ex,String method,Object clazz) throws IOException{
|
||||||
return sendContent(ex,HTTP_NOT_IMPLEMENTED,format(message,clazz.getClass().getSimpleName()));
|
return sendContent(ex,HTTP_NOT_IMPLEMENTED,format("{0}.{1} not implemented",clazz.getClass().getSimpleName(),method));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,26 @@
|
|||||||
<script>
|
<script>
|
||||||
|
import { t } from '../../translations.svelte.js';
|
||||||
|
import { onMount } from 'svelte';
|
||||||
|
|
||||||
|
let items = $state(null);
|
||||||
|
let error = $state(null);
|
||||||
|
async function loadItems(){
|
||||||
|
const url = `${location.protocol}//${location.host.replace('5173','8080')}/api/items/list`;
|
||||||
|
const resp = await fetch(url,{credentials:'include'});
|
||||||
|
if (resp.ok){
|
||||||
|
items = await resp.json();
|
||||||
|
} else {
|
||||||
|
error = await resp.body();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
onMount(loadItems);
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<h1>Items</h1>
|
<h1>Items</h1>
|
||||||
|
{#if error}
|
||||||
|
<span class="error">{error}</span>
|
||||||
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
8
items/build.gradle.kts
Normal file
8
items/build.gradle.kts
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
description = "Umbrella : Items"
|
||||||
|
|
||||||
|
dependencies{
|
||||||
|
implementation(project(":core"))
|
||||||
|
implementation("de.srsoftware:configuration.api:1.0.2")
|
||||||
|
implementation("de.srsoftware:tools.jdbc:1.3.2")
|
||||||
|
implementation("de.srsoftware:tools.util:2.0.3")
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
package de.srsoftware.umbrella.items;
|
||||||
|
|
||||||
|
public class Constants {
|
||||||
|
private Constants(){}
|
||||||
|
|
||||||
|
public static final String CONFIG_DATABASE = "umbrella.modules.items.database";
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
package de.srsoftware.umbrella.items;
|
||||||
|
|
||||||
|
public class Item {
|
||||||
|
}
|
||||||
@@ -0,0 +1,53 @@
|
|||||||
|
package de.srsoftware.umbrella.items;
|
||||||
|
|
||||||
|
import com.sun.net.httpserver.HttpExchange;
|
||||||
|
import de.srsoftware.configuration.Configuration;
|
||||||
|
import de.srsoftware.tools.Path;
|
||||||
|
import de.srsoftware.tools.SessionToken;
|
||||||
|
import de.srsoftware.umbrella.core.BaseHandler;
|
||||||
|
import de.srsoftware.umbrella.core.api.UserService;
|
||||||
|
import de.srsoftware.umbrella.core.exceptions.UmbrellaException;
|
||||||
|
import de.srsoftware.umbrella.core.model.Token;
|
||||||
|
import de.srsoftware.umbrella.core.model.UmbrellaUser;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
import static de.srsoftware.umbrella.core.ConnectionProvider.connect;
|
||||||
|
import static de.srsoftware.umbrella.core.Paths.LIST;
|
||||||
|
import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.missingFieldException;
|
||||||
|
import static de.srsoftware.umbrella.items.Constants.CONFIG_DATABASE;
|
||||||
|
|
||||||
|
public class ItemApi extends BaseHandler {
|
||||||
|
|
||||||
|
private final ItemDb itemDb;
|
||||||
|
private final UserService users;
|
||||||
|
|
||||||
|
public ItemApi(Configuration config, UserService userService) throws UmbrellaException {
|
||||||
|
var dbFile = config.get(CONFIG_DATABASE).orElseThrow(() -> missingFieldException(CONFIG_DATABASE));
|
||||||
|
itemDb = new SqliteDb(connect(dbFile));
|
||||||
|
users = userService;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean doGet(Path path, HttpExchange ex) throws IOException {
|
||||||
|
addCors(ex);
|
||||||
|
try {
|
||||||
|
Optional<Token> token = SessionToken.from(ex).map(Token::of);
|
||||||
|
var user = users.loadUser(token);
|
||||||
|
if (user.isEmpty()) return unauthorized(ex);
|
||||||
|
var head = path.pop();
|
||||||
|
return switch (head) {
|
||||||
|
case LIST -> listItems(ex,user);
|
||||||
|
default -> super.doGet(path,ex);
|
||||||
|
};
|
||||||
|
} catch (UmbrellaException e){
|
||||||
|
return send(ex,e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean listItems(HttpExchange ex, Optional<UmbrellaUser> user) throws IOException {
|
||||||
|
var items = itemDb.list();
|
||||||
|
return notImplemented(ex,"listItems",this);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
package de.srsoftware.umbrella.items;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
|
public interface ItemDb {
|
||||||
|
Collection<Item> list();
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
package de.srsoftware.umbrella.items;
|
||||||
|
|
||||||
|
import java.sql.Connection;
|
||||||
|
|
||||||
|
public class SqliteDb implements ItemDb{
|
||||||
|
private final Connection db;
|
||||||
|
|
||||||
|
public SqliteDb(Connection connection) {
|
||||||
|
db = connection;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -12,4 +12,5 @@ include("web")
|
|||||||
include("company")
|
include("company")
|
||||||
include("contact")
|
include("contact")
|
||||||
|
|
||||||
include("markdown")
|
include("markdown")
|
||||||
|
include("items")
|
||||||
Reference in New Issue
Block a user