working on project view

This commit is contained in:
2025-07-19 00:40:28 +02:00
parent 08838e8ddc
commit 744b8a4576
6 changed files with 22 additions and 4 deletions

View File

@@ -6,13 +6,16 @@ import static java.nio.charset.StandardCharsets.UTF_8;
public class Constants {
private Constants(){}
public static final String ADDRESS = "address";
public static final String ATTACHMENTS = "attachments";
public static final String AUTHORIZATION = "Authorization";
public static final String BODY = "body";
public static final String COMPANY = "company";
public static final String COMPANY_ID = "company_id";
public static final String CONTENT_TYPE = "Content-Type";
public static final String DATA = "data";
public static final String DATE = "date";
public static final String DEFAULT_LANGUAGE = "en";
@@ -21,6 +24,7 @@ public class Constants {
public static final String DOMAIN = "domain";
public static final String DUE_DATE = "due_date";
public static final String DURATION = "duration";
public static final String EMAIL = "email";
public static final String END_TIME = "end_time";

View File

@@ -11,7 +11,7 @@ import static java.net.HttpURLConnection.HTTP_NOT_FOUND;
import static java.text.MessageFormat.format;
public class UmbrellaException extends Exception{
public class UmbrellaException extends RuntimeException{
private final int statusCode;
public UmbrellaException(String message, Object ... fills){

View File

@@ -39,6 +39,14 @@ public record Project(long id, String name, String description, Status status, L
}
}
public boolean hasMember(UmbrellaUser user) {
for (var member : members){
if (member.userId() == user.id()) return true;
}
return false;
}
public static Project of(ResultSet rs) throws SQLException {
return new Project(rs.getLong(ID),rs.getString(NAME),rs.getString(DESCRIPTION),Status.of(rs.getInt(STATUS)),rs.getLong(COMPANY_ID),rs.getBoolean(SHOW_CLOSED),new ArrayList<>());
}

View File

@@ -12,8 +12,6 @@ public class Constants {
public static final Pattern POST_CODE = compile("(.*\\w+.*)\n(.*\\d+.*)\n(\\d{5}) (\\w+)",DOTALL);
public static final String COMPANIES = "companies";
public static final String COMPANY = "company";
public static final String CONFIG_DATABASE = "umbrella.modules.document.database";
public static final String CONFIG_TEMPLATES = "umbrella.modules.document.templates";

View File

@@ -31,6 +31,12 @@
<th>{t('project')}</th>
<td>{project.name}</td>
</tr>
{#if project.company}
<tr>
<th>{t('company')}</th>
<td>{project.company.name}</td>
</tr>
{/if}
<tr>
<th>{t('context')}</th>
<td>

View File

@@ -1,6 +1,7 @@
/* © SRSoftware 2025 */
package de.srsoftware.umbrella.project;
import static de.srsoftware.tools.Optionals.nullable;
import static de.srsoftware.umbrella.core.ConnectionProvider.connect;
import static de.srsoftware.umbrella.core.Constants.*;
import static de.srsoftware.umbrella.core.Paths.LIST;
@@ -87,6 +88,7 @@ public class ProjectModule extends BaseHandler implements ProjectService {
private boolean getProject(HttpExchange ex, long projectId, UmbrellaUser user) throws IOException, UmbrellaException {
var project = projects.load(projectId);
if (!project.hasMember(user)) throw forbidden("You are not a member of {0}",project.name());
var map = project.toMap();
var members = new HashMap<Long,Map<String,Object>>();
for (var member : project.members()){
@@ -95,7 +97,7 @@ public class ProjectModule extends BaseHandler implements ProjectService {
members.put(userId,Map.of(USER,users.loadUser(userId).toMap(),PERMISSION,perm));
}
if (!members.isEmpty()) map.put(MEMBERS,members);
nullable(project.companyId()).map(companies::get).map(Company::toMap).ifPresent(data -> map.put(COMPANY,data));
return sendContent(ex,map);
}