preparing for adding positions to document

This commit is contained in:
2025-07-15 21:58:06 +02:00
parent 148c0f27b5
commit e436f09698
14 changed files with 211 additions and 48 deletions

View File

@@ -79,6 +79,7 @@ public class Constants {
public static final String PATH_POSITIONS = "positions";
public static final String PATH_SEND = "send";
public static final String PATH_TYPES = "types";
public static final String POSITION = "position";
public static final String PROJECT_ID = "project_id";
public static final String STATES = "states";

View File

@@ -141,7 +141,15 @@ public class DocumentApi extends BaseHandler {
case LIST -> listCompaniesDocuments(ex,user.get(),token.orElse(null));
case TEMPLATES -> postTemplateList(ex,user.get());
case null -> postDocument(ex,user.get());
default -> super.doPost(path,ex);
default -> {
var docId = 0L;
try {
docId = Long.parseLong(head);
} catch (NumberFormatException ignored) {
yield super.doPost(path,ex);
}
yield postToDocument(ex,path,user.get(),docId);
}
};
} catch (UmbrellaException e) {
return send(ex,e);
@@ -247,6 +255,10 @@ public class DocumentApi extends BaseHandler {
return sendContent(ex,saved.toMap());
}
private boolean postDocumentPosition(long docId, HttpExchange ex, UmbrellaUser user) throws IOException {
return notImplemented(ex,"postDocumentPosition",this);
}
private boolean postTemplateList(HttpExchange ex, UmbrellaUser user) throws UmbrellaException, IOException {
var json = json(ex);
if (!(json.has(COMPANY) && json.get(COMPANY) instanceof Number companyId)) throw missingFieldException(COMPANY);
@@ -255,4 +267,13 @@ public class DocumentApi extends BaseHandler {
var templates = db.getCompanyTemplates(companyId.longValue());
return sendContent(ex,templates.stream().map(Template::toMap));
}
private boolean postToDocument(HttpExchange ex, Path path, UmbrellaUser user, long docId) throws IOException {
var head = path.pop();
return switch (head){
case POSITION -> postDocumentPosition(docId,ex,user);
case null, default -> super.doPost(path,ex);
};
}
}