completed company deletion implementation
Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
This commit is contained in:
@@ -5,7 +5,4 @@ public class Constants {
|
||||
private Constants(){}
|
||||
public static final String CONFIG_DATABASE = "umbrella.modules.items.database";
|
||||
public static final String TABLE_ITEMS = "items";
|
||||
public static final String TAX = "tax";
|
||||
public static final String UNIT = "unit";
|
||||
public static final String UNIT_PRICE = "unit_price";
|
||||
}
|
||||
|
||||
@@ -1,39 +0,0 @@
|
||||
/* © SRSoftware 2025 */
|
||||
package de.srsoftware.umbrella.items;
|
||||
|
||||
import static de.srsoftware.umbrella.core.Constants.*;
|
||||
import static de.srsoftware.umbrella.core.Constants.CODE;
|
||||
import static de.srsoftware.umbrella.core.Util.mapMarkdown;
|
||||
import static de.srsoftware.umbrella.items.Constants.*;
|
||||
|
||||
import de.srsoftware.tools.Mappable;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Map;
|
||||
|
||||
public record Item(long id, long companyId, String code, String name, String description, String unit, long unitPrice, long tax) implements Mappable {
|
||||
public static Item of(ResultSet rs) throws SQLException {
|
||||
var id = rs.getLong(ID);
|
||||
var companyId = rs.getLong(COMPANY_ID);
|
||||
var code = rs.getString(CODE);
|
||||
var name = rs.getString(NAME);
|
||||
var desc = rs.getString(DESCRIPTION);
|
||||
var unit = rs.getString(UNIT);
|
||||
var unitPrice = rs.getLong(UNIT_PRICE);
|
||||
var tax = rs.getInt(TAX);
|
||||
|
||||
return new Item(id,companyId,code,name,desc,unit,unitPrice,tax);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> toMap() {
|
||||
return Map.of(
|
||||
ID,id,
|
||||
COMPANY_ID,companyId,
|
||||
CODE,code,NAME,name,
|
||||
DESCRIPTION,mapMarkdown(description),
|
||||
UNIT,unit,
|
||||
UNIT_PRICE,unitPrice,
|
||||
TAX,tax);
|
||||
}
|
||||
}
|
||||
@@ -16,9 +16,11 @@ import de.srsoftware.umbrella.core.BaseHandler;
|
||||
import de.srsoftware.umbrella.core.ModuleRegistry;
|
||||
import de.srsoftware.umbrella.core.api.ItemService;
|
||||
import de.srsoftware.umbrella.core.exceptions.UmbrellaException;
|
||||
import de.srsoftware.umbrella.core.model.Item;
|
||||
import de.srsoftware.umbrella.core.model.Token;
|
||||
import de.srsoftware.umbrella.core.model.UmbrellaUser;
|
||||
import java.io.IOException;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Optional;
|
||||
|
||||
@@ -50,13 +52,18 @@ public class ItemApi extends BaseHandler implements ItemService {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<Item> list(long companyId) throws UmbrellaException {
|
||||
return itemDb.list(companyId);
|
||||
}
|
||||
|
||||
private boolean listItems(HttpExchange ex, UmbrellaUser user) throws IOException, UmbrellaException {
|
||||
var json = json(ex);
|
||||
if (!(json.has(COMPANY_ID) && json.get(COMPANY_ID) instanceof Number cid)) throw missingFieldException(COMPANY_ID);
|
||||
var companyId = cid.longValue();
|
||||
var company = registry.companyService().get(companyId);
|
||||
if (!registry.companyService().membership(companyId,user.id())) throw forbidden("You are mot a member of company {0}",company.name());
|
||||
var items = itemDb.list(companyId)
|
||||
var items = list(companyId)
|
||||
.stream()
|
||||
.map(Item::toMap)
|
||||
.map(HashMap::new)
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
package de.srsoftware.umbrella.items;
|
||||
|
||||
import de.srsoftware.umbrella.core.exceptions.UmbrellaException;
|
||||
import de.srsoftware.umbrella.core.model.Item;
|
||||
import java.util.Collection;
|
||||
|
||||
public interface ItemDb {
|
||||
|
||||
@@ -8,6 +8,7 @@ import static de.srsoftware.umbrella.core.Constants.COMPANY_ID;
|
||||
import static de.srsoftware.umbrella.items.Constants.TABLE_ITEMS;
|
||||
|
||||
import de.srsoftware.umbrella.core.exceptions.UmbrellaException;
|
||||
import de.srsoftware.umbrella.core.model.Item;
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Collection;
|
||||
|
||||
Reference in New Issue
Block a user