refactoring project module: better separation of loading of projects and loading of project members
This commit is contained in:
@@ -11,7 +11,10 @@ public class 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 CODE = "code";
|
||||
public static final String COMPANY = "company";
|
||||
public static final String COMPANY_ID = "company_id";
|
||||
public static final String CONTENT_TYPE = "Content-Type";
|
||||
|
||||
@@ -4,10 +4,17 @@ package de.srsoftware.umbrella.core.api;
|
||||
import de.srsoftware.umbrella.core.exceptions.UmbrellaException;
|
||||
import de.srsoftware.umbrella.core.model.Project;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public interface ProjectService {
|
||||
public Collection<Project> listCompanyProjects(long companyId, boolean includeClosed) throws UmbrellaException;
|
||||
public Map<Long,Project> listUserProjects(long userId, boolean includeClosed) throws UmbrellaException;
|
||||
CompanyService companyService();
|
||||
public Map<Long,Project> listCompanyProjects(long companyId, boolean includeClosed) throws UmbrellaException;
|
||||
public Map<Long,Project> listUserProjects(long userId, boolean includeClosed) throws UmbrellaException;
|
||||
public Collection<Project> loadMembers(Collection<Project> projects);
|
||||
public default Project loadMembers(Project project){
|
||||
loadMembers(List.of(project));
|
||||
return project;
|
||||
}
|
||||
Map<Long, Map<String,Object>> mapProjects(Map<Long, Project> projects);
|
||||
}
|
||||
|
||||
@@ -7,9 +7,9 @@ import static de.srsoftware.umbrella.core.Constants.*;
|
||||
import de.srsoftware.tools.Mappable;
|
||||
import java.util.Map;
|
||||
|
||||
public record Member(long userId, Permission permission) implements Mappable {
|
||||
public record Member(UmbrellaUser user, Permission permission) implements Mappable {
|
||||
@Override
|
||||
public Map<String, Object> toMap() {
|
||||
return Map.of(USER_ID,userId,PERMISSION,permission.name());
|
||||
return Map.of(USER,user.toMap(),PERMISSION,permission.toMap());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,15 @@
|
||||
/* © SRSoftware 2025 */
|
||||
package de.srsoftware.umbrella.core.model;
|
||||
|
||||
import static de.srsoftware.umbrella.core.Constants.CODE;
|
||||
import static de.srsoftware.umbrella.core.Constants.NAME;
|
||||
import static java.text.MessageFormat.format;
|
||||
|
||||
import de.srsoftware.tools.Mappable;
|
||||
import java.security.InvalidParameterException;
|
||||
import java.util.Map;
|
||||
|
||||
public enum Permission {
|
||||
public enum Permission implements Mappable {
|
||||
OWNER(1),
|
||||
EDIT(2),
|
||||
ASSIGNEE(3),
|
||||
@@ -27,4 +31,9 @@ public enum Permission {
|
||||
}
|
||||
throw new InvalidParameterException(format("{0} is not a valid permission code"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> toMap() {
|
||||
return Map.of(NAME,name(),CODE,code);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ public class Project implements Mappable {
|
||||
|
||||
public boolean hasMember(UmbrellaUser user) {
|
||||
for (var member : members){
|
||||
if (member.userId() == user.id()) return true;
|
||||
if (member.user().id() == user.id()) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user